> -----Original Message----- > From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED] > Sent: Friday, September 23, 2005 3:45 PM > To: Ryan Frantz > Cc: beginners perl > Subject: Re: Hash Problem > > On Sep 23, Ryan Frantz said: > > > I'm working on a small script that checks the free space on local fixed > > drives on my system. Since there other drive types (i.e. floppy, > > CD-ROM, network maps) I want to exclude those. I decided to use a hash > > but the script still displays all of the drives on my system. If I just > > use simple 'next' statements, it works fine. I've placed the block > > inside the original foreach and even tried wrapping it around the print > > statements to no avail. What gives? > > The problem is you've got another loop, and that's what the 'next' is > getting you out of. > > > my %ignoreDriveTypes = ( > > 'floppy' => '2', > > 'network' => '4', > > 'cdROM' => '5', > > ); > > I would invert this: > > my %ignoreDriveTypes = ( > 2 => 'floppy', > 4 => 'network', > 5 => 'cdrom', > ); > > Then you can say: > > > foreach my $process (in $sobj->InstancesOf("Win32_LogicalDisk")) { > > next if $ignoreDriveTypes{ $process->{DriveType} };
So this would evaluate to true if $process->{DriveType} matches a key in the hash? > > since the "names" associated with the types are really just satellite > data. > > > foreach my $type ( keys %ignoreDriveTypes ) { > > next if ( $process->{DriveType} == $ignoreDriveTypes{$type} ); > > } > > Here was the problem. This 'next' was working on THIS foreach loop, not > the $process foreach loop. You'd have had to put a label on the outer > foreach loop like so: > > PROCESS: foreach my $process (...) { > foreach (...) { > next PROCESS if ...; > } > ... > } > > -- > Jeff "japhy" Pinyan % How can we ever be the sold short or > RPI Acacia Brother #734 % the cheated, we who for every service > http://www.perlmonks.org/ % have long ago been overpaid? > http://princeton.pm.org/ % -- Meister Eckhart -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>