Re: search & relplace question



Tassilo v. Parseval wrote:
> Also sprach Ashwin:
>
>>I am not able to understand why
>>my @result =map ((s/BBI_DIR/BBI_DIR\\RBI/), @BBY); modifies the @BBY
>>array,
>>what I expected was that @result should get updated with replaced lines,
>>but it only updated with value 1 , which is what search function
>>returns on success
>
> Precisely.
>
>>if I try
>>
>>my @result =map ((s/BBI_DIR/BBI_DIR\\RBI/,$_), @BBY);
>>@results and @BBY get the same value , but @result also gets those line
>>which are replaces appended with 1,
>>what I need is only @result to get updated
>
> You can make a copy of $_ in the map block and apply s/// to that. Or
> you use List::MoreUtils::apply() (courtesy of Brian McCauley) which is
> just like map() only that it wont alter the input elements:
>
> use List::MoreUtils qw/apply/;
>
> my @result = apply { s/BBI_DIR/BBI_DIR\\RBI/ } @BBY;

Another way to do it:

s/BBI_DIR/BBI_DIR\\RBI/ for my @result = @BBY;



John
--
use Perl;
program
fulfillment
.