The OP with formatting:

#!/usr/local/bin/perl -w use Email::Sender::Simple qw(sendmail); use Email::Simple; use Email::Simple::Creator; open (IN, 'top.log'); $input=<IN>; print $input; $lngth=length($input); print $lngth; $load = substr($input,16,4); print $load; $value=.1 if ($load > $value) { # print "$load greater than $value"; my $email = Email::Simple->create( header => [ To => '"Hardy Cherry" <hcherry@youngliving.com>', From => '"Hardy Cherry" <hcherry@youngliving.com>', Subject => "Load g", ], body => "$load greater than $value.\n", ); sendmail($email); }
"my" variable $email masks earlier declaration in same scope at hcshor +t.pl line 26. syntax error at hcshort.pl line 15, near ") {" syntax error at hcshort.pl line 28, near "}" Execution of hcshort.pl aborted due to compilation errors.

I intend to use sendmail more than once but I'm a newbie in perl so I don't understand why I'm getting a syntax error and why the ()and {} seem to be ignored.

The problems stem from the missing semicolon after "$value=.1". Perl is seeing the following (which is perfectly legitimate):

$value=.1 if ($load > $value)

That can't be followed by an opening brace, so Perl gives a syntax error 'near ") {"'. Been there, done that.


In reply to Re: understanding scope and () and {} by ikegami
in thread understanding scope and () and {} by hcherry

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.