|
|
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.
Sorry, don't understand what you mean.
>
>
> 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.
That's not clear either, I'm afraid.
>
> i'm trying to build a regexp here so that i can place it in a larger
> program.
Sorry, I don't see how that relates to the above or the code below.
Still, at least there's code. :-)
>
> ************************************************************start
> code**************************************
> #! /usr/bin/perl
> use strict;
> use warnings;
>
> my $tmp;
> my @temp = split "\n", `sfu sho /det`;
>
> if ($temp[1] =~ /Drive:/){
> my $drvs = 'Drives: ';
> my $rls = 'RAID Levels: ';
> my $ssz = 'Stripe Sizes: ';
> my $wps = 'Write Policies: ';
>
> print "blah! the array starts....
> \t1:$temp[0]
> \t2:$temp[1]
> \t3:$temp[2]
>
> ";
>
> # now get some of this that we want to pass on
> while($tmp = shift(@temp)){
>
> print "\tTEMP IS: $tmp\n";
>
> # find each drive's info
> if($tmp =~ /drive: (\w+)/i){
> $drvs .= "$1, "; # add the drive
>
>
> while(!(($temp[1] =~ /Drive:/i) ||
> ($temp[1] =~ /Unit:/i) ||
> ($temp[1] =~ /Volume:/i))){
Why $temp[1] rather than $temp[0] ?
> $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\n\n
>
> and this should be nothing: $temp[1]
> ";
>
> }
> ************************************************************end
> code**************************************
Bearing in mind I don't fully understand what you are trying to do, the
above code does seem a bit over-complicated. The following code seems to
do the same, but simpler (IMHO, that is).
-----------------------------------------------------------
use strict;
use warnings;
#my $data = `sfu sho /det`;
my $data;
{
local $/;
$data = <DATA>;
}
# Split data on title lines (note parentheses in pattern).
my @recs = split /^(\w+:.+?)$/m, $data;
# First entry should be empty, as data starts with a title line.
shift @recs if $recs[0] =~ /^\s*$/;
my (@drvs, @rls, @ssz, @wps);
while (my ($title, $rec) = splice @recs, 0, 2) {
if ($title =~ /^drive:\s+(\w+)/i) {
push @drvs, $1;
push @rls, $1 if $rec =~ /raid level:\s+(\d+)/i;
push @ssz, $1 if $rec =~ /stripe size:\s+(\d+ \w\w)/i;
push @wps, $1 if $rec =~ /write policy:\s+(\w+ \w+)/i;
}
}
print "Drives: ", join(", ", @drvs), "\n";
print "Raid Levels: ", join(", ", @rls), "\n";
print "Stripe Sizes: ", join(", ", @ssz), "\n";
print "Write Policies: ", join(", ", @wps), "\n";
__DATA__
[cut & paste example data from OP here - elided for brevity]
-----------------------------------------------------------
HTH
--
Brian Raven
=================================
Atos Euronext Market Solutions Disclaimer
=================================
The information contained in this e-mail is confidential and solely for the
intended addressee(s). Unauthorised reproduction, disclosure, modification,
and/or distribution of this email may be unlawful.
If you have received this email in error, please notify the sender immediately
and delete it from your system. The views expressed in this message do not
necessarily reflect those of Atos Euronext Market Solutions.
L'information contenue dans cet e-mail est confidentielle et uniquement
destinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee.
Toute copie, publication ou diffusion de cet email est interdite. Si cet e-mail
vous parvient par erreur, nous vous prions de bien vouloir prevenir
l'expediteur immediatement et d'effacer le e-mail et annexes jointes de votre
systeme. Le contenu de ce message electronique ne represente pas necessairement
la position ou le point de vue d'Atos Euronext Market Solutions.
_______________________________________________
ActivePerl mailing list
ActivePerl@xxxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
|
|