Quantcast
Channel: perl – Coding School
Viewing all articles
Browse latest Browse all 15

Perl ARGV

$
0
0

@ARGV and %ENV

The built-in array @ARGV contains the command line arguments for a Perl program. The following run of the Perl program critic.pl will have the ARGV array (“-poetry”, “poem.txt”).

unix% perl critic.pl -poetry poem.txt

%ENV contains the environment variables of the context that launched the Perl program.

@ARGV and %ENV make the most sense in a Unix environment.

So for example you have a script like test.pl


#!/usr/bin/perl

use strict;

my $column=$ARGV[0];

my $database=$ARGV[1];



------run the program now---

$./test.pl ssn employees

in above example we are passing two values as commandline arguments. so $column will have “ssn” and $database will have “employees”.
Note: Pass values in quoutes if values have spaces.


Viewing all articles
Browse latest Browse all 15

Trending Articles