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

Your image hash parsing code makes the regex engine work harder than necessary. I've reworked this bit to show several alternatives.

The problem is that /.* .*/ creates a lot of unnecessary backtracking. The regex engine is greedy, so it will scan the whole string and match it to the leading '.*'. Then it has to back track and remove one character at a time until it finds a space. If you write /[^ ]* .*/, then the engine can read until it finds a space, then move on the next match criterion, must be a space, match that and slurp in the rest of the string to match the final '.*'. I once read a great article that talked about this in detail, but I can't track it down.

my %image_hash = ( ); while (<IMAGEHASH>) { # Limited scope of $search/$replace # You could just use split to split on whitespace: my ($search, $replace) = split; # Or if you want to split on the first single space character, and + force only 2 items: # my ($search, $replace) = split ' ', $_, 2; # or you could use a regex: # my ($search, $replace) = m/([^ ]*) (.*)/); # Suppress uninitialized warnings. # check for non-zero length, # although eq '' checks should be fine, too. { no warnings 'uninitialized'; if ( length $search and length $replace ){ warn "Found uplicate entry for: $search\n" if exists $image_hash{$searc}; $image_hash{$search} = $replace; } } }

Warning: all code untested.


TGI says moo