Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Loop through all directory and files and lines

by 1nickt (Canon)
on Oct 18, 2018 at 13:32 UTC ( [id://1224233]=note: print w/replies, xml ) Need Help??


in reply to Loop through all directory and files and lines

Hi, please post an SSCCE. The code you have shown does not compile. It certainly looks as if your solution does not need to be this complicated, but it's hard to know since the code is incomplete.

Your problem description is also unclear. "I want to go into first directory/i/j/*" -- this path does not look like a directory.

If you haven't yet done so, take a look at the module I recommended in your previous thread, Path::Iterator::Rule. Or another module by the same author, Path::Tiny, which provides the handy visit() method. The following should do what you want:

use strict; use warnings; use feature 'say'; use Path::Tiny; use List::Util 'any'; my $regexp = qr/(?:TbhODK|octuov|qas_uop)/; my $found = path('/some/path')->visit( sub { my ($path, $results) = @_; return if $path->is_dir; $results->{$path}++ if any { /$regexp/ } $path->lines; }, { recurse => 1 }, ); say for keys %{ $found }; __END__

Hope this helps!


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Loop through all directory and files and lines
by MissPerl (Sexton) on Oct 18, 2018 at 14:25 UTC
    Hi 1nickt ! I have updated the code, could you try and run once?

    while I go through your code for now thank you !!

    I really wish to know what's wrong in the code. :'(

    I have review your code. seems like this two Path::Tiny; and List::Util 'any' are helpful module!

    I wasn't allowed to install module in the laptop. but I will be sure to check out these soon for own knowledge!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-25 09:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found