when I run the following script.pl script with no arguments:
./script.pl
I do not get the message No arg. Why? How to identify if $param is a null value or empty value, same as [ -z from ksh?
#!/usr/bin/perl
my $param = $ARGV[0];
if ($param = "") {
print No arg;
} else {
print arg: $param;
}
Because it's not Perl. Where did you learn that syntax? So much is wrong with it.
$param = "" assigns an empty string to $param, that's not what you want.
null is spelled undef in Perl.
To compare strings, use the 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};
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With