in reply to "not grep iterator" error

This works for me:
perl -we "use strict; sub subby(&\@\@){print qq|in subby..@{$_[2]};\n| +}; my @x=subby sub{print qq|calling...|},my @c, @{[ grep {/\d/} 0..6] +}"
OUTPUT:
in subby..0 1 2 3 4 5 6;

Basically - encapsulate the "grep" result into something that looks like an array (Make an arrayref and dereference it).

But, like Fletch said .. do the right thing, and declare it properly.

     Potentia vobiscum ! (Si hoc legere scis nimium eruditionis habes)

Replies are listed 'Best First'.
Re^2: "not grep iterator" error
by toddfreed (Novice) on Sep 09, 2009 at 21:54 UTC
    You're right, that does work. However, the reason I was using \@ in my prototype was so that I could modify the list. Copying into and then dereferencing a new list defeats the purpose. What I have ended up doing is using a prototype like this
    sub subby(&\@@)
    Then, I can modify the first list (but only pass it in as @list) and for the second list, I can use grep and friends to produce it, which suits my needs. Thanks

      From what you've said, your function takes a callback and two list, modifies the elements of both lists and returns a third list. Your function is insane.

      ( No, I misunderstood. It only modifies the first array which makes the rest of this post moot. The function is still pretty crazy, though )

      Anyway, you seem to be asking how to create an array of aliases. It's actually possible with little work!

      sub foo(\@) { my ($array) = @_; $_ = uc($_) for @$array; } my @array = qw( foo bar Foo Bar ); foo @{ sub { \@_ }->( grep /^[A-Z]/, @array ) }; print "$_\n" for @array;
      foo bar FOO BAR

      Of course, an array wouldn't normally be used at all.

      sub foo { $_ = uc($_) for @_; } my @array = qw( foo bar Foo Bar ); foo grep /^[A-Z]/, @array; print "$_\n" for @array;
      foo bar FOO BAR