tags:

views:

63

answers:

2

hi

  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}; 
    } 
+2  A: 

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.

Salgar
Giving the OP a link to the manual would have been helpful here: http://perldoc.perl.org/perlop.html
Ether
`print~~@ARGV` :)
ysth
A: 

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

benzebuth