Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: check for latest file, remove and touch file?

by fasoli (Beadle)
on Jan 05, 2016 at 16:25 UTC ( [id://1151979]=note: print w/replies, xml ) Need Help??


in reply to Re: check for latest file, remove and touch file?
in thread check for latest file, remove and touch file?

"Do you want the "latest file" as per the filesystem or the highest-sequence file as per your naming convention? Is the inode change time important? The modification time? Is it just the filename? What if the files get out of sync and you end up having S0007 but not S0006? Do you want to still delete S0005 if it exists? Why not sort your files, pop the two newest off the array, then delete the rest if making sure you have the two newest available is what you're actually trying to do?"

Sorting the files and popping the two newest off the array does sound like a good idea but I'll have to think about it and see if it works for my case. Thank you for the recommendation.

I thought about this and I think the best way to proceed in my case will be to look for a file with the biggest number (S0007 over S0005 for example), then look if the previous one is there, remove the previous one and proceed to create the next one. So if 7 is there, check if 6 is there, delete 6 and proceed to create 8. I'll have to think about the rest of my script and read up a tutorial to figure out my other issues, but if I can get past the thing that I just described it would be great. Can someone help me regarding how I can do that within my $step variable? How can I say "if we are at step x, check step x-1 exists and create step x+1"?

  • Comment on Re^2: check for latest file, remove and touch file?

Replies are listed 'Best First'.
Re^3: check for latest file, remove and touch file?
by 1nickt (Canon) on Jan 05, 2016 at 17:29 UTC

    Can someone help me regarding how I can do that within my $step variable? How can I say "if we are at step x, check step x-1 exists and create step x+1"?

    At this point you really should step back from your thinking on how to solve your "problem" and reexamine the overall task. Please say what you're really trying to do (beyond manipulating filenames), and especially what data you want to have available as your "backup."

    It's possible that your whole premise "a script for data handling that will loop through a variety of files and do a variety of things" could be misguided.

    The way forward always starts with a minimal test.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-24 12:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found