On Tue, Jun 26, 2001 at 04:07:06PM -0300, Silvio Luis Leite Santana wrote:
> $bissexto = <STDIN>;
> chop($bissexto);
> $bissexto and { print "OK\n" };
> print "end\n";

You obviously aren't running with warnings on.  With warnings turned on,
your code produces the following (perl 5.6.1):

    Useless use of single ref constructor in void context at -e line 1.
    Odd number of elements in hash assignment at -e line 1, <STDIN> line 1.

Your '{ print "OK\n" }' statement is being evaluated as an anonymous hash
constructor.  It works, but only by accident.  Always debug your code with
warnings and use strict on.


> $bissexto = <STDIN>;
> chop($bissexto);
> $bissexto and { print "OK\n"; };
> print "end\n";

A semicolon in an anonymous hash constructor is a syntax error.


This is probably the code you were looking for:

    #!/usr/bin/perl -w

    use strict;

    my $bissexto = <STDIN>;
    chop($bissexto);

    print "OK\n" if $bissexto;
    print "end\n";


If you want multiple statements executed if $bissexto is true I would
suggest going with the more verbose form of a condition:

    if ($bissexto) {
        print "OK\n";
        ...
    }


If you insist on trying to put it all on one line, you want do {}, as in:

    do { print "OK\n"; ... } if $bissexto;

OR

    $bissexto and do { ... };


At this point, however, you're trying to be too clever and short.  Use the
more verbose form if you want multiple statements.

Also, the chop in your code should probably be a chomp; perldoc -f chomp.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

Reply via email to