in reply to Using substr on Hash Keys
The output is:#!/usr/bin/perl use warnings; use strict; my %hash = ( '.111' => 'Aaaa', '.222' => 'Bbbb', '.333' => 'Cccc' ); my %newhash = map { substr ($_, 2) => $hash{$_} } keys %hash; for ( keys %newhash ) { print "$_ => ", $newhash{$_}, "\n"; }
Update: For an in-place transformation, replace %newhash with %hash. e.g.C:\Code>perl newkeys.pl 22 => Bbbb 11 => Aaaa 33 => Cccc
%hash = map { substr ($_, 2) => $hash{$_} } keys %hash;
|
|---|