The problem is that your regex is matching the whole line:

 @ [EMAIL PROTECTED]@banana[4];
 ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
$1 $2

Instead, use non greedy matches:

$line =~ s/(@)(\S+?\[\S+?\])/\$$2/g;

and you'll get what you want:

 @ array[1] = @ array[2] +@ banana[4];
 ^ ^^^^^^^^   ^ ^^^^^^^^  ^ ^^^^^^^^^
$1 $2        $1 $2       $1 $2

Regards,

jac


On Thu, 2004-04-29 at 09:31, Owen wrote:
> I would like to replace all instances of
> 
>  @non_space_characters[non_space_characters] with
>  $non_space_characters[non_space_characters]
> 
> The program below gets the first one only. How do I get the others?
> 
> TIA
> 
> Owen
> ---------------------------------------------------
> #!/usr/bin/perl -w
> use strict;
> 
> my $line;
> while (<DATA>){
> $line=$_;
> #$line=~s/(@)(\S+)(\[\S+\])/\$$2$3/g;
> $line=~s/(@)(\S+\[\S+\])/\$$2/g;
> 
> print "$line\n";
> 
> }
> __DATA__
> @[EMAIL PROTECTED]@banana[4];
-- 
Josà Alves de Castro <[EMAIL PROTECTED]>
Telbit - Tecnologias de InformaÃÃo


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to