On Thu, Jun 28, 2001 at 02:34:31PM -0700, Paul wrote:
> > $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} ) {

Well, you make a good point that one should use foreach, but then you use it
in almost identical way as the for loop.  If you were to use it this way,
you might as well use a for loop.  The most readable and idiomatic way to do
this is:

    foreach my $street (@{ $state{$city} }) {
        ... if $street ne "MAIN";
    }

You should try to avoid the foreach (0 .. $#array) form; that list has to go
into memory somewhere, and it's just a more verbose way of saying foreach
(@array).

Otherwise, that's some good advice.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

Reply via email to