Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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-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?

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-06-20 06:54 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.