if ($alphabet{$s} % 2) {

The problem must be here somehow, becase you're using the % operator only here. The warning indicates that one operand of % is undefined. 2 is a defined constant, so $alphabet{$s} must be undef. %alphabet mus have been filled somehwere else, you didn't show that code, $s comes from a very "ugly" part of your code:

foreach $record (@contents) { # where does @contents come from? # you said a flat-file: why did you read the whole # file into an array, if you did? is that neccessary? # you'll probably rather like while(defined(my $record = <$flatfilehandle>)){ @fields = split(/\|/,$record); # @fields is global? probably not my @fields = split... $tidm=$fields[0];$tidm=~s/\s+$//g; $nice=$fields[1];$nice=~s/\s+$//g; #it's much easier to say my ($tidm,$nice) = split /\|/,$record; # and it's more effective to drop the /g, for it's # completely useless: You cannot mach the EOString more # than one time. Correct me if these variables might # contain multiple lines, but i'm "quite sure" they don't # :) $s = substr($nice,0,1);

So now $s holds the first character of $nice. If $nice is empty, $s will be empty, too. Do you have the key '' in your hash %alphabet. $s may be any character (apart from '') depending on the input, are all cases covered in %alphabet? If not, consider assuming a default:

(defined $alphabet{$s} ? $alphabet{$s} : 0) % 2 # use exists() if all values of %alphabet are defined
--
http://fruiture.de

In reply to Re: uninitialized value in modulus (%) by fruiture
in thread uninitialized value in modulus (%) by alexiskb

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.