rs wrote: > Hi, > Here's a snippet of some code from the cookbook. Hmm, time to get a new cookbook :~)
> I am trying to understand what $seen{$1} is. ie where did $1 come > from, and what is in $seen{$1}, and how is the hash populated? $1 is a built-in variable that is set by capturing parens in a regular expression. It's not being set in the script below, and the script below doesn't properly capture the unique characters. > thanks. > Radhika > ======================== > #!/usr/bin/perl > > #use strict; > #use diagnostics; > > my %seen = (); > my $string ="an apple a day"; > foreach $byte (split //,$string) { > $seen{$1}++; This should presumably be $seen{$byte}++; > } > print "unique chars are: ", sort(keys %seen), "\n"; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>