Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: A regarding glob

by arunagiri (Initiate)
on May 17, 2013 at 00:19 UTC ( #1033927=note: print w/ replies, xml ) Need Help??


in reply to Re: A regarding glob
in thread Q regarding glob

Sorry if I didn't mention it clearly. There are many folders inside dir2. Eg: A1, B1, C1 etc: are the folder inside dir2. only A1 and B1 folders have a file names "hello.txt" Hence, I want only the names of A1 and B1. If I do glob from some other folder like glob ("../../dir1/dir2/*/hello.txt") How can I get the only folders A1 and B1. I am going through the various suggestions that you guys gave. I will try them out. Thanks


Comment on Re^2: A regarding glob
Re^3: A regarding glob
by LanX (Canon) on May 17, 2013 at 01:53 UTC
    > Sorry if I didn't mention it clearly.

    Sorry still not clear! (And unfortunately you didn't update your posts with code-tags either).

    2 possibilities:

    • If you want the whole sub-path which fills into the wild-card, then the demonstrated code is already perfect. Try it out.

    • If you're only interested in the highest level folder do a @folders = split '/', $path for every path found by your glob and just take $folder[$index], where index is the number of folders in the "head" part.

      E.g 4 for "../../dir1/dir2/" will give you the next directory after "dir2".

    HTH! =)

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      I find the solution easier with both split and

       $element =~ m!dir1/dir2/(.*)/dir3/filename!;
        It's the same solution, just less abstract and therefore more vulnerable for typos and other errors!

        Good luck! =)

        Cheers Rolf

        ( addicted to the Perl Programming Language)

      Thanks for your time.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2014-09-23 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (241 votes), past polls