On Tue, 2008-09-23 at 14:57 -0300, Jose Perez wrote:
> By trial and error, I found that the following code works:
> 
> 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.

This will also work:

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


-- 
Just my 0.00000002 million dollars worth,
  Shawn

Linux is obsolete.
-- Andrew Tanenbaum


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


Reply via email to