Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Bare BLOCK vrs. grep BLOCK

by AnomalousMonk (Archbishop)
on Jan 16, 2018 at 02:32 UTC ( [id://1207331]=note: print w/replies, xml ) Need Help??


in reply to Bare BLOCK vrs. grep BLOCK

Here's something that's rather crass, but maybe something like it will save you from venturing into dark regions:

c:\@Work\Perl\monks>perl -wMstrict -le "sub working { my @x = (1, 0, 2); my @y = grep { print qq{in grep: '$_'}; return 'byebye'; } @x; print 'still in working(): ', qq{(@y)}; return @y; } my @z = working; print qq{from working(): (@z)}; " in grep: '1' from working(): (byebye) c:\@Work\Perl\monks>perl -wMstrict -le "sub mygrep (&@) { my $code = shift; my @result; for (@_) { no warnings 'exiting'; push(@result, $_) if map { print 'in map: ', qq{'$_'}; $_; } &$code; } MYGREP_FINAL: return @result; } ;; sub notworking { my @x = (4, 0, 3); my @y = mygrep { print qq{in mygrep: '$_'}; goto MYGREP_FINAL; } @x; print 'still in notworking(): ', qq{(@y)}; return @y; } ;; my @z = notworking; print qq{from notworking(): (@z)}; " in mygrep: '4' still in notworking(): () from notworking(): ()


Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1207331]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-18 08:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found