Here's how to do it
open(IN, "$myfile.txt");
my @file = <IN>;
close(IN);

foreach (reverse @file) {
   chomp;
    my @field = split(/\|/);
    if ($field[0] ne '') {
        print "$field[0]|$field[1]|$field[2]\n";
    }
}

Note that I'm using the default variable ( $_ ) that's why you don't see
more arguments in split and chomp.
That's done by not specifiying a variable name in the foreach loop.

Regards,

----- Original Message -----
From: "Daniel Hurtado Brenner" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, September 19, 2002 4:43 AM
Subject: sort


>
> Hi friend:
> I want know if is possible to do this:
>
> For example:
> If i have a flat data base myfile.txt with this info:
>
> 1|name|address|
> 2|name two|address two|
> 3|name three|address three|
> 4|name four|address four|
> ..... (etc, etc)
>
> If i execute:
>
>  open(IN,"$myfile.txt");
>  while(<IN>){
>   @file=split(/\|/,$_);
> If ($file[0] ne ""){
> print "$field[0] | $field[1] | $field[2]";
> }
> }
> close (IN);
>
> THE RESULTS IS:
>
> 1|name|address|
> 2|name two|address two|
> 3|name three|address three|
> 4|name four|address four|
>
> OK. BUT HOW I CAN DO FOR THIS RESULTS BE:
> 4|name four|address four|
> 3|name three|address three|
> 2|name two|address two|
> 1|name|address|
>
> ??????
>
> Thanks
> Daniel
> (Excuse me my english)
>

Reply via email to