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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.