Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
No such thing as a small change
 
PerlMonks  

Re^3: Extracting from a File

by tadman (Prior)
on May 15, 2002 at 14:02 UTC ( [id://166812]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re: Re: Extracting from a File
in thread Break List into Pieces (was: other ways ?)

I wouldn't dismiss unpack so soon. If you can develop a specification like the one you just said there, then you can use it. As an alternative, if things really are quite wacky, why not specify the position of elements in a hash and use that in conjunction with substr?
my @frags = ( { line => 5, column => 12, length => 10, name => 'foo' }, { line => 6, column => 12, length => 10, name => 'foo' }, ); # ... my %var; # @chunks is an array of arrays, where each contains a # block of the file. foreach my $chunk (@chunks) { foreach my $frag (@frags) { push(@{$var{$frag->{name}}}, substr($chunk->[$frag->{line}], $frag->{column}, $frag->{length})); } }
It will probably be a lot faster to use substr or unpack than to glue individual characters together, especially when you are pulling them out of a complex data structure and not just a string.

Replies are listed 'Best First'.
Re: Re^3: Extracting from a File
by physi (Friar) on May 15, 2002 at 14:54 UTC
    Thanks, that idea saves me abot 70% time :-)
    ++
    ----------------------------------- --the good, the bad and the physi-- -----------------------------------

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://166812]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.