On Fri, Jun 29, 2001 at 10:15:54AM -0400, F.H wrote:
> CITY:while (my $line = <DATA>){
>
> my @line = split /\s*,\s*/, $line;
> my $city = $line[3];
>
> foreach my $city (keys %state) {
> foreach my $street (@{ $state{$city} } ){
> if ($street ne 'MAIN'){
> next ;
> }
>
> }
> next CITY;
> }
>
> print "$line\n";
>
> }
Ok, those nexts cause this to do nothing; if the street does not equal main,
you go to the next loop; after reaching the end of one loop, you go to the
line (labeled, poorly, CITY). Look at my original code; you'll notice I
print something if there is a "MAIN" street, and something if there isn't.
If you don't want something printed if there isn't, remove the print
statement, don't move the code around, don't relabel loops with poor
names, and especially don't turn off use strict.
Also, the read loop should be:
while (defined(my $line = <DATA>)) {
...
}
> I want my output to be (print only lines where city/ street <> 'MAIN' :
> STATE ,IL, SDW,CHICAGO
> STATE, MA, FDR,BOSTON
> STATE, WA, SDF,SEATTLE
For this, you should make the following changes to your code: place the two
foreach loops in my original code inside your while loop, remove the
statement printing something when there is a 'MAIN' street, and change the
statement printing something when there is no 'MAIN' street to print the
data you want.
Do you understand my code? Do you understand your own code? It sounds to
me like you haven't quite gotten some of the Perl basics. What learning
material do you have?
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--