求助:怎样输出文件内容到数组?

求助:怎样输出文件内容到数组?

求助:怎样输出文件内容到数组?
my @b; my@c;
@a=("LBA = 0x05AA501 Sec Cnt = 0x45",
   "LBA = 0x05DE521 Sec Cnt = 0x35",
  );

  while(@a)
   { if(/LBA = 0x(.*)\S+Sec Cnt = 0x(\d+)/g)
      {$b=$1; $c=$2;
      }
    }  
 print @b;   print @c;
[quote]--perldoc -f pu.

perldoc -f push

  push ARRAY,LIST
      Treats ARRAY as a stack, and pushes the values of LIST onto the
      end of ARRAY. The length of ARRAY increases by the length of
      LIST. Has the same effect as

        for $value (LIST) {
          $ARRAY[++$#ARRAY] = $value;
        }

      but is more efficient. Returns the number of elements in the
      array following the completed "push".

不大明白
my @lines;   my @rows;
while (<FH>) {
 @rows = split(/\s+\|/);
  push @lines, @rows;

}
这样做后@lines是一个一维数组。怎么能分为列数组呢?

想将下述内容写入数组@seconds   @Primitive    @Delta  @Count_Type中,push结构是怎样的?

seconds   Primitive    Delta  Count - Type
167265    SATA_SOF    252   Host -> Dev
167290     SATA_SOF    286   Host -> Dev
167294     SATA_SOF    115   Host -> Dev
167409     SATA_SOF    131   Host -> Dev
167542     SATA_SOF    194   Host -> Dev
167737    SATA_SOF    183   Host -> Dev
167921     SATA_SOF    134   Host -> Dev




   

[quote]--my @lines; .

my @lines;  my @rows;
while (<FH>) {
@rows = split(/\s+\|/);
 push @lines, @rows;

}
这样做后@lines是一个一维数组。怎么能分为列数组呢?


perl 只有 1 维数组,没有 2 维和高维数组。

push @lines, @rows; 是将 数组 @rows 的引用插入到 @lines 里。

引用时,$lines[0]->[0] 就是第 1 行第 1 列的值。


想将下述内容写入数组@seconds  @Primitive  @Delta @Count_Type中,push结构是怎样的?

seconds  Primitive  Delta Count - Type
167265  SATA_SOF  252  Host -> Dev
167290   SATA_SOF  286  Host -> Dev
167294   SATA_SOF  115  Host -> Dev
167409   SATA_SOF  131  Host -> Dev
167542   SATA_SOF  194  Host -> Dev
167737  SATA_SOF  183  Host -> Dev
167921   SATA_SOF  134  Host -> Dev

为清晰起见,可以这样

while (my $line = <FH>) {
  next unless ($line =~ /^\d/);  # 跳过标题行
  chomp($line);
  my ($second, $primitive, $delta, $count_type) = split(/\s+/, $line);
  push @seconds, $second;
  push @primitiv, $primitiv;
  push @delta, $delta;
  push @count_type, $count_type;
}