On Monday 15 May 2006 14:40, Smith, Derek wrote:
> I have this system output
>
>
>
> --- Logical volumes ---
>
> LV Name                     /dev/vg00/lvol1
>
> VG Name                     /dev/vg00
>

<snip>

>
> And I have this multiple lvols populated into 2 arrays like printed like
> so:
>
>
>
> Mirror copies               1
>
> Mirror copies               1
>

<snip>

>
> second array
>
> LV Name                     /dev/vg00/lvol3
>
> LV Name                     /dev/vg00/lvol1
>

<snip>

>
> But what I need to do is get rid of "LV Name" yet keep the
> /dev/vg00/lvol entries.
>
> Problem is this data is on one line.
>

So, as i understand it, you have an array that contains something like

LV Name                     /dev/vg00/lvol3

and you want to get rid of

LV Name

and keep the

/dev/vg00/lvol3

> Here is my code:

<snip>

> my @lvs;
>
> my @lvaray = qx(bdf);
>
> foreach (@lvaray) {
>
>         if (/(?:)vg00/) {
>
>            push @lvs, (split)[0]
>
>         }
>
>     }
>
>
>
>     my (%hash,@mir,@mir2)    = ();
>
>     my ($key2,$value2)       = 0;
>
>     foreach my $lv (@lvs) {
>
>         push @mir => (grep /mirror/i, `lvdisplay $lv`);
>
>         push @mir2 => (grep /lvol\d+/i, `lvdisplay $lv`);

Try replacing the above line with

        push @mir2 => (grep s/^LV Name\s*//, `lvdisplay $lv`);

Or

        push @mir2 => (grep {/lvol\d+/i; s/^LV Name\s*//;} `lvdisplay $lv`);

Or if you want to keep your line

        push @mir2 => (grep /lvol\d+/i, `lvdisplay $lv`);
        map s/^LV Name\s*//, @mir2;

Since grep returns the value when the expression is true, if the substitution 
succeeds, you will get the modified string.

Correct me if I'm wrong, but all of the expressions in the block have to 
evaluate to true for grep to return the value when using the block form.

In the last one, you are carrying out the substitution on each element of the 
array that you created.

Hope The Helps, Derek

>
>         #chomp (@mir,@mir2);
>
>     }
>
>
>
>     #%hash = (@mir,@mir2);
>
>
>
>     #while (($key2,$value2) = each %hash) {
>
>     #   print "$key2\t:$value2";
>
>     #}
>
>
>
> print @mir; print "\nsecond array\n";
>
> print @mir2;
>
>
>
> #($key1,$value1) = split/=/;
>
> #$cc{$key1}= $value1;
>
>
>
> Thanks
>
> Derek

<snip>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to