NAME

Block::NamedVar - Replacements for map, grep with named block variables.

DESCRIPTION

Gives you nmap and ngrep which are new keywords that let you do a map or grep. The difference is you can name the block variable instead of relying on $_. You can also turn custom map/grep like functions into keywords that act like nmap and ngrep.

SYNOPSIS

#!/usr/bin/perl
use strict;
use warnings;

use Block::NamedVar qw/nmap ngrep/;

my @stuff = qw/a 1 b 2 c 3/
my ( @list, $count );

# grep with lexical $x.
@list = ngrep my $x { $x =~ m/^[a-zA-Z]$/ } @stuff;

# map with lexical $x
@list = nmap my $x { "updated_$x" } @stuff;

# grep with package variable $v
$count = ngrep our $v { $v =~ m/^[a-zA-Z]$/ } @stuff;

# grep with closure over existing $y
my $y;
$count = ngrep $y { $y =~ m/^[a-zA-Z]$/ } @stuff;

# Shortcut for lexical variable
# must be bareword.
$count = ngrep thing { $thing =~ m/^[a-zA-Z]$/ } @stuff;

EXPORTED FUNCTIONS

@out = nmap var { $var ... } @list
@out = nmap $var { $var ... } @list
@out = nmap my $var { $var ... } @list
@out = nmap our $var { $var ... } @list

Works just like map except you specify a variable instead of using $_.

@out = ngrep var { $var ... } @list
@out = ngrep $var { $var ... } @list
@out = ngrep my $var { $var ... } @list
@out = ngrep our $var { $var ... } @list

Works just like grep except you specify a variable instead of using $_.

AUTHORS

Chad Granum exodist7@gmail.com

COPYRIGHT

Copyright (C) 2010 Chad Granum

Block-NamedVar is free software; Standard perl licence.

Block-NamedVar is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.