Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Split problem using limit

by davido (Cardinal)
on Aug 20, 2004 at 15:17 UTC ( #384615=note: print w/replies, xml ) Need Help??

in reply to Split problem using limit

Using a limit with split tells split to return only that number of elements. However, that doesn't mean that split should skip the step of splitting. If I understand you're problem, you are trying to get split to not split, some of the time.

Using a limit of zero won't help you. According to perldoc -f split: "If LIMIT is unspecified or zero, trailing null fields are stripped (which potential users of pop would do well to remember)." As you can see, this has nothing to do with getting split to keep the entire line in tact.

Perhaps you should be performing whatever check you're using to determine whether or not to split, and then if the check is positive, don't invoke split on that line at all.

Also, your first experiment (  split(0) ) can't work. You can't just leave off preceeding arguments from a subroutine and expect that Perl will know that you really intend the single arg you've provided to take the third arg's position. That falls under the category of "You can't just make sh#@ up and expect it to work..."


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://384615]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2023-12-03 17:33 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (20 votes). Check out past polls.