On Tuesday 04 December 2007 07:28, ciwei2103 wrote: > thans for the reply. > > I modify the program a bit , the $cmd output looks like: > ======== > Ident Symbolic Numeric Slot Type Status > > DF-1A 01A 1 1 DISK Online > FA-4A 04A 4 4 FibreChannel Online > FA-13A 13A 13 13 FibreChannel Online > DF-16A 16A 16 16 DISK Online > > > the code is below: > ============== > my $cmd = "/usr/symcli/bin/symcfg -sid 0133 list -dir all"; > open (SYMCFG, " $cmd |" ) or die "cannot open $!\n"; > > while ( <SYMCFG> ) { > print $_ if /FibreChannel\s+Online/ ; > my ( $ident, $fa , $type, $status ) = (split /\s+/ )[0,1,4,5] if / > FibreChannel\s+Online\s+$/ ; > print "$ident $fa $type $status \n" if defined $status ; > > } > close SYMCFG ; > > then when run it: > bash-2.03# ./emc_device_matching_to_fa2.pl > FA-4A 04A 4 4 FibreChannel Online > FA-4A 4 FibreChannel > FA-13A 13A 13 13 FibreChannel Online > FA-13A 13 FibreChannel > > > if I chane the line: > my ( $ident, $fa , $type, $status ) = (split )[0,1,4,5] if / > FibreChannel\s+Online\s+$/ ; > then I got the correct results. > > FA-4A 04A 4 4 FibreChannel Online > FA-4A 04A FibreChannel Online > FA-13A 13A 13 13 FibreChannel Online > FA-13A 13A FibreChannel Online > FA-4B 04B 20 4 FibreChannel Online > FA-4B 04B FibreChannel Online > > so why the differience with split vs split /\s+/ ? thanks.
perldoc -f split [ SNIP ] As a special case, specifying a PATTERN of space (' ') will split on white space just as `split' with no arguments does. Thus, `split(' ')' can be used to emulate awk's default behavior, whereas `split(/ /)' will give you as many null initial fields as there are leading spaces. A `split' on `/\s+/' is like a `split(' ')' except that any leading whitespace produces a null first field. A `split' with no arguments really does a `split(' ', $_)' internally. John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/