• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3392
  • Last Modified:

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.
0
meow00
Asked:
meow00
  • 3
1 Solution
 
shivsaCommented:
ARGV is an array which stores values from stdin.
shift Remove the first element of an array, and return it.
0
 
shivsaCommented:
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.
0
 
meow00Author Commented:
Thanks, just have one more question :
what does "@" mean here ? Thanks a lot !!!

meow.
0
 
shivsaCommented:
it represent an array variable.
in this context it is saying that ARGV is a array.
0
 
ozoCommented:
See
perldoc perldata
and
perldoc -f shift
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now