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";