activeperl@listserv.activestate.com
[Top] [All Lists]

Re: shift-sets in while-loops (perl 5.7.8)

Subject: Re: shift-sets in while-loops perl 5.7.8
From: "$Bill Luebkert"
Date: Thu, 20 Jul 2006 18:01:17 -0700
Josh.Perlmutter@xxxxxxxxxxx wrote:

> Gurus-
> i remember using the var setting in the while loop before when i needed to 
> do some movement. not sure if it was pre- perl 5.7.8 or not.
> 
> 
> could anyone enlighten me as to what i must be completely overlooking 
> that's causing the inside of the while loop t remained untouched? it is as 
> if it forgets there is any information in the global array.
> 
> i'm trying to build a regexp here so that i can place it in a larger 
> program.

> #! /usr/bin/perl
> use strict;
> use warnings;
> 
> my $tmp;
> my @temp = split "\n", `sfu sho /det`;

# now get some of this that we want to pass on

my $drvs = 'Drives: ';
my $rls = 'RAID Levels: ';
my $ssz = 'Stripe Sizes: ';
my $wps = 'Write Policies: ';

while (defined (my $tmp = shift @temp)) {

        next if $tmp !~ /Drive:\s*(\w+)/i;

#       find each drive's info

        $drvs .= "$1, "; # add the drive

        while ($temp[1] !~ /^\s*(Drive|Unit|Volume):/i) {

                $tmp = shift @temp;
                if ($tmp =~ /Raid level:\s+(\d+)/i) {
                        $rls .= "$1, ";
                }
                if ($tmp =~ /Stripe size:\s+(\d+\s\w\w)/i) {
                        $ssz .= "$1, ";
                }
                if ($tmp =~ /Write policy:\s+(\w+\s\w+)/i) {
                        $wps .= "$1, ";
                }
        }
}

#       copy and paste unit/volume info

print "drvs: $drvs
raids: $rls
stripes: $ssz
wps: $wps
";

__END__
_______________________________________________
ActivePerl mailing list
ActivePerl@xxxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

<Prev in Thread] Current Thread [Next in Thread>