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.
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.
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.
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.
ASKER
Thanks, just have one more question :
what does "@" mean here ? Thanks a lot !!!
meow.
what does "@" mean here ? Thanks a lot !!!
meow.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
See
perldoc perldata
and
perldoc -f shift
perldoc perldata
and
perldoc -f shift
shift Remove the first element of an array, and return it.