This seems like a good place to add debugging statements using Data::Dumper (Basic debugging checklist). For example, if you show $second_directory, you'll see

$VAR1 = '/somewhere//1/2'; $VAR1 = '/somewhere//3/4'; $VAR1 = '/somewhere//5/6';

So first of all, you'll notice the double slashes, which is an issue that you can fix using e.g. File::Spec's catfile and catdir instead of building the strings yourself.

Second, you might notice that '/somewhereelse/' is missing. This is because splice is a destructive operation. As poj showed, one possible solution would be to move the declaration of @store_array right before the while loop that uses it. poj's code also shows how the if with three regexes can be more efficiently written as if ( /TbhODK|octuov|qas_uop/ ), and opening the $store_location once, at the start of the program, instead of re-opening it in append mode for each line of output.

In general, glob has several caveats, which might apply in your case, since you're using variables in the patterns. Switching to one of the other file-handling modules, such as Path::Class and/or File::Find::Rule, would help there.

Other than that, your code looks relatively ok to me; whether it works for you or not will depend on whether the directory structure matches what your code is doing, which we can't tell.


In reply to Re: Loop through all directory and files and lines by haukex
in thread Loop through all directory and files and lines by MissPerl

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.