Hello Monks, I have following code in script.pl(this is only part):
my $i = 'Insert'; $i->dodaj_narzut($products_price, \%zakresy)
There is following code in package "Insert.pm":
sub dodaj_narzut { my ($class,$cena,$zakresy) = @_; my $narzut = $class->ret_narzut($cena,$zakresy); my $new = sprintf('%.2f', $cena+($cena*($narzut/100))); return $class->zaokraglenie($new); } sub ret_narzut { my ($class,$cena,$zakresy) = @_; # use Data::Dumper; # print Dumper($zakresy); while (($zakres,$wartosc) = each %$zakresy) { my @zak = split '-', $zakres; if ($cena > $zak[0] and $cena <= $zak[1]) { return $wartosc; } } print "55\n"; return 55; }
The problem is that in subroutine "dodaj_narzut" half of the time it's like hash reference doesn't exist. It skips while loop. Next time when subroutine is executed it works perfectly - it goes through while loop and returns proper "$wartosc". But if I uncomment "Use Data::Dumper" and "print Dumper($zakresy)" while loop is executed every time. When I resign on using references it also works OK every time. It must be something with the references.

Thank you for any help.
Best regards,
Jerzy

In reply to Half of hash references are missing by jerzy

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.