in reply to Re^3: What's so bad about &function(...)?
in thread What's so bad about &function(...)?

You're half right, but you did miss something that jdporter missed, too.

@{\@foo} is, as far as I know, a truly useless elaboration of @foo.

The anonymous copy provided by @{[@foo]} is sometimes useful when you want to preserve @foo's contents. Example:

my @mutant_foo = map { mutator($_) } @{[@foo]};
It helps with for loops, too. That kind of situation comes up surprisingly often and the copy is an effective and unobtrusive solution.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^5: What's so bad about &function(...)?
by demerphq (Chancellor) on Dec 08, 2005 at 10:21 UTC

    @{[...]} also has the interesting side effect that it lets you interpolate a list inside of a quoted string. Which can be useful in some circumstances, like inside of a here doc. This actually applies to ${\(expression)} but the latter is a little less useful IMO.

    ---
    $world=~s/war/peace/g

Re^5: What's so bad about &function(...)?
by jdporter (Paladin) on Dec 20, 2005 at 13:07 UTC

    I didn't miss anything. You seem to have missed my entire point, which was that the ampersand on a sub call is as useless an elaboration as the above array thing.

    (Of course, it's not really entirely as useless; it's only useless if you avoid coding in a way that exploits the ampersand's wierdness. In general, I avoid such coding, and claim it is a "best practice".)

    We're building the house of the future together.
Re^5: What's so bad about &function(...)?
by Anonymous Monk on Dec 08, 2005 at 16:55 UTC
    Hmmm... are there other benefits?

    I never use mutator functions, nor the "alter in place" bindings of for loops. I also don't like to interpolate non-constant expressions into constant strings, like here docs or string interpolations...

    If I really need a copy of @foo, I'll label the copy with a proper variable name, do a normal assignment, and be done with it. No trickyness required! :-)