When the perl script is run, the parameters passed to it from the command line are stored in the built-in array @ARGV. @ARGV is the array used by PERL to receive parameters by default. There can be multiple parameters. $ARGV[0] is the first parameter received, and $ARGV[1] is the second one.
How to use it is:
See a specific example:
For example, the content of file 1:
1320239
1320239
1320238
1320238
1320238
1320235
1320237
Contents of file 2:
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 content of file 1 first, and then read the content of file 2. When reading the content of file 2, the last column of file 2 needs to be included in the previous file 1.
[root@localhost ~]$ cat
#!/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 $column4=$line[3];
$hash{$column4}=$_;
}
while (<ONE>) {
chomp;
print $hash{$_} if defined $hash{$_};
}
print"\n";