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

Re: Loop through all directory and files and lines

by haukex (Archbishop)
on Oct 19, 2018 at 11:14 UTC ( [id://1224331]=note: print w/replies, xml ) Need Help??


in reply to Loop through all directory and files and lines

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1224331]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-25 13:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found