Below is the full code. The odd thing is its running on my ubuntu box - I am sure there is a syntax error I am blind to here but then why is no problem reported under ubuntu

steveb@laptop:~/Loading_Scripts$ perl -c syslog_smtp.pl syslog_smtp.pl syntax OK

On the Solaris box

bash-3.00# perl -c ./syslog_smtp.pl Unrecognized escape \S passed through at ./syslog_smtp.pl line 38. Unrecognized escape \s passed through at ./syslog_smtp.pl line 38. Unrecognized escape \s passed through at ./syslog_smtp.pl line 38. "my" variable $msgdate masks earlier declaration in same scope at ./sy +slog_smtp.pl line 53. "my" variable $msgtime masks earlier declaration in same scope at ./sy +slog_smtp.pl line 53. "my" variable $msgid masks earlier declaration in same scope at ./sysl +og_smtp.pl line 53. "my" variable $from masks earlier declaration in same scope at ./syslo +g_smtp.pl line 62. "my" variable $remainder masks earlier declaration in same scope at ./ +syslog_smtp.pl line 62. "my" variable $msgdate masks earlier declaration in same scope at ./sy +slog_smtp.pl line 63. "my" variable $msgtime masks earlier declaration in same scope at ./sy +slog_smtp.pl line 63. "my" variable $msgid masks earlier declaration in same scope at ./sysl +og_smtp.pl line 63. "my" variable $remainder1 masks earlier declaration in same scope at . +/syslog_smtp.pl line 63. "my" variable $csv masks earlier declaration in same scope at ./syslog +_smtp.pl line 66. Global symbol "$remainder1" requires explicit package name at ./syslog +_smtp.pl line 38. Global symbol "$csv" requires explicit package name at ./syslog_smtp.p +l line 38. Global symbol "$csv" requires explicit package name at ./syslog_smtp.p +l line 38. syntax error at ./syslog_smtp.pl line 52, near "my ( $from, $srvrip ) += $remainder =~ m/=>\s*(" (Might be a runaway multi-line ** string starting on line 38) syntax error at ./syslog_smtp.pl line 60, near "} elsif" syntax error at ./syslog_smtp.pl line 70, near "}" ./syslog_smtp.pl had compilation errors.
#!/usr/bin/perl # use strict; use warnings; my $no = 0; my %monthNos = map {$_ => ++$no} qw{ Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov +Dec }; while (my $line = <STDIN>) { chomp($line); my ($mon, $day, $time, $loghost, $prog, $remainder) = split m{:?\s+}, $line, 6; my ($user) = $remainder =~ m{user=([^,]+)}; my ($rip) = $remainder =~ m{rip=([^,]+)}; my ($op) = $remainder =~ m{\s(==|<=|\*\*|\+\+)\s}; my $yr = 2012; my $srvrip = ''; my $from = ''; my $msgid = ''; my $msgdate = ''; my $msgtime = ''; $remainder =~ tr/"/'/; $_ //= '' for $user, $rip, $op, $srvrip, $from, $msgid, $msgdate, +$msgtime; # <= message arrival # => normal message delivery # -> additional address in same delivery # *> delivery suppressed by -N # ** delivery failed; address bounced # == delivery deferred; temporary problem if( $op eq '<=' ){ # message arrival my ( $from, $srvrip ) = $remainder =~ m/<=\s*(\S+)[^[]+\[([^\]]+)/ +; # <=\s* # (\S+) # Capture the email address following <= # [^[]+\[ # Skip to the first subsequent square bracket. # ([^\]]+) # Capture until a closing bracket. # /x; my ($msgdate, $msgtime, $msgid, $remainder1) = split m{:?\s+}, $remainder, 4; # DATETIME, SERVER, SEQNO, DATETIME1, MSGID, SENDER, RECIPIENT, SVRIP, + ORIGMSGID, STATUS, SUBJECT my $csv = sprintf q{%02d-%02d-%s %s,%s,,%s %s,%s,%s,,%s,%s,,"%s"}, $yr, $monthNos{$mon}, $day, $time, $loghost, $msgdate, $msgtime, $ +msgid, $from, $srvrip, $msgid, $remainder; print "$csv\n"; } elsif( $op eq '=>' ){ # normal message delivery my ( $from, $srvrip ) = $remainder =~ m/=>\s*(\S+)[^[]+\[([^\]]+)/ +; my ($msgdate, $msgtime, $msgid, $remainder1) = split m{:?\s+}, $remainder, 4; # DATETIME, SERVER, SEQNO, DATETIME1, MSGID, SENDER, RECIPIENT, SVRIP, + ORIGMSGID, STATUS, SUBJECT my $csv = sprintf q{%02d-%02d-%s %s,%s,,%s %s,%s,%s,,%s,%s,,"%s"}, $yr, $monthNos{$mon}, $day, $time, $loghost, $msgdate, $msgtime, $ +msgid, $from, $srvrip, $msgid, $remainder; print "$csv\n"; } elsif( $op eq '==' ){ # delivery deferred; temporary problem my ( $from ) = $remainder =~ m/==\s*(\S+)/; my ($msgdate, $msgtime, $msgid, $remainder1) = split m{:?\s+}, $remainder, 4; # DATETIME, SERVER, SEQNO, DATETIME1, MSGID, SENDER, RECIPIENT, SRVRIP +, ORIGMSGID, STATUS, SUBJECT my $csv = sprintf q{%02d-%02d-%s %s,%s,,%s %s,%s,%s,,,%s,,"%s"}, $yr, $monthNos{$mon}, $day, $time, $loghost, $msgdate, $msgtime, $ +msgid, $from, $msgid, $remainder; print "$csv\n"; } elsif( $op eq '**' ){ # fall back on a default behavior my ( $from ) = $remainder =~ m/\*\*\s*(\S+)/; my ($msgdate, $msgtime, $msgid, $remainder1) = split m{:?\s+}, $remainder, 4; # DATETIME, SERVER, SEQNO, DATETIME1, MSGID, SENDER, RECIPIENT, SRVRIP +, ORIGMSGID, STATUS, SUBJECT my $csv = sprintf q{%02d-%02d-%s %s,%s,,%s %s,%s,%s,,,%s,,"%s"}, $yr, $monthNos{$mon}, $day, $time, $loghost, $msgdate, $msgtime, $ +msgid, $from, $msgid, $remainder; print "$csv\n"; } else { my $csv = sprintf q{%02d-%02d-%s %s,%s,,,,,,,,,"%s"}, $day, $monthNos{ $mon }, $yr, $time, $loghost, $remainder; print "$csv\n"; } }

In reply to Re^6: String Matching by stevbutt
in thread String Matching by stevbutt

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.