Hi all, I studied perl 10 yrs ago and i didnot use now i am lost. If i have a file name db flat file mylist.log
2011/04/12 12:50:24|red|florida 2011/04/12 15:20:21|green|tampa 2011/04/12 15:30:12|red|miami
How do i compare if current time - fielone time > 216000 and field 2 is red then email me f1, f3 ?
#!/usr/dist/share/perl,v5.003/5bin.sun4/perl use Time::Local; $today = timelocal(localtime); $mailprog = "|/usr/sbin/sendmail -t"; $lst_email = 'someone@outthere.com'; open (DATA,"/mylist.log") || die ("Can't Open data File: $!\n"); @data=<DATA>; foreach $line (@data) { ($datestamp, $status, $location)=split(/\|/,$line); my $lastaction = &date_to_unix($datestamp); if (($today > ($lastaction - 216000)) && ($db =~ 'red') ) { MAILIT close DATA; sub date_to_unix() { my ($year,$mon,$day,$hour,$min,$sec) = $_[0] =~ /(\d+)\/(\d+)\/(\d+)\s(\d+):(\d+):(\d+)/; return undef unless ($day and $mon and $year); return timelocal(0,$min,$hour,$day,$mon-1,$year-1900); } open (MAILIT, "$mailprog") || &cgierr("Can't start mail program"); print MAILIT "To: $lst_email\n"; print MAILIT "Subject: $location is stuck \n\n"; print MAILIT "$location light has been red for more than an hour \ +n\n"; print MAILIT "please check it. \n\n"; print MAILIT "Here are the info\n"; print MAILIT "$datestamp and $location"; close (MAILIT);

In reply to Compare field andsend mail by britney

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.