in reply to File Name Pattern
use printf or sprintf:
To get the first three digits:printf("%06d\n",$_) for (123, 1234, 12345, 123456); my $val = sprintf("%06d",123);
You might want to look at File::MMagic if you have to ensure that the files really are jpg's.my $name = '012345'; my ($three) = $name =~ /^(\d\d\d)/;
UPDATE:
more code for you :)
use strict; while (<DATA>) { chomp; my ($numbs) = $_ =~ /^(\d+)/; my $formatted = sprintf("%06d",$numbs) . '.jpg'; my ($dir) = $formatted =~ /^(\d\d\d)/; print "filename: $formatted\t\tdirname: $dir\n"; } __DATA__ 123.jpg 1234.jpg 12345.jpg 123456.jpg
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (jeffa) Re: File Name Pattern
by FamousLongAgo (Friar) on Dec 13, 2002 at 16:52 UTC |