Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Top Seven (Bad) Reasons Not To Use Modules

by dreadpiratepeter (Priest)
on Mar 12, 2009 at 16:44 UTC ( [id://750213]=note: print w/replies, xml ) Need Help??


in reply to Top Seven (Bad) Reasons Not To Use Modules

I am the choir that you are preaching to.

I find that the use of modules is the most compelling reason to use Perl. Once you get into the habit of looking on cpan before you code, you will find your productivity growing in leaps and bounds (as well as your reputation as a miracle worker at your job).

Let me share what happened to me this morning. I was writing code to deal with a really bad ticketing system that my company uses. The saving grace is that it is built on top of a database, so i can manipulate it's data.

I wrote a query that inserted formated data into a field in the db, but when i looked at the results in the app, the newlines were gone, replaced by black boxes. I (correctly) assumed that the app was expecting to see dos eol semantics, rather than unix.
I'm old and the part of my brain that remembers eol semantics punted them long ago to make room for something more important. But...

A quick search on cpan for "DOS NL" revealed the Text::FixEOL module, "cpan Text::FixEOL" installed it, and 2 lines of perl code implemented it. In less than 5 minutes, my problem was solved.

And because the modules is on cpan, i know it is tested on any platform i might ever use this code on, and i am far more sure that it is correct than I ever would be if I had implemented it myself.

Yay Perl!


-pete
"Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."
  • Comment on Re: Top Seven (Bad) Reasons Not To Use Modules

Replies are listed 'Best First'.
Re^2: Top Seven (Bad) Reasons Not To Use Modules
by licking9Volts (Pilgrim) on Mar 12, 2009 at 21:00 UTC
    I too have found CPAN to be indispensable. Not only does it help my productivity by solving one problem, but I often find myself writing code with future uses in mind. My code is also physically portable. I use a portable version of Strawberry on a thumb drive since our PC's are managed. All the better for me since I can take it anywhere I need it. Like dreadpiratepeter said, once you start using CPAN, you'll realize the benefits of not have to re-invent the wheel. My current favorite module is Text::CSV_XS. It's so handy I could cry...

      ++ To to original post. Nice summary.

      My current favorite module is Text::CSV_XS. It's so handy I could cry...

      licking9Volts, thanks for the compliment, I feel flattered :)


      Enjoy, Have FUN! H.Merijn
Re^2: Top Seven (Bad) Reasons Not To Use Modules
by JavaFan (Canon) on Mar 13, 2009 at 10:51 UTC
    A quick search on cpan for "DOS NL" revealed the Text::FixEOL module, "cpan Text::FixEOL" installed it, and 2 lines of perl code implemented it. In less than 5 minutes, my problem was solved.
    Wait, you spend a whole five minutes, installed a module when all you need is:
    $text =~ s/\R/\r\n/g;
    That doesn't really sound as a convincing anecdote.
      You seem to have missed my point: I don't remember what the semantics for newlines are.
      I would have had to do a lot of looking stuff up to come up with that line, and I wouldn't be sure that it covers all cases. In addition, if you look at the module in question, I now have a tool that can also do the reverse translation, do the same for mac eol semantics (which again I have no idea what they are), and will handle all the edge cases properly.

      As a side note, I the negative and dismissive nature of your post to be completely counter-productive to what I hope the Perl monks should be accomplishing. It's wonderful that you know that line of code, but to post so condescendingly because someone else might not, is just rude.
      If you wanted to point out that there is a simple solution to this you could have done so in a much more positive way.
      But, I guess my expectations are too high in a medium where you never have to talk to someone face-to-face as a person.


      -pete
      "Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."

      Erm ... what do you expect the \R to mean? I don't know, maybe it means something in Perl 5.10, but in 5.8 it's equivalent to R. So what you wrote was equivalent to

      $text =~ s/R/\r\n/g;
      probably not what you wanted, right?

      Even though this is not a task that would be too complex, it's not such a no-brainer as you seem to imply. It's not really "convert the internal notion of newlines (\n) to the Windows notion (CR LF)". It's "convert whatever newlines to the Windows newlines". So it should handle not only "\n", but also "\r\n" (windows already) and "\r" (old Mac). You do not want to end up with "CR CR LF", do you?

      I use

      $s =~ s/(?:\x0D\x0A?|\x0A)/\x0D\x0A/sg;
      within Mail::Sender, but if I did not want to waste my time and wanted to be sure I end up with the right line ends without having to study all posibilities, Text::FixEOL looks like a very good candidate.

        Thank you for very elegantly proving my point!


        -pete
        "Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."
        It's "convert whatever newlines to the Windows newlines".
        \R does indeed mean, "whatever newlines".

        Assuming you have upgraded your Perl in the last 5 quarters.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-04-19 06:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found