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

How is a prototype of just @ a feature?

lodin

Replies are listed 'Best First'.
Re^6: Module Bloat and the Best Solution
by dragonchild (Archbishop) on Nov 12, 2007 at 18:14 UTC
    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?
      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?

      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?
      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?