How to print the number of arguments开发者_运维技巧 from @ARGV
according to the following script why its important to print
like
print q{don't have parameters};
And not as
print "don't have parameters"; ??
lidia
#!/usr/bin/perl
if (@ARGV) {
print ......
} else {
print q{don't have parameters};
}
To print the number of elements in any array in perl:
print scalar(@ARGV);
Using q{}
OR single quotes ''
means that a string will get quoted but NOT interpolated, meaning any variables you have inside will not have their actual values. This is a faster way to create strings than with double quotes ""
or qq{}
which WILL interpolate variables in the string.
moreover, print q{} is a shorthand for :
print 'don\'t have parameters'
double quotes mean your string gets interpolated. ie : perl analysis it to retrieve variable values. simple quotes won't. No unrequired analysis -> faster, less memory/cpu/whatever usage
精彩评论