Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Python dict to perl hash

by garg10may (Initiate)
on Mar 30, 2015 at 12:01 UTC ( [id://1121807]=note: print w/replies, xml ) Need Help??


in reply to Re: Python dict to perl hash
in thread Python dict to perl hash

But I copied that dict from somewhere and need to convert it to hash to work upon it. I cannot have dumper output without the input. So yes you can say in general.

Replies are listed 'Best First'.
Re^3: Python dict to perl hash
by hdb (Monsignor) on Mar 30, 2015 at 13:00 UTC

    If you need THAT hash, here it is

    my %hash = map { chr(65+$_)=>chr(65+($_+13)%26), chr(97+$_)=>chr(97+($_+13)%26)} 0..25;
Re^3: Python dict to perl hash
by Anonymous Monk on Mar 30, 2015 at 12:21 UTC
    But I copied that dict from somewhere ...

    It's still unclear to me whether you're talking about only this one dict? Or whether you have a bunch of different dicts that you need to translate to Perl?

    The code you showed produces an output: a hash(ref) in Perl's own syntax. Copy that output back into your Perl script, replacing your current hash definition, and you'll have a hash defined in pure Perl.

    sub rot13 { my %hash = ( a=>"n", b=>"o", c=>"p", ... ); ... }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (8)
As of 2024-04-23 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found