On 11 Aug 2006 at 14:45, John W. Krahn wrote:
> Beginner wrote:
> > I would be interested to know who I can improve this, or what a real
> > programmer would do differently. Any tips are much appreciated.
>
> Okey doke!
> > ================ What I have so far =========
> >
> > use strict;
> > use warnings;
> > use XML::Simple;
> > use Data::Dumper;
> >
> > my $file = 'test2.tif';
> > my ($d, $start,$end);
> >
> > open(FH, $file) or die "Can't open $file: $!\n";
> >
> > binmode(FH);
> > while ( <FH> ) {
> > if ($_ =~ "<x:xapmeta xmlns:x='adobe:ns:meta/") {
> > $start = tell FH;
> > }
> > if ($_ =~ "</x:xapmeta>") {
> > $end = tell FH;
> > last;
> > }
> > }
> >
> > $start -= 84; # Length of string above.
> > my $amount = ($end - $start);
> >
> > print "Start=$start, END=$end, $amount\n";
> > seek(FH,$start,0);
> > read(FH,$d, $amount);
> >
> > close(FH);
> > print Dumper($d);
> > ================
>
>
> use strict;
> use warnings;
> use XML::Simple;
> use Data::Dumper;
>
> my $file = 'test2.tif';
>
> open my $FH, '<:raw', $file or die "Can't open $file: $!\n";
>
> my $data;
> while ( <$FH> ) {
> next unless s!.*?<x:xapmeta xmlns:x='adobe:ns:meta/!!;
> $data = $_;
>
> $data .= <$FH> until $data =~ s!</x:xapmeta>.*!!s;
> last;
> }
>
> close $FH;
> print Dumper $data;
>
> John
> --
> use Perl;
> program
> fulfillment
That's interesting, thanx John.
It is leaner. You have eliminated all the seek/read stuff, nice.
You haven't specified binmode, is it implied by the '<:raw' notation?
What is "s!." in line 12, "next unless s!...."
I haven't seen a filehandle made into a variable, is there some more
reading I could be doing, perlI/O perhaps?
Here the output I get:
$VAR1 = '\' x:xaptk=\'XMP toolkit 2.8.2-33, framework 1.5\'>
I am missing a couple of characters at the beginning.
Your help is much appreciated. I am trying to learn more about the
perl mind-set and how to program corerctly. Thanx again.
Dp.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>