develooper Front page | perl.perl5.porters | Postings from September 2013

[perl #120047] perl should enable "$_" for use before calling subs

Thread Previous
From:
Victor Efimov via RT
Date:
September 29, 2013 13:25
Subject:
[perl #120047] perl should enable "$_" for use before calling subs
Message ID:
rt-3.6.HEAD-31239-1380461118-945.120047-15-0@perl.org
On Sun Sep 29 05:57:53 2013, aristotle wrote:
> The design reason is that a user subroutine may well be interested in
> the value that was previously in $_, even if that was a read-only value.

example of this:
===
use v5.10;
use strict;
use warnings;

my @a = (1, 2, undef, 3);

print grep { defined } @a;
print "\n";

sub is_even(_)
{
 shift() % 2 == 0;
}

print grep { defined && is_even } @a ;
print "\n";

===
prints:

123
2

i.e. we define function "is_even" which acts like (builtin!) "defined"
function (i.e. can accepts $_ as argument).


---
via perlbug:  queue: perl5 status: rejected
https://rt.perl.org:443/rt3/Ticket/Display.html?id=120047

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About