Re: search & relplace question
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Fri, 28 Oct 2005 11:21:43 GMT
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
.
- Follow-Ups:
- Re: search & relplace question
- From: Anno Siegel
- Re: search & relplace question
- References:
- Re: search & relplace question
- From: Tassilo v. Parseval
- Re: search & relplace question
- Prev by Date: Re: to parse a string
- Next by Date: Re: search & relplace question
- Previous by thread: Re: search & relplace question
- Next by thread: Re: search & relplace question
- Index(es):