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


In reply to Re: How do I move array contents into a directory? by TGI
in thread How do I move array contents into a directory? by tonyz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.