in reply to Re^3: = rather than =~ ? (too brief?)
in thread = rather than =~ ?
$foo = $1 if /(foo)/; may very well be the expected behaviour in certain situations where we want to modify $foo if the match is successfull or leave it otherwise. Using it when declaring a variable is not desirable however. If there is no match, then $foo will not be declared and any attempt to read the scalar later will result in a "variable not declared" error. Of course, this is why we use strict;. Without it, we won't get an error :) defined.
Basically, $foo = $1 if /(foo)/; should really only be used where we might otherwise do a $foo = /(foo)/ ? $1 : $foo; (which is just programatically ugly).
Update: Whoa, was I off base. Read the replies to this node to see the reason :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Actually, it's worse than that
by mrpeabody (Friar) on Jan 02, 2004 at 19:44 UTC | |
|
Re^5: = rather than =~ ? (too brief?)
by Aristotle (Chancellor) on Jan 02, 2004 at 22:00 UTC | |
|
Re: Re^4: = rather than =~ ? (too brief?)
by BrowserUk (Patriarch) on Jan 02, 2004 at 20:31 UTC |