Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Parsing error

by MoodyDreams999 (Beadle)
on Jan 31, 2023 at 15:40 UTC ( [id://11150056]=note: print w/replies, xml ) Need Help??


in reply to Re: Parsing error
in thread Parsing error

I suppose that would be another way to write it, but using the bang like that, "&& ! $t[7]" is definitely new to me. "$z[7]" $z is Zipcode, so I was trying to use that varible in the loop like that.

Replies are listed 'Best First'.
Re^3: Parsing error
by kcott (Archbishop) on Jan 31, 2023 at 19:06 UTC

    Do note that "! defined $var" is not the same as "! $var".

    $ perl -Mstrict -wE ' my $x; say "\$x not defined: ", (! defined $x) ? "Y" : "N"; say "\$x not TRUE: ", (! $x) ? "Y" : "N"; $x = 0; say "\$x not defined: ", (! defined $x) ? "Y" : "N"; say "\$x not TRUE: ", (! $x) ? "Y" : "N"; $x = 1; say "\$x not defined: ", (! defined $x) ? "Y" : "N"; say "\$x not TRUE: ", (! $x) ? "Y" : "N"; ' $x not defined: Y $x not TRUE: Y $x not defined: N $x not TRUE: Y $x not defined: N $x not TRUE: N

    — Ken

Re^3: Parsing error
by exilepanda (Friar) on Feb 01, 2023 at 03:01 UTC
    I suppose that would be another way to write it
    It is not. But in short, if you want to check if a variable is in false condition, use if (! $var) {..., or  unless ($var) {..., or the example I gave above.
    A false condition includes 0, "" (empty string), and undefined value.

    On the other hand, defined is checking a null condition (not initialized, undefed). In other words, a variable given "" or 0 also consider as defined, because value already inside. And a proper usage on defined should following a variable, like if ( defined $x ). In your code, ... !defined is checking with $_ which is what you read from <FH>, which I believe is not what you wanted.

    "$z[7]" $z is Zipcode...
    That's why I quoted my @z = 90005; in your code snip, as this is not even a proper array, thus there will be no $z[7] existed.

    Finally, please read other's responds, you can't read Excel by simply open.... , not even CSV. Use a proper module for the job.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11150056]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-05-26 14:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found