I am trying to run a script that I got from a book. I typed it myself from the book, using Notepad, and then save it as a .pl file.

When I tried to execute it, I got the following error:

syntax error at file.pl line 26, near "{ else" syntax error at file.pl line 30, near "}" Execution of file.pl aborted due to compliation errors.

Lines 18-34 are:

if ($res->is_success) {</br> my $fh = new FileHandle ">$filename"; if (defined $fh) { print $fh $res->content; $fh->close; } else { print STDERR "could not open file $filename: $!\n"; } { else } print STDERR $res->status_line, "\n"; } } } $station = 'mn'; for ($year = 00; $year <= 04; $year++) { my $filename = '200' . $year . $station . 'zip';
I will say that I am new to Perl, but having gotten this directly from the book, I wasn't thinking I needed to be a master. After some initial research, I inserted  use Diagnostics; at the top, but I got the same error.

Any idea what this means? In the perldiag documentation, it just says that this message means the execution ended, but I kinda figured that much. If there's somewhere else I can go to do my own research, just point me in that direction, and I'll take it from there.

Thanks!


In reply to Syntax Error by djaesone

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.