in reply to Writing to file part duex
Part of the problem is that you only want to assign to $locus when you have just read that particular sort of line from the file. If you do this sort of assignment on every line:my $locus; while (<$in>) { if ( /LOCUS\s+(\w+)/ ) { $locus = $1; } elsif ( /\^\^/ ) { if ( $locus ) { s/\^\^/>$locus\n^^\n/g; } else { warn "Found ^^ without a preceding LOCUS value\n"; } } print $out $_; }
then $locus will get cleared every time your regex fails to match a given line of input. So see if the match will work first, and if it does, then assign the result to $locus.( $locus ) = ( /LOCUS\s+(\w+)/ );
Another part is that you'll want to know (via STDERR) if you get a situation where a locus value should be plugged in but you don't have one yet.
(I hope I understood the question -- not sure that I did...)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Writing to file part duex
by Anonymous Monk on Jul 24, 2009 at 04:41 UTC |