Jay Savage wrote:
> On 3/2/07, Robert Boone <[EMAIL PROTECTED]> wrote:
>> I think this is all you do:
>>
>> $piid = (split(/\t/, $row))[0];
> 
> Split also takes an optional limit that keeps it from splitting the
> string into more than n parts. This keeps spilt from performing
> useless operations when you only want the first n-1 items, or when you
> want to lump all the items >= n into a single lump:
> 
>    $piid = (split(/\t/,$row,2)[0];
> 
> Most of the time it probably doesn't matter, but adding a limit will
> be markedly more efficient if $row is particularly long or you are
> looping through an extremely long list of rows.
> 
> As always, see perldoc -f split for the details.

perldoc -f split

[ snip ]

        The LIMIT parameter can be used to split a line partially

            ($login, $passwd, $remainder) = split(/:/, $_, 3);

        When assigning to a list, if LIMIT is omitted, or zero, Perl supplies
        a LIMIT one larger than the number of variables in the list, to avoid
        unnecessary work.  For the list above LIMIT would have been 4 by
        default.  In time critical applications it behooves you not to split
        into more fields than you really need.


The limit is supplied automagically if the size of the list is know at compile
time like in your example above so using the limit argument is superfluous.




John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall

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


Reply via email to