Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-24 10:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found