hello again dominick_t
An explicit array is @arr = qw(a b x) and an anonymous one is $array_ref = [qw(c d e)]
Use print and/or Data::Dumper or better Data::Dump to se in action:
my $array_ref = [qw(c d e)]; print Dumper $array_ref;
The doc covering this is perlref
> %chars hash, are you saying that a new hash is made for each word in the list, and that the keys of that hash are the individual characters in the word?
Yes! try it to see; print is your first debugging tool:
use strict;
use warnings;
my $good = [qw( allo mallo malo)];
my $bad = [qw( tillo sillo sallo)];
foreach my $list ($good, $bad){
print "got list [@{$list}]\n";
my $has_unique;
foreach my $word(@$list){
print "analizing word [$word]\n";
my %chars;
foreach my $char ($word =~ /./g){
print "\tGot char [$char]\n";
$chars{$char}+= 1;
}
print "\tchars count is:\n";
print map{"\t$_ = $chars{$_} "}keys %chars;
print "\n";
if (scalar keys %chars == length $word){
print "\t$word has no repeated letters (keys of \%chars
+ are equal to the length of \$word)\n";
$has_unique++;
}
print "\n";
}
print "I print the whole list: ",(join ' ', @$list),"\n\n" if $has
+_unique;
}
# output
got list [allo mallo malo]
analizing word [allo]
Got char [a]
Got char [l]
Got char [l]
Got char [o]
chars count is:
l = 2 a = 1 o = 1
analizing word [mallo]
Got char [m]
Got char [a]
Got char [l]
Got char [l]
Got char [o]
chars count is:
l = 2 a = 1 m = 1 o = 1
analizing word [malo]
Got char [m]
Got char [a]
Got char [l]
Got char [o]
chars count is:
l = 1 a = 1 m = 1 o = 1
malo has no repeated letters (keys of %chars are equal to the
+length of $word)
I print the whole list: allo mallo malo
...
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|