@argv analysis of the built-in array of perl command line parameters _perl

Source: Internet
Author: User
Tags hash perl script

When the Perl script is run, the arguments passed to it from the command line are stored in the built-in array @argv, @ARGV is the array that Perl defaults to receive parameters, can have multiple arguments, $ARGV [0] is the first parameter that is received, $ARGV [1] represents the second.
Use the method:

Copy Code code as follows:
Perl my.pl $ARGV [0] $ARGV [1]

Look at a specific example:
For example, the contents of document 1:
Copy Code code as follows:
1320238
1320239
1320239
1320238
1320238
1320238
1320235
1320237

Contents of document 2:

Copy Code code as follows:
102 5709072117805887 4001 1301854
102 5709072117807510 4001 1320292
102 5709072117838653 4001 1301857
102 5709072117814280 4001 1305832
102 5709072117839397 4001 1310673
102 5709072117839335 4001 1311270

I want to read the contents of file 1 First, then read the contents of file two, and when I read the contents of File 2, the last column of file 2 needs to be included in file 1.

Copy Code code as follows:
[Root@localhost ~]$ perl ex.pl 1.txt 2.txt
[Root@localhost ~]$ Cat ex.pl
#!/usr/bin/perl
Use strict;

Open (One, "$ARGV [0]") or Die $!;
Open (Two, "$ARGV [1]") or Die $!;

My%hash;
while (<TWO>) {
Chomp
My @line =split;
My $column 4= $line [3];
$hash {$column 4}=$_;
}

while (<ONE>) {
Chomp
Print $hash {$_} if defined $hash {$_};

}

print "\ n";

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.