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...)
In reply to Re: Writing to file part duex
by graff
in thread Writing to file part duex
by perl_n00b
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |