Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: sequencial file naming

by mrmick (Curate)
on Jun 08, 2001 at 20:36 UTC ( #86969=note: print w/replies, xml ) Need Help??


in reply to sequencial file naming

One way is to get a list of the matching files in the directory, sorting them and adding to the digit. This example outputs last digit and the new filename to STDOUT to demonstrate:

(remember to use strict when programming)

$dir='path to directory'; opendir D, $dir or die "Cannot open directory $dir: $!\n"; while( defined (my $file = readdir(D)) ) { if ($file =~ /\.dat$/){ push(@files,$file); } } closedir D; @files = sort @files; @filename = split(/\./,$files[$#files]); print $filename[0],"\n"; $filename = ($filename[0] + 1) . '.dat'; print $filename,"\n";

Mick

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://86969]
help
Chatterbox?
[LanX]: what is the intention of your question?
[LanX]: why do you need to see the nodelet without votes left???
[marinersk]: LanX, the problem is that the lack of interface visual stability is disconcerting to me. The Nodelet appearing and disappearing is distracting, and despite over a decade, still troubles me. It jangles me.

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2017-05-29 13:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?