Debbie, your problem seemed easy enough.  See if this works for you:

my $state;
my $code;
my $currCode = 0;
my $outLine = "";

open(STATES, "<state.txt") || die("can't open state:");
while($line = <STATES>) {

        $line =~ /^(\w+): (\d+)/;
        if($code == $currCode) {
                $outLine .= ", " . $1;
        }
        else {
                unless($outLine eq "") { print("$outLine \n"); }
                $outLine = $2 . " " . $1;
        }
}

print("$outLine \n");
close STATES

Caveat:  this script assumes all input follows as per your example.


Will


-- Original Message --

>I am brand new to perl; I am only on chapt 4 of the learning perl book.
> My
>boss has already given me a project to do that I am really struggling with.
>I know you are all really busy, but I would really appreciate any help
you
>can give.
>
>I have a text file that looks something like this
>
>OH:  702
>PA: 702
>ND: 702
>NJ :703
>NY: 703
>Ca: 703
>
>
>#my simple program
>
>open(STATES,"state.txt")||
>                                        die "can't open state:";
>while ($line = <STATES>)
>{
>print $line;
>}
>close STATES;
>
>
>I am able to open the file and read it with no problem.  Where I get lost
>is
>My boss wants the data to come out like
>702 OH, PA, ND
>703 NJ, NY, CA
>
>I have looked up Faq questions and have looked through my books.  I have
>even tried formating it with no luck.  Any help you can give would be great.
>
>
>
>
>
>
>Thanks,
>Debbie Christensen
>
>
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>




Visit iWon.com - the Internet's largest guaranteed cash giveaway! Click
here now for your "Thank You" gift:
http://www.iwon.com/giftcenter/0,2612,,00.html?t_id=20157




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to