in reply to Re: Optimizing Splitting of Array
in thread Optimizing Splitting of Array
Another technique is the use of list slice. There can be some good reasons to combine this with split limit. The below code shows how to "get rid of a value" from the split. In this case, the date token. You probably don't want to do that, but this is just an example.
As another point about "space splitting": If you split a complete line with \s+, the ending \n will be removed because the \s set includes \n\f\r\space\t (so when splitting a complete line with \s, you do not have to "chomp" it first).#!/usr/bin/perl -w use strict; use Data::Dumper; my @rows; while (<DATA>) { my @data = (split(/\s+/,$_, 6))[0,1,3..5]; push (@rows, \@data); } foreach (@rows) { print "@$_"; } #prints #abc 322 aaa aadda dasdas a1 a2 a3 #def 433 dasd bdbdbd wings b1 b2 b3 b4 b5 __DATA__ abc 322 2/3/09 aaa aadda dasdas a1 a2 a3 def 433 3/4/08 dasd bdbdbd wings b1 b2 b3 b4 b5
|
|---|