in reply to Re^5: Module Bloat and the Best Solution
in thread Module Bloat and the Best Solution

Because it allows me to write code like my @foo = map { [whatever] } uniq @arr1, uniq @arr2; With the prototype, this parses to uniq(@arr1), uniq(@arr2);. Without the prototype, this parses to uniq(@arr1, uniq(@arr2));. See the difference?

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re^7: Module Bloat and the Best Solution
by educated_foo (Vicar) on Nov 12, 2007 at 18:29 UTC
    Nope, you need "\@" for that.
      Try it.

      Update: lodin has pointed out my confusion between @ and \@. However, this only makes my point even clearer - I know how to manage prototypes, but I get them confused. Furthermore, lodin pointed out a place where \@ would be poor (uniq( map { ... } @foo )). Given that, it's good that someone who actually gives a damn about prototypes has thought about the issues and provided the best solution.


      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re^7: Module Bloat and the Best Solution
by lodin (Hermit) on Nov 12, 2007 at 18:26 UTC

    That sounds weird. Which perl are you using? For all I know, that difference in parsing shouldn't happen.

    lodin

      Try it. The difference in parsing is specifically why prototypes exist.

      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re^7: Module Bloat and the Best Solution
by codeacrobat (Chaplain) on Nov 13, 2007 at 20:23 UTC
    Why not just uniqify both arrays with one uniq?
    perl -MO=Deparse -MList::MoreUtils=uniq -e ' @arr1=(1,2,1); @arr2=(2,3,3); my @foo = map { $_ } uniq @arr1, @arr2; print @foo ' use List::MoreUtils (split(/,/, 'uniq', 0)); @arr1 = (1, 2, 1); @arr2 = (2, 3, 3); my(@foo) = map({$_;} uniq(@arr1, @arr2)); print @foo; -e syntax OK
    perl -MList::MoreUtils=uniq -e ' @arr1=(1,2,1); @arr2=(2,3,3); my @foo = map {$_ } uniq @arr1, @arr2; print @foo ' 123

    print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});
      What if the arrays are (1, 2, 2, 3) and (1, 3, 5) and I want my map to run over (1, 2, 3, 1, 3, 5) ? Doesn't matter why ... what if that is the requirement?

      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
        Well then an alternative is to use brackets.
        map { something } uniq(@arr1), uniq (@arr2).
        The saving of 4 brackets
        map { something } uniq @arr1, uniq @arr2.
        comes at the cost of looking in the code and finding out (and remembering) the signature. If the whole developing team uses List::MoreUtils and prototypes are well understood by everyone then its ok to save the brackets. Otherwise, and that is my personal opinion, preserve the default semantic of list flattening and be explicit by using brackets.

        print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});