Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: How to use @ARGV

by kcott (Archbishop)
on Aug 29, 2017 at 05:21 UTC ( [id://1198242]=note: print w/replies, xml ) Need Help??


in reply to How to use @ARGV

G'day chaney123,

Welcome to the Monastery.

@ARGV is a special variable (see perlvar). You'll find documentation about @ARGV, along with other variables containing 'ARGV', in the "Variables related to filehandles" section.

You can use it directly in your code:

$ perl -E 'say for @ARGV' file_1 file_2 file_1 file_2

You can assign it to another variable and use that:

$ perl -E 'my @x = @ARGV; say for @x' file_1 file_2 file_1 file_2

Be careful if your arguments (whether filenames or something else) start with a hyphen, e.g. the -file_1 and -file_2 you show:

$ perl -E 'say for @ARGV' -file_1 -file_2 -i used with no filenames on the command line, reading from STDIN.

They look like options (to both Perl and humans). Separate options and other (non-option) arguments with '--':

$ perl -E 'say for @ARGV' -- -file_1 -file_2 -file_1 -file_2

If your command line arguments are options, instead of trying to process them yourself, use one of the core modules. Getopt::Long is what I use. There's also Getopt::Std: I don't use that one so I can't really comment on it.

— Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1198242]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2024-04-18 06:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found