- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Route emails in a perl script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2011 06:36 PM
08-10-2011 06:36 PM
Re: Route emails in a perl script
@allanm77 wrote:
Have another question about the original perl script (from above), I want to use that on three to four different files -
/var/tmp/email & /var/tmp/email_new & /var/tmp/email_newer
with same logic and probably send to different userids with different subjects.
I tried to keep that in the same script but struggled with die statements which used to close the program if it couldn't find the one of the file.
Currently you 'die' (with the reason for the death) if you can't open a file. That's one way. I would construct your 'open...or die...' like this, though:
... my $HM_name = '/var/tmp/email';
open NM, .'<', $NM_name or die "Can't open '$NM_name': $!\n";
...
You can also test for the presence of a file and only if present, open it:
if ( -e $NM_name ) { open NM, '<', $NM_name or die "Can't open '$NM_name': $!\n"; } else { ... }
Notice how we defined the file name as a variable for consistent use throughout, too. If it's wrong in one place, its the same "wrong" everywhere :-)
In the second example code where we test for file existence we are ignoring a race condition where a file does indeed exist and the test is satisfied, but the open fails (and you die) because when that's atttempted another process has removed the file. I don't believe that you need to worry in a case like this, but you should be aware of the potential if only in the abstract.
Regards!
...JRF...
- « Previous
-
- 1
- 2
- Next »