J
Justin C
#!/usr/bin/perl
use warnings ;
use strict ;
use File::Copy ;
open ( CSV, '<', "forthcoming_releases.csv" )
or die "Cannot open csv file: $!" ;
foreach ( <CSV> ) {
chomp ;
if ( my ($newname, undef, undef, undef, $oldname) = split /,/ ) {
print $newname, "\t", $oldname, "\n" ;
$newname .= ".jpg" ;
$oldname = $oldname . ".jpg" ;
print $newname, "\t", $oldname, "\n" ;
move ( $oldname, $newname ) ;
}
}
The two print statements are there to help me debug, but they're no help!
A sample of the CSV:
1,AC/DC,2003 Logo,TS,ts_ac_2003
2,AC/DC,A5 Highway Fire,JO,jo_ac_a5highw
3,AC/DC,Album Stiff,TS,ts_ac_albumst
4,AC/DC,Amp,TS,ts_ac_amp
5,AC/DC,Angus,TS,ts_ac_angusb
6,AC/DC,Angus Caricature,SB,sb_ac_angus
7,AC/DC,Angus Comin' At Ya,HF,hf_ac_angusco
8,AC/DC,Angus For Those,TS,ts_ac_angusf
9,AC/DC,Angus Head,RP,rp_ac_angushe
10,AC/DC,Angus Let,TS,ts_ac_angusle
The last field in the CSV is the current filename without the .jpg,
the first field is a unique number, I'm trying to name these files
sequentially, but with .jpg
As you can see I've tried two methods for concatenation and neither
seems to do what I'd expect. $oldname never gets .jpg appended and
$newname starts of being .jpg, then .jpgpj, and lastly (for 3 digit
numbers) .jpgjpg. I can see what is happening with $newname but don't
understand why.
If someone could point me at an explanation here I'd be grateful. I've
never had trouble with assignment before, well, not like this. The code
looks right to me but obviously I know nothing!
Thanks for any help you can give.
Justin.
use warnings ;
use strict ;
use File::Copy ;
open ( CSV, '<', "forthcoming_releases.csv" )
or die "Cannot open csv file: $!" ;
foreach ( <CSV> ) {
chomp ;
if ( my ($newname, undef, undef, undef, $oldname) = split /,/ ) {
print $newname, "\t", $oldname, "\n" ;
$newname .= ".jpg" ;
$oldname = $oldname . ".jpg" ;
print $newname, "\t", $oldname, "\n" ;
move ( $oldname, $newname ) ;
}
}
The two print statements are there to help me debug, but they're no help!
A sample of the CSV:
1,AC/DC,2003 Logo,TS,ts_ac_2003
2,AC/DC,A5 Highway Fire,JO,jo_ac_a5highw
3,AC/DC,Album Stiff,TS,ts_ac_albumst
4,AC/DC,Amp,TS,ts_ac_amp
5,AC/DC,Angus,TS,ts_ac_angusb
6,AC/DC,Angus Caricature,SB,sb_ac_angus
7,AC/DC,Angus Comin' At Ya,HF,hf_ac_angusco
8,AC/DC,Angus For Those,TS,ts_ac_angusf
9,AC/DC,Angus Head,RP,rp_ac_angushe
10,AC/DC,Angus Let,TS,ts_ac_angusle
The last field in the CSV is the current filename without the .jpg,
the first field is a unique number, I'm trying to name these files
sequentially, but with .jpg
As you can see I've tried two methods for concatenation and neither
seems to do what I'd expect. $oldname never gets .jpg appended and
$newname starts of being .jpg, then .jpgpj, and lastly (for 3 digit
numbers) .jpgjpg. I can see what is happening with $newname but don't
understand why.
If someone could point me at an explanation here I'd be grateful. I've
never had trouble with assignment before, well, not like this. The code
looks right to me but obviously I know nothing!
Thanks for any help you can give.
Justin.