in reply to How do I move array contents into a directory?

I'm taking a different stab at your problem. I'm not 100% sure about your intent, but if I understand your problem, here is a solution. (I'm sure that there will be more elgant prose to accomplish)
my @the_files = ('apple', 'pear', 'food'); my %image_hash = ('a'=>'z', 'o'=>'u', ); foreach my $file (@the_files) { my $newFile = $file; foreach my $key (keys %image_hash) { my $replaceVal = %image_hash->{$key}; $newFile =~ s/$key/$replaceVal/g; } print "move $file, $newFile or die 'Bummer!' \n"; }
This performs all s// actions in the hash on each file name. The output from the above snippit is:
move apple, zpple or die 'Bummer!' move pear, pezr or die 'Bummer!' move food, fuud or die 'Bummer!'

Replies are listed 'Best First'.
Re^2: How do I move array contents into a directory?
by kyle (Abbot) on Aug 29, 2008 at 17:45 UTC

    If I use warnings and diagnostics, it also says,

    Using a hash as a reference is deprecated

    (D deprecated) You tried to use a hash as a reference, as in %foo->{"bar"} or %$ref->{"hello"}. Versions of perl <= 5.6.1 used to allow this syntax, but shouldn't have. It is now deprecated, and will be removed in a future version.

    Instead of "%image_hash->{$key}", say "$image_hash{$key}".