Hmm, I think you might have got caught up in a side street on this one. For instance for first example _shouldn't_ be written that way. When people say "dont use map in void context" they say it for good reasons.
@out_list=@in_list; s/foo(.*?)bar/$1 baz/ for @in_list;
Update:
I like japhys version, and I'd probably use it myself, but I can see some people saying that the above version is more understandable. japhy++

Your second method leaves a lot to be desired (its unusable for a variety of reasons), and your third version is workable, although i'd probably write it
@out_list = map {local $_=$_; s/foo(.*?)bar/$1 baz/; $_ } @in_list;
Anyway, heres a sub so you can write it the way that feels comfortable
sub ro_map (&@){ my $sub=shift; my @return; foreach (@_) { local $_=$_; push @return,$sub->(); } @return } my @out=ro_map{s/x/y/g}@in; print "original: @in\n"; print "changed : @out\n";
One could argue that this dual result from the mapped code block -- doing in-place editing of the input list and also returning the edited list -- seems to be overdoing it, or is somewhat redundant.

I dont think you would get far with this argument. Howabout this:

# lc the filenames and create a set of filespecs from them. my @filespecs=map{ $_=lc($_); File::Spec->joinpath($path,$_) } @files;
HTH

Now on to read the other comments. :-)

Yves / DeMerphq
---
Software Engineering is Programming when you can't. -- E. W. Dijkstra (RIP)


In reply to Re: A "harmless" alternative to 'map{}'? by demerphq
in thread A "harmless" alternative to 'map{}'? by graff

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.