ela said:
Marvellous! You pointed out the problem correctly.
Now I have to use special characters as a separator in the hash name
instead, e.g.
What is a "hash name"? Do you mean the name of the hash, i.e. the
variable name like 'foobar' in '%foobar'? Or are you talking about the
keys in the hash? Either way, neither of them has a seperator.
Furthermore your code doesn't even pass the perl syntax checker.
Not to mention that you should always, yes always, add the obligatory
"use strict; use warnings;" !!! If you had done so then perl would have
given your a very crucial hint.
$cell1="It's a good day!";
$cell2="What?";
hash{"$cell1\%$cells2"}{freq}++;
Global symbol "$cells2" requires explicit package name at [...]
syntax error at [...], near "}{"
to result in:
hash{It's a good day!%What?}{freq}++;
Global symbol "%What" requires explicit package name at [...]
syntax error at [...], near "?}"
Now think about why the compiler may be giving you this specific error
(about the missing symbol, not the syntax error). Why would the compiler
try to interpret %What as a variable name? Think about it!
foreach key (sort (keys(%hash))) {
@tmp = split /\%/, $key
print "$tmp[0]\t$tmp[1]\n";
}
Well, it failed so what's the problem then?
"It failed" is the worst possible error description, along with "it
doesn't work".
I am sure you posted the lasted and most complete code sample you got.
And because you didn't say I must guess that you are stuck right there
with whatever perl is telling you about this piece of code.
Well, the error messages are pretty clear:
syntax error at t.pl line 4, near "}{"
syntax error at t.pl line 6, near "?}"
Missing $ on loop variable at t.pl line 8.
In each case you are missing the '$' sign (the sigil) in front of the
variable name '$hash' resp. '$key'.
Furthermore you have to enclose the key
It's a good day!%What?
in quotes(*) because it is not a single bareword.
And there is the statement separator (i.e. the ';') missing at the end
of
@tmp = split /\%/, $key
HTH
jue