Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Do I have to trick Split?

by perldigious (Priest)
on Aug 23, 2016 at 12:55 UTC ( [id://1170221]=note: print w/replies, xml ) Need Help??


in reply to Re: Do I have to trick Split?
in thread Do I have to trick Split?

Well that's awesome. I have this problem a lot, and I've always written around it since I didn't know you could specify a negative limit and get all the trailing empties. As usual I didn't RTFM well enough.

Thanks for this tip. I feel pretty silly now for how many times that, among other things, I've added extra no warnings 'uninitialized'; and use warnings 'uninitialized'; around every split in to an array where I have that problem.

I love it when things get difficult; after all, difficult pays the mortgage. - Dr. Keith Whites
I hate it when things get difficult, so I'll just sell my house and rent cheap instead. - perldigious

Replies are listed 'Best First'.
Re^3: Do I have to trick Split?
by BrowserUk (Patriarch) on Aug 23, 2016 at 14:30 UTC
    I have this problem a lot, and I've always written around it since I didn't know you could specify a negative limit and get all the trailing empties.

    Pretty much the defining characteristic of Perl -- the real Perl that is; not a bastardised, pseudo-sanitised subset, nor an orthoganised, pseudo-java superset that the "modern" crowd would try to sell you on -- is that the built-ins are very well designed to deal with all the variations that you will ever need.

    Many languages now have a split in their libraries, but none of them cater to all the common variations and edge cases the way Perl's does.

    It was when early in my use of Perl: I repeatedly found myself needing to do something that I knew was going to be awkward and messy to deal with, only to find that Perl's designer(s) had been there before me, recognised the need and catered for it; that caused me to pin the Perl documentation in my browser for quick reference.

    It's still there 13 years later. I don't have to look so often as I once did; but I am still discovering the purpose of stuff that I've read many times, but took no notice of because I didn't need it at that time, but that has been sitting there dormant just waiting for my need.

    And it is that that brings me back to Perl time and time again. I'm currently trailing yet another new language -- this time Julia -- to replace my reliance on Perl. It is very cool language that acts exactly as a RELP-able, interpreted language; that when stressed, JITs into a near-C speed demon. But I recently spent a week trying to code something from scratch in Julia; that when I got frustrated took me 37 minutes from start to finish in Perl.

    Even with the working Perl example and a 2/3rds complete Julia version it took 3 more days to get the Julia version working because of the need to manually code all the special cases that Perl takes care of for me. The result ran 13x faster, which in the long run of process that will run for months, is a huge saving and well worth the effort; but it will still be a long time before I give up Perl 5.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re^3: Do I have to trick Split?
by TomDLux (Vicar) on Aug 23, 2016 at 16:09 UTC

    perldoc -f split is your friend!

    As Occam said: Entia non sunt multiplicanda praeter necessitatem.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-04-16 06:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found