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/
>
>
>

Reply via email to