Christiane Nerz wrote:
>
> Hi everybody!
Hello,
> Two questions:
> I've got a test-file and want to add something to some lines, while
> reading it out.
> I tried the following code:
>
> while (<TXTFILE>) {
> if (/pattern/) {
> #$line = $_ . $something;
> #push (@new_array, $line);
> }
> else {
> #$line = $_;
> #push (@new_array, $line);
> }
> }
>
> But @new_array didn't get the lines!
>
> The textfile look like
>
> >SA texttexttext...\n
> texttexttext\n
> texttexttext\n
> texttexttext\n
> >SA texttexttext...\n
> texttexttext\n
> texttexttext\n
> texttexttext\n
> >SA texttexttext...\n
> texttexttext\n
> texttexttext\n
> texttexttext\n
>
> I tried to get the >SA..-lines by
>
> if (/^SA[.]*\n/) {
> do...
>
> but the pattern was not be found.
> Whats wrong with it?
Your pattern specifies that the line must start with the characters 'S'
and 'A' followed by zero or more of the '.' character followed by a
newline character but your example shows that the line starts with the
characters ' ', '>', 'S', 'A' and ' '.
while ( <TXTFILE> ) {
if ( /^ >SA .*\n/ ) {
push @new_array, $_ . $something;
}
else {
push @new_array, $_;
}
}
> Or does anyone knows a simple method to read the lines in a hash -
> every-SA-line should be the key, the following lines until the next >SA
> the value. That'll be much more simple to handle..
my ( $key, %hash );
while ( <TXTFILE> ) {
if ( /^ >SA .*\n/ ) {
$key = $_;
}
elsif ( defined $key ) {
$hash{ $key } .= $_;
}
}
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]