淑昊柠 发表于 2018-9-1 07:27:57

@ARGV:perl命令行参数

  当perl脚本运行时,从命令行上传递给它的参数存储在内建数组@ARGV中,@ARGV是PERL默认用来接收参数的数组,可以有多个参数,$ARGV是表示接收到的第一个参数,$ARGV表示第二个。
  使用方法为:
  perl   my.pl $ARGV$ARGV
  看一个具体例子:
  比如文件1的内容:
  1320238
  1320239
  1320239
  1320238
  1320238
  1320238
  1320235
  1320237
  文件2的内容:
  102 5709072117805887 4001 1301854
  102 5709072117807510 4001 1320292
  102 5709072117838653 4001 1301857
  102 5709072117814280 4001 1305832
  102 5709072117839397 4001 1310673
  102 5709072117839335 4001 1311270
  我想先把文件1的内容读取出来,然后读取文件二的内容,在读取文件2的内容的时候,文件2的最后一列需要包含在上文件1内。
  $ perlex.pl 1.txt 2.txt
  $ cat ex.pl
  #!/usr/bin/perl
  use strict;
  open(ONE,"$ARGV") or die $!;
  open(TWO,"$ARGV") or die $!;
  my %hash;
  while () {
     chomp;
     my @line=split;
     my $column4=$line;
     $hash{$column4}=$_;
  }
  while () {
      chomp;
      print $hash{$_} if defined $hash{$_};
     
  }
  print"\n";

页: [1]
查看完整版本: @ARGV:perl命令行参数