perl + identify if param is empty value from ARG -
when run following script.pl script no arguments:
./script.pl
i not message no arg
. why? how identify if $param
null value or empty value, same [ -z
ksh?
#!/usr/bin/perl $param = $argv[0]; if ($param = "") { print no arg; } else { print arg: $param; }
because it's not perl. did learn syntax? wrong it.
$param = ""
assigns empty string$param
, that's not want.null spelled
undef
in perl.to compare strings, use
eq
operator.you must quote strings:
print "no arg"
much easier:
#!/usr/bin/perl if (@argv) { print 'have parameters'; } else { print q{don't have parameters}; }
Comments
Post a Comment