Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Parsing error

by exilepanda (Friar)
on Jan 31, 2023 at 02:13 UTC ( #11150047=note: print w/replies, xml ) Need Help??

in reply to Parsing error

 my @t=(',',$_);
Do you actually means this?
my @t = split /,/, $_;


... my @z = 90005; ... ..elsif($t[6] eq "CA" && $t[7] eq !defined) { $worksheet->write($rowCount1+1, 7, $z[7]); ...
Do you mean ... && ! $t[7]?
But where is $z[7] came from?

Replies are listed 'Best First'.
Re^2: Parsing error
by MoodyDreams999 (Acolyte) on Jan 31, 2023 at 15:40 UTC
    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.

      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

      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?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2023-03-31 02:57 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (74 votes). Check out past polls.