Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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..."


Dave


In reply to Re: Split problem using limit by davido
in thread Split problem using limit by NovMonk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2023-12-09 02:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (37 votes). Check out past polls.

    Notices?