Re: search & relplace question
- From: anno4000@xxxxxxxxxxxxxxxxxxxxxxx (Anno Siegel)
- Date: 28 Oct 2005 11:37:24 GMT
John W. Krahn <krahnj@xxxxxxxxx> wrote in comp.lang.perl.misc:
> 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;
Ah... very nice. That's the array version of the scalar idiom
( my $result = $RBY) =~ s/.../.../;
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
.
- References:
- Re: search & relplace question
- From: Tassilo v. Parseval
- Re: search & relplace question
- From: John W. Krahn
- Re: search & relplace question
- Prev by Date: Re: search & relplace question
- Next by Date: Re: Unintuitive expression evaluation
- Previous by thread: Re: search & relplace question
- Index(es):
Relevant Pages
|
|