...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).

In reply to Re: Re: Re: Newbie Question - arrays by graff
in thread Newbie Question - arrays by mohadib_the_nasty

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.