Thank you John. I have learned a lot from you and others just by following
this 'Perl Beginners' list'.
Shiping
At 02:00 PM 2/15/2007, John W. Krahn wrote:
Shiping Wang wrote:
> Hi,
Hello,
> I wrote a parsing script, it is working but give me some error message
> at beginning: Use of uninitialized value in concatenation (.) or string
> ... and also it gives some unwanted stuff. To get around this problem, I
> want to directly go to the line and start extract result, in this case I
> would like to start from line :
>
> Testing trait: lnsbp_adj_age
>
> From first line to "Testing trait: ..." line the $. can be vary depends
> on the application option I use, my question is how can I dynamically
> determine the first line number that match "Testing trait: ..." then I
> can directly jump there start parsing? or other better ways to handle it?
You can use the range operator in scalar context. Literal numbers are
compared to the value of $..
This appears to do what you require:
#!/usr/bin/perl
use warnings;
use strict;
open INF, '<', $qtdtout or die "Cannot open '$qtdtout' $!";
my ( $trt, $snp );
while ( <INF> ) {
last if /Run completed/;
if ( 1 .. /^Testing trait:\s+(.*)/ ) {
$trt = $1;
next;
}
$snp = $1 if /^Testing marker:\s+(.*)/;
next unless /^\s+\d/;
print "$trt\t$snp\t", /not tested/ ? 'notest' : ( split )[ 6 ], "\n";
}
__END__
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/