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

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

by Jenda (Abbot)
on Mar 13, 2009 at 14:41 UTC ( #750439=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Top Seven (Bad) Reasons Not To Use Modules
in thread Top Seven (Bad) Reasons Not To Use Modules

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.


Comment on Re^3: Top Seven (Bad) Reasons Not To Use Modules
Select or Download Code
Re^4: Top Seven (Bad) Reasons Not To Use Modules
by JavaFan (Canon) on Mar 13, 2009 at 15:38 UTC
    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.

      Ah, I didn't know that. (I guess I would have been better off with the module too, eh?).

      And you didn't even know bears could type.

        Don't get me wrong. I never claimed people shouldn't use modules. I never claimed the module used in the example shouldn't be used.

        I just don't think using a module to replace a substitution consisting of a single 2 character token as the pattern is a great example of how timesaving modules can be.

Re^4: Top Seven (Bad) Reasons Not To Use Modules
by dreadpiratepeter (Priest) on Mar 13, 2009 at 17:28 UTC
    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."

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (10)
As of 2014-11-27 08:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (182 votes), past polls