Friday, December 31, 2010

GREP examples

my @selected = map { /before(pattern)after/ ? $1 : () } @all;


next unless grep {$_ eq $fromdevice} @sitenamekeys); 


@map_results1 = map { substr $_, -3 } grep { /^[Ff]/ } @map_results1;



@array = ( 'hai','hello','bar','foo' ) ;

print grep (/hai/ , @array );
hai
# writes all elements from @array containing 'hai' in them

print grep ("hai",@array ) ;
haihellobarfoo
# writes all elements, because "hai" evaluates to true

print map (/hai/ , @array );
1
# writes 1 for the only element from the @array, that contains 'hai'

print map ("hai",@array ) ;
haihaihaihai
# maps 'hai' to each element from @array

No comments: