Beginner wrote: > > I had just found tell (honest) in the opentut. You are of course > tight I have to step back a couple of bytes to get to the beginning > of the string I want but WHOOPIE it works. > > I can quickly retrieve all the XML/XMP from an image file (similar > to, but no where near as well as, the excellent JPEG::MetaData > module). $d is now XML and ready for parsing. > > 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 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>