Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: pushing individual rows of return (DBI) into seperate arrays

by Mr. Muskrat (Canon)
on Aug 28, 2003 at 19:13 UTC ( #287491=note: print w/replies, xml ) Need Help??


in reply to pushing individual rows of return (DBI) into seperate arrays

Your if statements are true for each row because you use = instead of ==.
  • Comment on Re: pushing individual rows of return (DBI) into seperate arrays

Replies are listed 'Best First'.
Re: Re: pushing individual rows of return (DBI) into seperate arrays
by peppiv (Curate) on Aug 28, 2003 at 19:20 UTC
    Mr. Muskrat Thanks for the fresh pair of eyes. Can't believe I missed something so simple. Too much time staring at code.

    Thank you sir

    peppiv

      Hi peppiv,

      Like everyone else, at some time or other, I have been bitten by this. I have noticed lately around the monastery some people using the idiom

      if ( 1 == $row ){ ... }

      the reason being that if ( 1 = $row ){ ... } would yield an error. ( Can't modify constant item in scalar assignment )

      My first impression was that the construct was ugly, and counter-intuitive, but I feel my opinion changing. I haven't included it in any code, yet, but who knows what the future will bring? :-)

      Does anyone have any thoughts on whether the use of this construct should be encouraged?

      thinker

        I'm a big fan of the if ( 2 == $whatever ) {...} construct myself, and try to use it whenever possible to avoid the problem you describe. After a while you get used to it and it looks normal.
        Maybe I haven't been reading closely enough, but I've never seen that before. I must say that I find that counter-intuitive, as you did initially. I don't see the need for additional code that exists only to validate earlier code where you want to guard against making a coding mistake - does that make sense? Just bite the bullet and learn that "==" is to compare numbers. peppiv did the right thing posting his question here - someone will see the error, even if you can't ;-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2021-06-17 23:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (86 votes). Check out past polls.

    Notices?