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.

  1. $param = "" assigns empty string $param, that's not want.

  2. null spelled undef in perl.

  3. to compare strings, use eq operator.

  4. 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

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -