On 11 Aug 2006 at 9:28, Tom Phoenix wrote:

> On 8/11/06, Beginner <[EMAIL PROTECTED]> wrote:
> 
> > But once I have found my tag I would like to use sysseek and sysread
> > to slurp up some data. Is there some way I can find out where my
> > position in the file is once $_ has matched?
> 
> You probably want seek() and read(), instead of sysseek() and
> sysread(). (The "sys" variants are very low-level.) Then you would
> want tell() to identify the position in the file. You may need to
> subtract a few bytes if you need to locate the position of a string
> that has already been read. It's not the way most Perl programmers
> would solve the problem, but it may work for you. Good luck with it!
> 

Thanx Tom,

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.

Thanx.
Dp.


================ 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);
================

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to