Gerard ter Haar ([EMAIL PROTECTED]) wrote: > I have a hash related question. Thanks in advance for your assistance! > > I have quite a large number of values in a hash: > > $errs->{ err_main_notfound } = "file not found. check config."; > $errs->{ err_main_perms } = "no permissions, check docs".; > $errs->{ err_main_unknown } = "unknown error occured."; > > Now I would like to remove the _main part of the hash keys, > so I would get: > $errs->{ err_notfound } = "file not found. check config."; > $errs->{ err_perms } = "no permissions, check docs".; > $errs->{ err_unknown } = "unknown error occured."; > > How can I accomplish this using some perl statements?
The following code is tested: $errs->{ err_main_notfound } = "file not found. check config."; $errs->{ err_main_perms } = "no permissions, check docs."; $errs->{ err_main_unknown } = "unknown error occured."; $errs->{ foo } = "untouched, eh?"; for ( keys %$errs ) { next unless /^err_main_/; my $oldkey = $_; s/^err_main_/err_/; $errs->{$_} = $errs->{$oldkey}; delete $errs->{$oldkey}; } # This is so that we can easily see the contents of the hash. use Data::Dumper; print Data::Dumper->Dump( [$errs], [qw(*errs)] ); Produces this as output: %errs = ( 'err_unknown' => 'unknown error occured.', 'foo' => 'untouched, eh?', 'err_perms' => 'no permissions, check docs.', 'err_notfound' => 'file not found. check config.' ); -- Mike Arms _______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs