hi..i am new to perl language..ive given a task to extract some info from a logfile and print the extracted to a new file..what make it difficult is because it need to extract vetically..for example below with some conditions;

------------------------------------------------------------------------
      C  H     W  S    Z      S      W      T    C    D       F  R   O M
      Y        E  E    O      T      I      L    N    E       A  E   R R
      L  D     G  Q    N      W      E      T    T    F       V  C   G G
------------------------------------------------------------------------

      0  0 65535  0    1      0      0      0    0    0       0  1   0 1
      1  0 65535  0    1      1      0      0    0    0       0  1   1 0
      2  0 65535  0    1      0      0      0    0    0       0  1   0 1
      3  0 65535  0    1      0      0      0    0    0       0  1   0 1
      4  0   252  0    1      1      0      0    0    0       0  1   1 0
      5  0 65535  0    1      0      0      0    0    0       0  1   0 1
      6  0 65535  0    1      0      0      0    0    0       0  1   0 1
      7  0 65535  0    1      1      0      0    0    0       0  1   1 0
if (ORG==1 && ((STW==1) || (TLT==1)) || (MRG==1)
    no problem;
else
    problem;{
print {#the lines/columns which problems but only print the CYL, HD, WEG, WIE, DEF columns}
}

can anyone help me?thanks..

From your example data set, it looks to me like the only data that's 'vertical' are the column names. If those are static (they never change), why don't you just count the fields in each line? Using your sample data above, for example:

#!/usr/bin/perl -w
$datafile = shift @ARGV;
open(DATAFILE,"$datafile") or die "Can't open $datafile: $!\n";
foreach $line (<DATAFILE>){
        next if $line =~ /^-\-/;
        next if $line =~ /[A-Z]/;
        next if $line =~ /^$/;
        @ary = split /\s+/, $line;
        print "CYL: $ary[1]\n";
        print "HD : $ary[2]\n";
        print "WEG: $ary[3]\n";
        print "WIE: $ary[7]\n";
        print "DEF: $ary[10]\n";
        print "\n";
}

thanks roswell..i tried your code but it didnt came out like what exactly i need..anyhow appreciate it though..i might use some of your idea and i think i can make it..thank you so much..

If you need the output on a single line, read about the 'printf' function which will allow you to create perfect columns for the data.

If you need the output on a single line, read about the 'printf' function which will allow you to create perfect columns for the data.

thanks..i'll give it a try then..maybe that what i need..

This article has been dead for over six months. Start a new discussion instead.