Re: commify_series script in cookbook page 94
- From: krahnj@xxxxxxxxx (John W. Krahn)
- Date: Sun, 30 Mar 2008 15:35:14 -0700
yitzle wrote:
my $sepchar = grep( /,/ => @_ ) ? ";" : ",";
And I also don't understand what ";" is doing in the ternary operator??The ";" is what is returned if the condition is TRUE.
"( / ,/ => @_)" is a(n anonymous) hash.
No it is not. /,/ and @_ are just two arguments to the grep() function.
I've had no idea that grep can
operate on a hash.
However, it seems that "grep( / ,/ => @_)" and "grep( / ,/, @_)" are equivalent.
Yes, '=>' and ',' are just different versions of the comma operator.
__CODE__
@a = qw/aa ab ba bb/;
print join(", ", grep(/a/, @a) );
print "\n";
print join(", ", grep(/a/ => @a) );
print "\n";
__END__
aa, ab, ba
aa, ab, ba
@_ is a list/array, and that is what grep is searching for the RegEx / ,/.
perldoc -q "What is the difference between a list and an array"
And the regexp in the example is /,/ not / ,/.
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
.
- References:
- Interpolate variable in a __DATA__ block
- From: Trudge
- Re: Interpolate variable in a __DATA__ block
- From: Gunnar Hjalmarsson
- Re: Interpolate variable in a __DATA__ block
- From: Trudge
- Re: Interpolate variable in a __DATA__ block
- From: Chas. Owens
- commify_series script in cookbook page 94
- From: Richard Lee
- Re: commify_series script in cookbook page 94
- From: Yitzle
- Interpolate variable in a __DATA__ block
- Prev by Date: Re: commify_series script in cookbook page 94
- Next by Date: Re: commify_series script in cookbook page 94
- Previous by thread: Re: commify_series script in cookbook page 94
- Next by thread: Re: commify_series script in cookbook page 94
- Index(es):
Relevant Pages
|