On 8/14/07, DJ Gruby <[EMAIL PROTECTED]> wrote: > Hello there! > > Have question if that is possible to empty a few arrays with one simple > command? > > For the moment I clear these six tables by assigning them an empty list: > > @bitmap_addr_lo = (); > @bitmap_addr_hi = (); > @screen_addr_lo = (); > @screen_addr_hi = (); > @colors_addr_lo = (); > @colors_addr_hi = (); > > Just wondering if there is a more elegant way to achieve the same result? > > Many thanks in advance for your help! > > Regards, > DJ Gruby.
The desire to empty arrays is a bad sign. It generally means you do not have them declared with the correct scope, but, assuming you have a good reason, there are many ways to reset a bunch of arrays. Here are two in addition to your straight forward way. @bitmap_addr_lo = @bitmap_addr_hi = @screen_addr_lo = @screen_addr_hi = @colors_addr_lo = @colors_addr_hi = (); @$_ = () for \(@bitmap_addr_lo, @bitmap_addr_hi, @screen_addr_lo, @screen_addr_hi, @colors_addr_lo, @colors_addr_hi); Frankly, I think the straight forward way is more readable since I dislike lines longer than 78 characters. But, given the names of the arrays and the fact that they are all being reset at the same time I think you are using the wrong data structure. You should be using an HoHoA (a hash of hashes of arrays): $addr{screen}{hi} instead of @screen_addr_hi. Then you could clear them all by saying for my $type (qw<screen bitmap colors>) { for my $loc (qw<hi low>) { $addr{$type}{$loc} = []; } } or (my favorite) @{$_}{qw<hi low>} = ([], []) for @addr{qw<screen bitmap colors>}; or the more comprehensive (but dangerous if other keys are being used) for my $type (keys %addr) { @$_ for keys %$type; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/