开发者

perl + @ARGV + print syntax

  1. How to print the number of arguments开发者_运维技巧 from @ARGV

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜