On Tuesday 18 December 2007 13:48, minky arora wrote:
>
> Hi Gurus,

Hello,

>  I am parsing through a file and need to print the records in the
> following order:
>
> Minky Arora
> 235 River Drive,
> Newton,PA 19073
>
> Here is my code:
> !/usr/bin/perl
>
> use strict;
> open FILE, "/users/meenaksharora/db.txt" or die"cnt open $!";
> my($fname,$lname,$address,$lline,$line,@db);
> foreach my $line(<FILE>){
> $fname=substr($line,0,10);
> $lname=substr($line,10,15);
>   $address=substr($line,16,25);
>
>   $lline=substr($line,59,13);
> $fname=~s/\s+/ /;
> $lname=~s/\s+/ /;
> $address=~s/\s+/ /;
> $lline=~s/\s+/ /;
> print "$fname $lname\n";
>
>
> print "$address\n";
> print"$lline\n";
> }
>
> Now each record as I calculated is of a fixed lenght of 75 chars.I
> need some idea as to how to run the Loop to print all such
> records.Right now I am only able to print the first record,

You could try something like this:

#!/usr/bin/perl
use warnings;
use strict;

my $file = '/users/meenaksharora/db.txt';

open my $fh, '<', $file or die "Cannot open '$file' $!";

while ( my $line = <$fh> ) {
    my ( $fname, $lname, $address, $lline ) = unpack 'A10 A15 A25 A13', 
$line;

    print "$fname $lname\n$address\n$lline\n";
    }

__END__



John
-- 
use Perl;
program
fulfillment

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


Reply via email to