Hi,
Here's a snippet of some code from the 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?
thanks.
Radhika
#!/usr/bin/perl
#use strict;
#use diagnostics;
my %seen = ();
my $string
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
On Tue, 26 Oct 2004 16:50:11 -0400, Bob Showalter
[EMAIL PROTECTED] wrote:
rs wrote:
Hi,
Here's a snippet of some code from the cookbook.
Hmm, time to get a new cookbook :~)
Nope. Just make sure you understand the the OP changed the code
quoted from the cookbook, and that the
%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
Interesting.
Why doesn't this skip already seen letters, I used the
case-insensitive modifier...
%seen = ( );
$string = AaBbCcDdEeFf;
while ($string =~ /(.)/gi) {
$seen{$1}++;
}
print \n\nunique chars are: , sort(keys %seen), \n;
'A' and 'a' are the same, or is the logic only char()
Simply put, the dot (.) matches everything regardless of modifier switch.
--
WC -Sx- Jones
http://youve-reached-the.endoftheinternet.org/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response
On Tue, 2004-10-26 at 22:00, Chasecreek Systemhouse wrote:
Interesting.
Why doesn't this skip already seen letters, I used the
case-insensitive modifier...
%seen = ( );
$string = AaBbCcDdEeFf;
while ($string =~ /(.)/gi) {
$seen{$1}++;
}
print \n\nunique chars are: , sort(keys