G'Mornin' Kavita --

Before you go off on a goose chase, how do you know that substr() is going
to be a problem for you?  Have you bench-marked it?  If your file is as
large as you say, I strongly suspect that your bottleneck is going to be
I/O and any differences between unpack() and substr() will be lost in the
noise band below 1%.


B


On Wed, Apr 10, 2013 at 5:02 AM, kavita kulkarni
<kavitahkulka...@gmail.com>wrote:

> Data file has the lines with same length and so the field positions I am
> interested in (so unpack works for me).
> Tried with "unpack" as well & it takes almost same time as substr().
>
> Here is sample code:
>
> Below function is called for each line of input data file..
>
> sub extractFieldValue {
> my $self = shift;
> my $data = shift; #Line from data file
> my $start = shift;
> my $length = shift;
> my $startPos = $start - 1;
> my $val = unpack("a$length", $data);
> $val =~ s/\|/ /g;
> return $val;
> }
>
>  $val is then used as key of a Hash for further processing.
>
> Cheers,
> Kavita
>
> Regards,
> Kavita :-)
>
>
> On Wed, Apr 10, 2013 at 4:32 PM, Jenda Krynicky <je...@krynicky.cz> wrote:
>
> > From: timothy adigun <2teezp...@gmail.com>
> > > On 10 Apr 2013 11:30, "Chankey Pathak" <chankey...@gmail.com> wrote:
> > > >
> > > > Hi Kavita,
> > > >
> > > > You may try unpack (http://perldoc.perl.org/functions/unpack.html)
> > > >
> > > unpack would not work if the OP has varying length of lines.
> >
> > Nope. It would work just fine as long as the bits he's interested in
> > are fixed lengh and are on fixed positions. The length of the
> > uninteresting trailing stuff is irrelevant.
> >
> > Jenda
> > ===== je...@krynicky.cz === http://Jenda.Krynicky.cz =====
> > When it comes to wine, women and song, wizards are allowed
> > to get drunk and croon as much as they like.
> >         -- Terry Pratchett in Sourcery
> >
> >
> > --
> > To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> > For additional commands, e-mail: beginners-h...@perl.org
> > http://learn.perl.org/
> >
> >
> >
>



-- 

Bob Goolsby
bob.gool...@gmail.com

Reply via email to