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", ... ); ... }