shift(@ARGV) .....

Posted on 2003-12-06
Last Modified: 2006-11-17
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 !!!

Question by:meow00
  • 3
LVL 24

Expert Comment

ID: 9890198
ARGV is an array which stores values from stdin.
shift Remove the first element of an array, and return it.
LVL 24

Expert Comment

ID: 9890205
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.

Author Comment

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

LVL 24

Accepted Solution

shivsa earned 60 total points
ID: 9892423
it represent an array variable.
in this context it is saying that ARGV is a array.
LVL 84

Expert Comment

ID: 9893422
perldoc perldata
perldoc -f shift

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Can Oracle Client work with an Oracle 12c Database? 5 152
Using Perl DBI to query oracle 3 43
Perl script to delete older files 6 86
parse a file and get data out 11 45
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question