[EMAIL PROTECTED] wrote:
>
>
> --- "F.H" <[EMAIL PROTECTED]> wrote:
> > Hi all,
>
> Hi. =o)
>
> > I am trying to skip any line in my input file that doesn't have a
> > city with a street named 'MAIN'. I am matching record[3] in my input
> > file with a $city (array) from a hash (%state) that I got from
> > another file. The problem is that @city contains more than one
> > element!
>
> a $city (array) ???
>
> What do you mean?
Sorry for the confusion, But I meant city is an array and at the same time an element
of the hash %state.
> > while ($line = <INPUT>){
> > ....
>
> It might help to see some of the ellipsed code....
>
Nothing much:
for ($line) { # get rid of quotes
s/^"|"$//g;
s/\s*","\s*|,"*/,/g;
}
> > $city = $record[3] ;
> > for ($i = 0; $i <= $#{ $state{$city}; $i ++ ) {
>
> Never use the
> for( ; ; ) { }
> construct in Perl without a significant and compelling reason.
> foreach is virtually always better for lots of reasons. Try:
>
> for my $i ( 0 .. $#{ $state{$city} ) {
>
> > next if $state{$city}[$i] ne "MAIN"
>
> Is that next supposed to advance the while loop?
> Because I think it's an expensive no-op that just advances the for
> loop.
I've tried that as well, and the purpose is to skip any line where the city doesn't
have street = 'MAIN'
> Label the while like this:
>
> READ: while($line=<INPUT>) {
>
> and then specify which loop is being advanced with
>
> next READ if ....
>
> > }
>
> Hmm...
> maybe:
> READ: while($line=<INPUT>) {
> my %lookup = ();
> @lookup{@state{$city}} = 1 .. scalar(@state{$city});
> next READ unless $lookup{MAIN};
> # it's there, so do whatever code...
>
> > }
>
> I haven't tested this, and something about it feels funny....
> But it's a start. =o)
>
> __________________________________________________
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail
> http://personal.mail.yahoo.com/
>
__________________________________________________________________
Get your own FREE, personal Netscape Webmail account today at
http://webmail.netscape.com/