in reply to Re^2: Unshift and push inside of map operation.
in thread Unshift and push inside of map operation.

I meant "doesn't work well" in the sense LNEDAD wanted to use it.
  • Comment on Re^3: Unshift and push inside of map operation.

Replies are listed 'Best First'.
Re^4: Unshift and push inside of map operation.
by ikegami (Patriarch) on Sep 23, 2008 at 04:30 UTC

    Whatever you meant doesn't apply to both foreach and map.

    foreach doesn't work well with changing arrays.
    map works well with changing arrays.

    foreach can do what the OP wants, but not well.
    map doesn't do what the OP wants at all.

      Um no. map doesn't like changing arrays either:
      #!/usr/bin/perl use Devel::Peek; @a = (1,2); @b = map { pop @a; Dump $_; } @a; $ perl5100 /tmp/p SV = IV(0x9cd41d4) at 0x9cd41d8 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 1 SV = UNKNOWN(0xff) (0x9cd40b8) at 0x9cd4308 REFCNT = 0 FLAGS = ()

      Dave.