in reply to Re: Re: Newbie Question - arrays
in thread Newbie Question - arrays
In order to see if a line is "blank" in the sense that it contains nothing, or contains only whitespace, do this:
But looking at the whole problem... It will probably be easier if you can add a little bit to the script that creates the email in the first place, so that it causes the body of the message to begin with a constant, recognizable line that never occurs in the mail header (and is unlikely to be found in other, unrelated email messages that might happen to get sent to this mailbox); this way, you don't have to worry about making sure you can parse a whole mailbox file correctly. In other words, something like this to create the message:if ( $array =~ /^\s*$/ ) { # true if line is empty or whitespace only .... }
Now, when you process the contents of your mailbox, just look for the string "SYSDATAMSG", read the next three lines for those outputs (and make sure you document your code to specify how the messages are supposed to be created):(echo SYSDATAMSG; uname -a; uptime; date) | mail -s uptime time@taproo +t.bz
Note that I'm opting to use a "while" loop, and taking stuff off the array until it's empty (so I don't have to count array indexes).open(MAIL, "$file") || die "cant open spool\n"; my @mail_lines = <MAIL>; close (MAIL); while ( @mail_lines ) { $_ = shift @mail_lines; if ( /^SYSDATAMSG$/ ) { # next three lines are needed $uname_data = shift @mail_lines; $uptime_data = shift @mail_lines; $time_stamp = shift @mail_lines; # (maybe you want to do things with those lines before/besides + printing) print $uname_data, $uptime_data, $time_stamp; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re:x4: Newbie Question - arrays
by mohadib_the_nasty (Initiate) on Jan 13, 2003 at 05:38 UTC |