Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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

by thinker (Parson)
on Aug 28, 2003 at 19:43 UTC ( #287504=note: print w/replies, xml ) Need Help??

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

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?


Replies are listed 'Best First'.
Re: Re: Re: Re: pushing individual rows of return (DBI) into seperate arrays
by kesterkester (Hermit) on Aug 29, 2003 at 13:00 UTC
    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.
Re: Re: Re: Re: pushing individual rows of return (DBI) into seperate arrays
by hmerrill (Friar) on Aug 28, 2003 at 19:55 UTC
    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 ;-)
      It's not additional code. It's using
      if (1 == $x) { ... }
      instead of
      if ($x == 1) { ... }
      if (1 = $x) { ... }
      is a syntax error, but
      if ($x = 1) { ... }
      is not.
      It's easy enough to learn that "==" is to compare numbers, "eq" is to compare strings, and "=" is for assignment in Perl, but peppiv is using Perl and SQL at the same time, and in SQL "=" is for all exact comparison and ":=" is for assignment. I (fortunately) tend to confuse the two to the detriment of my SQL, which almost always causes a syntax error instead of a logical error. Syntax errors are easier to fix than logical ones - I like "1 == $x" style for that reason (although I never remember to do it).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://287504]
[james28909]: cant seem to make it look in linux module path for
[james28909]: no matter how i prepare the paths. oh well. looks like ill just have to start wsl perl from scratch
[Corion]: james28909: You can get a list of all modules on your Windows Perl via the autobundle command in the cpan shell. But that likely lists many more modules than you actually want. I recommend a clear separation and installing modules on ...
[Corion]: ... both Perls separately. I use cpanfiles or Makefile.PL for that - listing all modules for an application there allows me to install them via cpanm . or cpan . automatically without any further interaction

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2018-05-23 17:21 GMT
Find Nodes?
    Voting Booth?