On Jun 1, Dennis G. Wicks said:
>Greetings;
Please start a new thread next time, instead of replying to a post and
creating a new topic.
> foreach (<FD>) {
> chomp;
> s/^ *//;
> ($rank, $artist) = split(/ /, $_, 2);
Those two lines (the s/// and the split) could be rewritten as:
($rank, $artist) = split ' ', $_, 2;
The ' ' argument to split() ignores leading and trailing whitespace.
>>> if ($name{$artist} eq "") {$cnt{$artist} = 0 ; $r{$artist} = 0 }
Simply do:
if (not exists $name{$artist}) { ... }
The reason you're getting the error is, when the key $artist doesn't exist
in %name, $name{$artist} returns undef, and using undef in a comparison
like '==' or 'eq' gives you the warning message you described.
Using the exists() function is more appropriate here.
> $r{$artist} = $r{$artist} + $rank;
$r{$artist} += $rank;
> $cnt{$artist} = $cnt{$artist} + 1;
++$cnt{$artist};
> $name{$artist} = $artist;
> print qq($rank, $artist), "\n";
> print qq($r{$artist}, $cnt{$artist}, $name{$artist}), "\n";
Why don't you include the \n in the qq() strings? Or, why do you feel the
need to use qq() here when a double-quoted string is fine?
> }
You might want to start including 'use strict' in your code; be aware,
though, that this will require you to declare your variables. Please read
variable scoping documentation to avoid headaches and frustration.
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
CPAN ID: PINYAN [Need a programmer? If you like my work, let me know.]
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>