...the blank lines in my mail spool test true...
In order to see if a line is "blank" in the sense that it
contains nothing, or contains only whitespace, do this:
if ( $array =~ /^\s*$/ ) { # true if line is empty or whitespace only
....
}
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:
(echo SYSDATAMSG; uname -a; uptime; date) | mail -s uptime time@taproo
+t.bz
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):
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;
}
}
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).
|