Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Why is my code producing weird output?

by NetWallah (Canon)
on Aug 30, 2023 at 23:23 UTC ( [id://11154177]=note: print w/replies, xml ) Need Help??


in reply to Why is my code producing weird output?

The code works fine for me : Output:
$ perl pm1.pl < pm1-dat.txt george:2~~14 nick:5~~10~~20 peter:3
My perl : This is perl 5, version 34, subversion 0 (v5.34.0) built for x86_64-linux-gnu-thread-multi

Your code uses an un-declared $a which is also used by sort.
Your perl seems to encounter side-effects of that.
I recommend you use a declared variable NOT named $a, or $b.

                "These opinions are my own, though for a small fee they be yours too."

Replies are listed 'Best First'.
Re^2: Why is my code producing weird output?
by hv (Prior) on Aug 30, 2023 at 23:31 UTC

    Note that in the line for $a( sort keys %res ), the work for the sort is completed before the first value is assigned to $a. So while this might not be best practice, I do not think it is causing the problem in this case.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11154177]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2025-06-20 20:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.