Thanks
V.M.
if (length $var) ....
--jk
it will produce warnings if it is not initialized.
If you want to avoid warnings you must use defined().
perl 5.10 introduces the defined-or Operator.
=> This is your solution.
--jk
I tried this test program:
#!/usr/bin/perl
use warnings;
use strict;
my $var;
if (defined($var) && $var ne "") {
print "$var\n";
}
It didn't produce any warnings. When I put in "my $var = 0;",
it printed "0", just like it should. I don't understand
your question. If by "shorter" you mean getting rid of the
defined() test, then, no, you can't get rid of that. If you
aren't sure if $var is going to be defined, you have to test
for it before trying to use it.
--
Christopher Mattern
NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities
... but no, you need a defined-and operator!
I give up, this exercise is futile!
Shorter:
if (length ($var // "")) { .. }
Abigail
--
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'