Link to home
Start Free TrialLog in
Avatar of meow00
meow00

asked on

shift(@ARGV) .....

To Experts,

   I have two perl programs, which output the same results.
--------------------------------------
#!/usr/bin/perl -w
use strict ;

my $dir ;
$dir = shift(@ARGV) || "/tmp" ; # line01..Q1
print $dir; print "\n" ;
--------------------------------------
#!/usr/bin/perl -w
use strict ;

my $dir1 ;
$dir1 = $ARGV[0] || "/tmp" ;
print $dir1; print "\n" ;
-------------------------------------
Q1. However, I do not understand what does it mean by "@ARGV" and "shift" in line01. Could anyone please explain it to me ?

Thanks !!!

meow.
Avatar of shivsa
shivsa
Flag of United States of America image

ARGV is an array which stores values from stdin.
shift Remove the first element of an array, and return it.
in first case,
shift takes the first value from array ARGV ie 0 and prints it.

in second case, u are not using shift and asking directly the first element of ARGV array and printing it.
thats why getting the same result.
Avatar of meow00
meow00

ASKER

Thanks, just have one more question :
what does "@" mean here ? Thanks a lot !!!

meow.
ASKER CERTIFIED SOLUTION
Avatar of shivsa
shivsa
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ozo
See
perldoc perldata
and
perldoc -f shift