chen li am Montag, 4. September 2006 15:51: > --- "John W. Krahn" <[EMAIL PROTECTED]> wrote: > > chen li wrote: > > > --- "John W. Krahn" <[EMAIL PROTECTED]> wrote: [...] > > > my @data=( > > > ['1','1','1'], > > > ['2','2','2'], > > > [''], > > > ['3','3','3'], > > > [''] > > > ); > > > > @data = grep @$_, map [ grep length, @$_ ], @data; > > > > John > > Thank you very much John. But could you explain a > little more about the line codes? It is difficult for > me to understand how they work even I read the perldoc > perllol. It looks to me @$_ is deferencing anonymous > array
yes > but is that all? Remember to read these two constructs from right to left :-) > @data = grep @$_, @data; This selects nested arrayrefs from @data that are not empty (grep @$_). The expression @$_ (dereferenced array) only evaluates to true if it contains one ore more entries, and is then selected by grep. > @data = grep @$_, map [ grep length, @$_ ], @data; This does the same, *after* all entries in the nested arrayrefs having a length < 1 are deleted. The part map [ grep length, @$_ ], transforms every nested arrayrefs in @data: It a) dereferences it (@$_) b) selects only entries having a length > 0 (grep length) c) and puts these remaining entries back into an arrayref ([]) See perldoc -f length perldoc -f grep perldoc -f map Hope this helps Dani -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>