ghosh24 has asked for the wisdom of the Perl Monks concerning the following question:

hii guyzz..Its a "how to question" actually..

I have a text file consisted of several lines/paragraphs and then there's a tab-delimited table.

I am looking for a method where my Perl code should split only the table into columns (thus ignoring the previous lines/paragraphs of the file) and then print the third column as output?

Any idea??

thanks

Replies are listed 'Best First'.
Re: Perl 'how to' question
by GrandFather (Saint) on Dec 17, 2010 at 11:16 UTC

    What ideas have you had and what have you tried? How did whatever you tried fail? Or, if you haven't tried anything, what part of the problem are you struggling with?

    True laziness is hard work
Re: Perl 'how to' question
by chrestomanci (Priest) on Dec 17, 2010 at 11:13 UTC

    Assuming that only line from that are part of the table contain any tab characters, then that should be easy.

    open FILE, '<', $srcFile or die "Error reading $srcFile $!"; LINE: while( my $line = <FILE> ) { next LINE unless $line =~ m/\t/; my @cols = split /\t/, $line; # The @cols array numbers from zero, so for the third col, you nee +d $cols[2] print $cols[2]; } close FILE;
Re: Perl 'how to' question
by bill.bbennett (Novice) on Dec 17, 2010 at 17:06 UTC
    Maybe something like this:
    my @list; while (my $line = <STDIN>){ chomp $line; my($one, $two, $three) = split(/\t/, $line); if(defined $three) { push @list, $three } } for my $i (@list){ print "$i\n"; }
Re: Perl 'how to' question
by locked_user sundialsvc4 (Abbot) on Dec 17, 2010 at 14:24 UTC

    Yeah, as you see from the first post, this comes down to two basic concerns: first, identifying the lines that you are interested in; then, splitting them.

    If you have not yet plunged into the world of Perl regular expressions, take a little time-out and do so now.