>
> > my @virtual_disks = sort map { /Virtual Disk:\s(\S+)/ } `$SSCS_CMD
> > list -a
> > $storage vdisk`;
> >
> > my question is, WHY IS THIS WORKING? My first idea was to use this
> > command
> > instead:
> >
> > my @virtual_disks = sort map { s/Virtual Disk:\s(\S+)/$1/ } `$SSCS_CMD
> > list
> > -a $storage vdisk`;
> >
> > but this, for some reason that I don't know, doesn't work, it returns
> > this
> > list (1, 1, 1, 1, 1, 1, 1, 1) instead of (1, 2, 3, 4, 5, 6, 7, 8); can
> > anyone explain me why?
>
> This is not map's fault; this is one of the differences between match
> and substitute.  Match will return a list of capture variables;
> substitute will return the number of substitutions.
>

Thanks for the tip! I found this on perlop documentation regarding 'match':

"If the "/g" option is not used, "m//" in list context returns a list
consisting of the subexpressions matched by the parentheses in the pattern,
i.e., ($1, $2, $3...)"

So (as you said), that is the reason! (One side note though, I've tried
using '/g' and the code still works, I guess it's working because I only
find one match in the string ...)


This will also work:
>
> my @virtual_disks = sort map { s/Virtual Disk:\s(\S+)/$1/; $_ } `$SSCS_CMD
> list -a $storage vdisk`;
>


This works because the return value is the last expression (in this case
$_), is that right?


JP

Reply via email to