Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: A regarding glob

by LanX (Chancellor)
on May 16, 2013 at 18:26 UTC ( #1033883=note: print w/replies, xml ) Need Help??

in reply to Q regarding glob

please use <code> tags around your code.

> Is there any easy way to get it?

No, not what you intend with "easy"!

Use a regex or split or substr to isolate what you wanted from the full path


DB<106> $head="/tmp/";$tail="/foo/file" => "/foo/file" DB<107> $path= <$head*$tail> => "/tmp/bla/foo/file" DB<108> ($middle) = $path =~ /^\Q$head\E(.*)\Q$tail\E$/ => "bla"

Easy enough! (?)


FWIW a one liner:

DB<109> ($middle) = <$head*$tail> =~ /^\Q$head\E(.*)\Q$tail\E$/ => "bla"

added quotemeta


Not sure if I misunderstood your question or if you phrasing is just fuzzy. What are folder names inside dir2 ?

Cheers Rolf

( addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^2: A regarding glob
by arunagiri (Initiate) on May 17, 2013 at 00:19 UTC
    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
      > 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!;
        Thanks for your time.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1033883]
[MidLifeXis]: (5.22 at that time)
[MidLifeXis]: Yeah, I know, really helpful :-)
[Corion]: If all else fails, Spreadsheet::XLSX should be "installable" by manually copying the files, provided that the prerequisites are met
[thezip]: It fails in the "formatted 2-digit numeric" tests
[thezip]: Okay Corion, that's what I wanted to hear. Thanks!
[Corion]: Oh, a test failure... Just force-install it then? --force and potentially --notest to skip the tests alltogether ?
[ambrus]: thezip: is Activestate Perl usable for your scenario instead?
[MidLifeXis]: Yeah, --notest is good, not sure I would do --force.
[thezip]: It fails 2/10 tests in that group. What are the ramifications if I force it? What should I look for for?
[thezip]: I've migrated from ActiveState to Strawberry. No going back...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (16)
As of 2017-03-23 17:16 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (290 votes). Check out past polls.