Mailing List Archive

perl 5.001m syntax error
>
> Date: Mon, 30 Oct 1995 14:41:39 -0500 (EST)
> From: "Sam Sexton 01203 256562 (24 742)" <sam.sexton@reuters.com>
> Subject: perl 5.001m syntax error
> To: perl5-porters@africa.nicoh.com
> X-Filter: mailagent [version 3.0 PL44] for rep@genrad.com
>
> Firstly, I have just installed 5.001m and have NO previous experience
> of perl, but as the script I have a problem with is taken from
> Programming Perl (so I'm told - I can't get hold of a copy
> immediately), I imagine that this is a Perl 5 issue. I Have had a hunt
> in the documentation, but there's rather a lot of it and I've been
> told to get this working asap. Enough of my whingeing - the script is
> the password checking one from the above book, and line 250:
>
> open(PASSWD,"passwd") || die "Can't open passwd file.\n";
>
> is rejected with
>
> syntax error at perlpass line 250, near "open"

There's a good chance that the real problem is before this. Commonly you
get errors like this if you leave out a semicolon or some other punctuation
on a preceding line. There's nothing apparently wrong with the line that
you have shown.

If you don't find anything obvious in the few lines before ine 250, send me
the whole script.

> I have played around, but without success.
>
> Whilst I'm here, I also had a problem with unmatched parentheses
> reported for line 647:
>
> if ($mo = ($pass =~ /^[ \d]*([a-zA-Z]{3,5})[ \d]*$/) &&
> ($mo =~ /^(jan|feb|mar(ch)?|apr(il)?|may|june?/i ||
> $mo =~|july?|aug|sept?|oct|nov|dec)$/i) ) {
> print "Please don't use dates.\n";
>
> 647 is the second of the above lines. I got round this by making the
> test for months into one long line - after checking (by eyeball and
> vi) that the parens were in fact matched.

You and vi may be able to match the parentheses, but they don't match in a
way that makes sense to perl. I looked at my copy of "Programming Perl"
(January 1991 -- First Printing) and it appears to have the same error.
Perhaps I'll incur the wrath of Larry and Randal by suggesting such a
thing. :-) On the other hand, possibly I'm missing some subtlety here.

The left-paren before "jan" in the second line matches the right-paren
after "dec" in the third line, but this matching is half in the first '$mo
=~ /stuff/' and half in the second one. It appears that you need something
like a ')$' after "june?" on the second line and '/^(' instead of '|'
before "july" on the third line.

My suspicion is that this code was originally written as one long line
split, incorrectly, into two lines to avoid the line-wrap.

> Any suggestions on either of these problems would be appreciated.
>
> TIA, Sam

pete peterson
rep@genrad.com
(508)287-7478; Home: (508)256-5829 (Chelmsford, MA)