Odd number of elements in hash assignment at ...
at where? The code snippet you present cannot be the cause of the error shown 1). I can't get a clue of what's going wrong if you omit the line number of the error, don't provide the code surrounding that very line, but an entirely unrelated snippet. See How (Not) To Ask A Question.
Are you doing some method call? Remember that the object (or class) is passed in as the first argument calling $obj->method(). Consider:
use strict; use warnings; my $obj = bless do { \my $x }, __PACKAGE__; # current package, e.g. 'm +ain' print "wrong:\n"; $obj->wrong(name =>'John', age => 28); print "-" x 50, "\n"; print "right:\n"; $obj->right(name =>'Paul', age => 30); sub wrong { warn +(caller(0))[3],'(',join(',',map "'$_'", @_),")\n"; my %h = @_; print "$_ => $h{$_}\n" for keys %h; } sub right { warn +(caller(0))[3],'(',join(',',map "'$_'", @_),")\n"; my $self = shift; my %h = @_; print "$_ => $h{$_}\n" for keys %h; } __END__ wrong: main::wrong('main=SCALAR(0x8167870)','name','John','age','28') Odd number of elements in hash assignment at - line 17. Use of uninitialized value in concatenation (.) or string at - line 18 +. 28 => John => age main=SCALAR(0x8167870) => name -------------------------------------------------- right: main::right('main=SCALAR(0x8167870)','name','Paul','age','30') name => Paul age => 30
As for this...
if(!$data{$match}) { $data{$match}++; $count = $count + 1; }
why don't you just $count++ ?
1): There is no assignment to a hash in that snippet, but a post-increment of a hash value keyed with the content of the variable $match
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
In reply to Re: Odd number of elements error
by shmem
in thread Odd number of elements error
by Angharad
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |