in reply to Re: Using x to build data structures considered harmful
in thread Using x to build data structures considered harmful

I admit. I don't get it. :-)

  foo(($x) x 2)

is supposed to be a lazy way to do

  foo($x, $x)

right? How is that evil? They will both give the same results (i.e. that $x is 12 after the call). What might one expect instead? Is my translation incorrect?

The thing you get bitten by here is just the aliasing, not the x operator as I understand it.

Update: Ah, got it. My translation was incorrect (because it actually was a correct translation). Seems like Perl does good dwim in this case, with the i meaning ihb. :-)   ($x) x $n in list context could be believed to be equivalent to

map $x => 1 .. $n # or sub { ($x) x $n } -> ()
which both return copies of the values and the output would then be
11 11 10
Good thinking, japhy.

ihb

Replies are listed 'Best First'.
Re^3: Using x to build data structures considered harmful
by japhy (Canon) on Jul 18, 2004 at 03:23 UTC
    It's the fact that it's not making copies, it is making aliases. The subroutine's aliasing is another layer, but the fact that 'x' doesn't make copies is the primary thing here.
    _____________________________________________________
    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart