in reply to Re: Re: Check on if statement
in thread Check on if statement
I think defined() is a good idea if there's a possibility of $foo being undefined, so as to avoid a warning about an undef being used in a string comparison/regex. Assuming an undefined value counts as a blank, I would write it like this:
if (!defined($foo) or $foo =~ m/^\??$/) { # Foo is valid }
Thus: "If foo is undefined, or matches an empty string or a single question mark."
But wasn't there something about \n's counting as "^" and/or "$"? Hmmm...
The Secret to Fortune Cookies in One Line
print join("... in bed", `fortune fortunes` =~ m/^(.*)(\.|\?|\!)$/), "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: defined() might be a good idea
by BrowserUk (Patriarch) on Aug 17, 2002 at 21:16 UTC | |
by demerphq (Chancellor) on Aug 18, 2002 at 17:28 UTC |