package Cheesy; use strict; use warnings; use Exporter; our (@ISA, @EXPORT_OK); @ISA = qw(Exporter); @EXPORT_OK = qw( grep map ); sub grep (&\@) { my $code = shift; my $ref = shift; return CORE::grep &$code, @$ref if defined wantarray; @$ref = CORE::grep &$code, @$ref; } sub map (&\@) { my $code = shift; my $ref = shift; return CORE::map &$code, @$ref if defined wantarray; @$ref = CORE::map &$code, @$ref; } 1; #### #!/usr/bin/perl -w use strict; use Cheesy qw(map grep); my (@foo, # tested @bar); # desired @foo = (1 .. 5); map {$_ * 10} @foo; @bar = (10, 20, 30, 40, 50); print "@foo\n"; print "Should be: @bar\n"; @foo = (1 .. 5); Cheesy::map {$_ * 10} @foo; @bar = (10, 20, 30, 40, 50); print "@foo\n"; print "Should be: @bar\n"; @foo = qw(fish chicken cheese); grep {$_ eq 'cheese'} @foo; @bar = ('cheese'); print "@foo\n"; print "Should be: @bar\n"; @foo = qw(fish chicken cheese); Cheesy::grep {$_ eq 'cheese'} @foo; @bar = ('cheese'); print "@foo\n"; print "Should be: @bar\n"; #### 1 2 3 4 5 Should be: 10 20 30 40 50 10 20 30 40 50 Should be: 10 20 30 40 50 fish chicken cheese Should be: cheese cheese Should be: cheese