Hi Ken.
Ken Tozier wrote:
> I wrote a simple script to extract some of the info Photoshop 6 embeds
> in jpeg files through the "file info" dialog box and find that I can
> extract the info no problem with:
>
> open(PROPS, 'egrep -a \'<photoshop:([^>]+)>[^<]*</photoshop:\1>\'
> "botanical-garden12-full.jpg" | ');
>
> Doing print <PROPS>; shows that the info I'm looking for is indeed
> extracted.
>
> Next I try to loop through the results and extract parts of each string
> like so:
>
> $tmp = "";
> while (<PROPS>)
> {
> $tmp .= s/<photoshop:([^>]+)>([^<]*)/$1: $2/;
> }
>
> Doing a "print" on $tmp, yeilds
>
> 1111111111111
>
> None of the lines in "PROPS" contain a single digit character so why am
> I getting a string of 1's?
Many people try to force Perl to be another language: usually either
C or a scripting language, although I have seen a few example of
LISP Perl!
What you have here is a scripting language approach. You would probably
find that it would run faster if you used 'cat' instead of 'egrep', but
why not do the whole thing in Perl:
open PROPS, 'botanical-garden12-full.jpg'
or die $!;
binmode PROPS;
my $tmp;
while (<PROPS>) {
$tmp .= "$1: $2" while /<photoshop:([^>]+)>([^<]*)/g;
}
print $tmp;
which I hope you agree is a lot clearer. It also picks up
multiple tags in the same record which your original didn't
do, although that may well not have been a problem. This is
untested as I have neither Photoshop nor a *nix system at
hand at the moment, but it shouldn't be far off correct.
Cheers,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]