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

Re^2: On bad habits

by Xenograg (Scribe)
on Jun 21, 2005 at 16:37 UTC ( [id://468744]=note: print w/replies, xml ) Need Help??


in reply to Re: On bad habits
in thread On bad habits

If I am going to use newline frequently, I create a constant for it.
use constant NEWLINE => "\n"; print $foobar . NEWLINE;
--- The harder I work, the luckier I get.

Replies are listed 'Best First'.
Re^3: On bad habits
by jeffa (Bishop) on Jun 21, 2005 at 18:23 UTC

    No thanks. :) If i am going to use a newline frequently, i add the -l (dash elle) run switch:

    #!/usr/bin/perl -l
    And then i don't need to worry about adding newlines. Uh oh ... what if i don't want to always print out a newline? Simple, just use printf.

    Work smart ... not hard. ;)

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      what if i don't want to always print out a newline? Simple, just use printf.

      For years, I have been sitting here, railing and fuming silently against the supposed "brokenness" of printf's disrespect for -l. It's something I'd always put aside as a non-orthogonal oddity of the language.

      My anger blinded me to the possibility of using my opponent's strength to my own advantage -- a classic judo move.

      Thank-you for letting me see the error of my ways.

      jeffa++

      • another intruder with the mooring in the heart of the Perl

      If i am going to use a newline frequently, i add the -l (dash elle) run switch
      And if I want the effect locally, I set $\ (and optionally, $,) in a block, for example to print out a tab delimited text file:
      { local($\, $,) = ("\n", "\t"); print @fields; }

      I am obviously in the explicit-declaration faction.

      ++jeffa thanks for another WTDI. :)

      --- The harder I work, the luckier I get.
Re^3: On bad habits
by kaif (Friar) on Jun 22, 2005 at 06:25 UTC

    Alternatively, remember that unless you changed it for slurp mode or whatnot, $/ is a newline.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://468744]
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: (5)
As of 2024-04-25 16:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found