> 
>   %seen = ( );
>   $string = "an apple a day";
>   foreach $char (split //, $string) {
>       $seen{$char}++;
>   }
>   print "unique chars are: ", sort(keys %seen), "\n";
> 
> Also, a couple of paragraphs later, the Cookbook goes on to show how
> to solve the same problem with a while loop and a regular expression:
> 
>   %seen = ( );
>   $string = "an apple a day";
>   while ($string =~ /(.)/g) {
>       $seen{$1}++;
>   }
>   print "unique chars are: ", sort(keys %seen), "\n";
> 
> In that example, the parens are grabbing a character and dropping it
> into $1.  Somehow the OP got the two examples mixed up.
> 
> Hey OP, since we've pointed out the mix-up, does this clear up your
> question?  Or do you still not understand what the two above examples
> are saying?

I realized I should have added a bit more reference information to the
post.  For those of you new to the list, "OP" stands for "Original
Poster".  In this context, I'm talking about and to Radhika.

For those of you with or without a copy of the "Cookbook" we're
talking about, I'm referring specifically to the "Perl Cookbook, 2nd
Edition" book written by Tom Christiansen, Nathan Torkington.  The
code snippets above come from Chapter 1, section 1.6, titled "Recipe
1.6 Processing a String One Character at a Time".  I hope that helps
add some context.

-Errin

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to