Richard Lee wrote: > > 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 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/