Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: using split

by naikonta (Curate)
on Jun 05, 2007 at 02:21 UTC ( [id://619274]=note: print w/replies, xml ) Need Help??


in reply to Re: using split
in thread using split

if ($cols[11] = $target1)

looks wrong!

Perhaps, but not really. One may need to assign a variable from another expression then test the truthness of that variable. What looks wrong if the variable is assigned to a literal value. This will issue a syntax warning (unless warnings are disabled):
my $x; if ($x = 'a literal value') { # will issue warnings }
Note that the if is (effectively) testing the contents of $target1, not equality of $target1 and $cols[11].
While you are right about the equality part, but the if construct is effectively testing the whole expression, not just the RHS.

Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

Replies are listed 'Best First'.
Re^3: using split
by GrandFather (Saint) on Jun 05, 2007 at 03:26 UTC

    I didn't say "is wrong", I said "looks wrong" (yes, I know you didn't say I said that either, but you seem to have reacted as though I did). It looks wrong to the extent that it should either be rewritten to "look right" or be commented. However the only appropriate comment effectively says "I did a dumb thing that needs an even dumber comment so that you know I'm being silly". Much better to rewrite it as:

    $x = $y; if ($x) { ... }

    which makes it quite clear that the assignment is intended and also quite clear what is being tested. Most countries don't tax code by the line so the cost of being clear is pretty low. ;)


    DWIM is Perl's answer to Gödel

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-18 18:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found