hi Debbie,
perhaps this is what you want.
#!/usr/bin/perl -w
use strict;
open STATES, "<state.txt" or die "cant open state.txt $!";
my %states = ();
while ((my ($state, $num)) = split /\s*:\s*/, <STATES>) {
$num =~ s/^\s+//;
$num =~ s/\s+$//;
push @{ $states{$num} }, $state;
}
for (keys %states) {
print "$_ ", join ( ',', @{ $states{$_} } ), "\n";
}
Am Dienstag, 24. Juli 2001 21:03 schrieb Debbie Christensen:
> 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
--
cu boris
Man hört, wegen der Gewöhnlichkeit, das Prügelgeschrei eines Kindes
mit weniger Rührung als eines Hunds.
-- Jean Paul
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]