Re: commify_series script in cookbook page 94
- From: rich.japh@xxxxxxxxx (Richard Lee)
- Date: Sun, 30 Mar 2008 19:19:58 -0400
Rob Dixon wrote:
Richard Lee wrote:thanks guys!!
While reading perl cookbook, I came to page 94 and having a hard time understanding this particular phrase
my $sepchar = grep( /,/ => @_ ) ? ";" : ",";
I recognize the ternary operator and grep but I am not sure how they are forming the meaning together.
I thought grep needed lists to work on ? and grep(/,/ => @_), I am not sure where it's getting the list from
my @results = grep EXPR, @input_list;
my $count = grep EXPR, @input_list;
And I also don't understand what ";" is doing in the ternary operator??
I think I understand the rest of the program though..
Can someone help me out please?
The => operator is misleading - it's exactly equivalent to a comma in
this case, so
grep(/,/, @_)
(in scalar context) returns the number of elements of @_ that contain a
comma character. Either comma or semicolon is assigned to $sepchar
according to whether that count is false (zero) or true (non-zero).
So, in plain English, if any of the elements of @_ contain a comma then
$sepchar is set to a semicolon; otherwise it is set to a comma.
HTH,
Rob
Understood them.. moving on.....
.
- 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: Rob Dixon
- Interpolate variable in a __DATA__ block
- Prev by Date: Re: commify_series script in cookbook page 94
- Next by Date: Re: sort without ignoring hyphens
- 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
|
|