<html>
<body>
Thank you.&nbsp; That was exactly the kind of optimization I was looking
for.<br><br>
<br>
At 07:16 PM 9/16/2009, you wrote:<br>
<blockquote type=cite class=cite cite="">If you're going to assign $_ to
$oldname, why not do it straight off the bat? I believe in always naming
variables, anyway. Just because some commands will fill in $_
automatically doesn't mean it's the best way to do things.<br><br>
for my $oldname ( @fileList ) { ....<br><br>
Then you can copy the old name to the new name and re-work it in one
step.<br><br>
my ( $newname = $oldname ) =~ s/.....<br><br>
or if you really don't like that, keep the steps separate:<br><br>
my $newname = $oldname;<br>
$newname =~ s/...<br><br>
If you only want field '10' of stats, why capture the whole
array?<br><br>
my $info = ( stats $oldname )[10]<br><br>
Your date formatting does not provide the underscores your specification
says you want:<br><br>
$date = time2str '%y_%m_%d', $info[10];<br><br>
<br><br>
Most importantly, the search-and-replace is wrong. There are no quotes in
the name. There are four digits not three. You aren't capturing the
xurrent name to reuse in the replace portion. Worst of all, this isn';t a
search-and-replace problem at all<br><br>
my $newname = $date . '_' . $oldname<br><br>
<br><br>
On Wed, Sep 16, 2009 at 6:37 PM, Chris Jones
&lt;<a href="mailto:cj@cr-jay.ca">cj@cr-jay.ca</a>&gt; wrote:<br>

<dl>
<dd>I want to go to the DOS prompt and rename all the files in that
directory with a date prefix if there is no prefix there:<br><br>

<dd>dsc_0023.jpg becomes 16_09_09_dsc_0023.jpg.<br><br>

<dd>I am sure the following can be improved on:<br>

<dd>#!/usr/bin/perl<br><br>

<dd>use strict;<br>

<dd>use warnings;<br>

<dd>use Date::Format;<br><br>

<dd>my $dir = '.\';<br>

<dd>my $date;<br><br>

<dd>my @info;<br>

<dd># Time in seconds since epoch<br>

<dd># atime = info[8]<br>

<dd># mtime = info[9]<br>

<dd># ctime = info[10]<br><br>

<dd># Convert epoch timestamp to YYYYMMDD<br>

<dd>my $created;<br><br>

<dd>my @fileList = glob &quot;${dir}???_????.jpg*&quot;;<br><br>

<dd>foreach (@fileList) {<br>

<dd>&nbsp;&nbsp; next if -d;<br>

<dd>&nbsp;&nbsp; @info = stat($_) || die &quot;Error $!&quot;;<br>

<dd>&nbsp;&nbsp; $date = time2str('%Y%m%d', $info[10]);<br>

<dd>&nbsp;&nbsp; my $oldname = $_;<br>

<dd>&nbsp;&nbsp;
s/&quot;???_???.jpg&quot;/&quot;$date_???_???.jpg&quot;/;&nbsp;&nbsp;&nbsp;&nbsp;
##### &lt;===<br>

<dd>&nbsp;&nbsp; rename $oldname, $_&nbsp; or<br>

<dd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $_ = $oldname,<br>

<dd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; warn $_, ' not renamed: ',
$!;<br>

<dd>}<br><br>
<br><br>

<dd>Chris Jones<br>

<dd>14 Oneida Avenue<br>

<dd>Toronto, ON M5J 2E3.<br>

<dd>Tel.&nbsp; 416-203-7465<br>

<dd>Fax. 416-946-1005<br><br>
<br>

<dd>_______________________________________________<br>

<dd>toronto-pm mailing list<br>

<dd><a href="mailto:toronto-pm@pm.org">toronto-pm@pm.org</a><br>

<dd>
<a href="http://mail.pm.org/mailman/listinfo/toronto-pm" eudora="autourl">
http://mail.pm.org/mailman/listinfo/toronto-pm</a><br><br>

</dl></blockquote>
<x-sigsep><p></x-sigsep>
<br>
Chris Jones<br>
14 Oneida Avenue<br>
Toronto, ON M5J 2E3.<br>
Tel.&nbsp; 416-203-7465<br>
Fax. 416-946-1005<br><br>
</body>
</html>