Thomas Wright wrote: > > Hi folks. > > I need to select a single file name from a list of filenames and assign it > to a variable. > > I currently do this in a few shell scripts using: $last_file=`ls -1r > somedata_file.dat.*.orig | head -1`
If you translate this to perl it becomes: my $last_file = (sort { $b cmp $a } <somedata_file.dat.*.orig>)[0]; > The "*" represents a timestamp in the filename. This allows me to select the > most recent file, in this case. > > as an example, this would return a value such as : > somedata_file.dat.20011203130101.orig which would be stored in $last_file > > When I do this in Perl thusly: > > $oldfile = `system "ls -1r $oldfile.\*.orig | head -1"`; $oldfile = (sort { $b cmp $a } <$oldfile.dat.*.orig>)[0]; > Where $oldfile contains the first part of a filename passed in via > Getopt::Long . John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]