|
Posted by news2003 on March 24, 2008, 5:13 am
Please log in for more thread options > news2...@wanadoo.es wrote:
> >I have a basic question. It has to do with the way I pass files with
> >spaces. I have two versions of the same code. once calls $exifTool-
> >>ExtractInfo($file) directly as argument from the command line.
>
> >perl extract.pl /home/john/pictures 2/15.jpg
>
> Your shell will break this line down into 4 elements:
> - perl
> - extract.pl
> - /home/john/pictures
> - 2/15.jpg
>
> If you want only three elements then you will have to tell your shell that=
> the last space is part of the third element rather than a separator,
> typically by enclosing the element in quotes.
>
> >being the code in this case:
>
> >open( FILE, "< $filename" ) or die "Can't open $filename : $!";
>
> I can't reproduce your problem. This line opens a file just fine, even if
> the name contains a space.
Thanks for the answers.
It's definitely in the version with spaces calling from a file not
from the @argv[0].
here my modification.
% cat test_spaces.txt
sandbox/noSpaces/63.jpg
sandbox/with\ Spaces/63.jpg
the result of the scrip calling this list.
% perl extract2.pl test_spaces.txt
sandbox/noSpaces/63.jpg =3D=3D=3D=3D=3D=3D=3D1=3D=3D=3D=3D=3D=3D=3D=3D
sandbox/noSpaces/63.jpg
=3D=3D=3D=3D=3D=3D=3D2=3D=3D=3D=3D=3D=3D=3D=3D
63.jpg 126 kB JPEG 2007:05:12 18:47:54 Canon Canon EOS 350D
DIGITAL image/jpeg Horizontal (normal)72 72 inches
1/60 4.0 Program AE 400 0 Evaluative Auto,
Fired, Red-eye reduction 21.0 mm Normal AI Focus AF
Auto 557-5800 799 533 799x533 18.0 - 200.0 mm
2007 05 12 18 47 54
sandbox/with\ Spaces/63.jpg =3D=3D=3D=3D=3D=3D=3D1=3D=3D=3D=3D=3D=3D=3D=
=3D
sandbox/with\ Spaces/63.jpg
=3D=3D=3D=3D=3D=3D=3D2=3D=3D=3D=3D=3D=3D=3D=3D
63.jpg
%
in the version called from the command line.
% perl extract.pl sandbox/noSpaces/63.jpg
63.jpg 126 kB JPEG 2007:05:12 18:47:54 Canon Canon EOS 350D
DIGITAL image/jpeg Horizontal (normal)72 72 inches
1/60 4.0 Program AE 400 0 Evaluative Auto,
Fired, Red-eye reduction 21.0 mm Normal AI Focus AF
Auto 557-5800 799 533 799x533 18.0 - 200.0 mm
2007 05 12 18 47 54
% perl extract.pl sandbox/with\ Spaces/63.jpg
63.jpg 126 kB JPEG 2007:05:12 18:47:54 Canon Canon EOS 350D
DIGITAL image/jpeg Horizontal (normal)72 72 inches
1/60 4.0 Program AE 400 0 Evaluative Auto,
Fired, Red-eye reduction 21.0 mm Normal AI Focus AF
Auto 557-5800 799 533 799x533 18.0 - 200.0 mm
2007 05 12 18 47 54
%
I added the print lines to the failing scripts to see what was the
cause.
sub extractInfo(){
my $file =3D shift;
print "=3D=3D=3D=3D=3D=3D=3D1=3D=3D=3D=3D=3D=3D=3D=3D\n";
print "$file\n";
print "=3D=3D=3D=3D=3D=3D=3D2=3D=3D=3D=3D=3D=3D=3D=3D\n";
In both cases seems to be the same.
Notice that I backslashed the version with spaces to avoid the space
failing in $argv[0]
the interesting thing is that if I replace the failing code with:
open( FILE, "< $filename" ) or die "Can't open $filename : $!";
foreach my $line ( <FILE> ) {
chomp ($line);
$line =3D "sandbox/with\ Spaces/63.jpg";
print $line."\t";
extractInfo("$line");
}
the code works fine, although always for the same file.
% perl extract2.pl test_spaces.txt
sandbox/with Spaces/63.jpg =3D=3D=3D=3D=3D=3D=3D1=3D=3D=3D=3D=3D=3D=3D=
=3D
sandbox/with Spaces/63.jpg
=3D=3D=3D=3D=3D=3D=3D2=3D=3D=3D=3D=3D=3D=3D=3D
63.jpg 126 kB JPEG 2007:05:12 18:47:54 Canon Canon EOS 350D
DIGITAL image/jpeg Horizontal (normal)72 72 inches
1/60 4.0 Program AE 400 0 Evaluative Auto,
Fired, Red-eye reduction 21.0 mm Normal AI Focus AF
Auto 557-5800 799 533 799x533 18.0 - 200.0 mm
2007 05 12 18 47 54
sandbox/with Spaces/63.jpg =3D=3D=3D=3D=3D=3D=3D1=3D=3D=3D=3D=3D=3D=3D=
=3D
sandbox/with Spaces/63.jpg
=3D=3D=3D=3D=3D=3D=3D2=3D=3D=3D=3D=3D=3D=3D=3D
63.jpg 126 kB JPEG 2007:05:12 18:47:54 Canon Canon EOS 350D
DIGITAL image/jpeg Horizontal (normal)72 72 inches
1/60 4.0 Program AE 400 0 Evaluative Auto,
Fired, Red-eye reduction 21.0 mm Normal AI Focus AF
Auto 557-5800 799 533 799x533 18.0 - 200.0 mm
2007 05 12 18 47 54
so it has to be in the way $line is pased to the sub extractInfo but I
can't see how.
|