Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: Globbing for file in an unkown directory path only works first time in foreach loop?

by Anonymous Monk
on Jan 29, 2016 at 20:09 UTC ( [id://1154023]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Globbing for file in an unkown directory path only works first time in foreach loop?
in thread Globbing for file in an unkown directory path only works first time in foreach loop?

Okay, actual code:

close but but not quite

See how I write code that first generates the requird files for the rest of the code to run?

You don't actually want me to manually have to go create files do you?

All that run tells me is that day 4257 doesn't have a file -- you say that is a problem, but how can I tell if the file really exists or not, other than you saying it does, but your code saying it doesn't?

I don't think you have a file there

  • Comment on Re^3: Globbing for file in an unkown directory path only works first time in foreach loop?

Replies are listed 'Best First'.
Re^4: Globbing for file in an unkown directory path only works first time in foreach loop?
by MarsRover (Novice) on Jan 29, 2016 at 20:11 UTC

    look at the output! it access the same file both runs, just the first time it finds it and the second time through the foreach loop it doesn't. I'll try and write it your way while you look

    notice the array it is scanning through has 4257 as it's first element and it's second. It finds the 4257 file through the foreach the first time, but then one the foreach move to the second element in the array, which happens to be the exact same as the first element, it can't find the same file it just found.

      How many files do you expect to find with

      glob('/home/myfiles/day_of_year/'.$day_of_year.'/*/desired_file.txt');

      Is it only 1 ?

      poj

        yes only one

        the directory structure looks something like

        /home/myfiles/day_of_year/255/data/JPF_374362/desired_file.txt

        /home/myfiles/day_of_year/256/data/EJF_264827/desired_file.txt

        /home/myfiles/day_of_year/257/data/FFE_387392/desired_file.txt

        where after the data directory there is a day specific ID (three letters, underscore, and then a bunch of numbers, all are unpredictable for each day) and within there is the file named desired_file.txt
Re^4: Globbing for file in an unkown directory path only works first time in foreach loop?
by MarsRover (Novice) on Jan 29, 2016 at 20:19 UTC
    i tried to mimic your code and i don't have the Tiny module. I'm working with some reallllly antiquated systems here

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-20 16:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found