- 论坛徽章:
- 0
|
原帖由 Lonki 于 2007-11-9 16:45 发表
先$count{$_}, 得到的东西++
你说的报错是未初始化吧? 正常的.
不是未初始化
#!/usr/bin/perl -w
use strict;
my @people=qw/hwllo hello yaya llll hwllo hwllo baby llll/;
foreach (@people)
{
print "数组的内容是:\n";
print"$_\n";
}
my %count;
#$count{$_}++ foreach(@people);
print "test hash##########\n";
foreach(@people)
{
print "($_)\n";
my $hash_val=$count{$_};
#print "now hash is: $hash_val\n";
print "now hashh is: $hash_val\n"; #18行
$count{$_}++;
#$count{$_}=$count{$_};
#$count{$_}+ 1;
}
##################################
输出的结果是
数组的内容是:
Use of uninitialized value in concatenation (.) or string at D:\workspace\perl\hash.pl line 18.
hwllo
数组的内容是:
hello
数组的内容是:
yaya
数组的内容是:
llll
数组的内容是:
hwllo
数组的内容是:
hwllo
数组的内容是:
baby
数组的内容是:
llll
test hash##########
(hwllo)
now hashh is:
(hello)
now hashh is:
(yaya)
now hashh is:
(llll)
now hashh is:
(hwllo)
now hashh is:1
(hwllo)
now hashh is:2
(baby)
now hashh is:
(llll)
now hashh is:1
Use of uninitialized value in concatenation (.) or string at D:\workspace\perl\hash.pl line 18.
Use of uninitialized value in concatenation (.) or string at D:\workspace\perl\hash.pl line 18.
Use of uninitialized value in concatenation (.) or string at D:\workspace\perl\hash.pl line 18.
Use of uninitialized value in concatenation (.) or string at D:\workspace\perl\hash.pl line 18.
哪位高人幫忙講解下foreach裏邊
$count{$_}++;時散列的變化,哪怕只講一兩個數組元素
暈,輸入法怎麽突然變成了繁體的?
[ 本帖最后由 yuio654 于 2007-11-9 18:06 编辑 ] |
|