Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Print a string X times?

by cdarke (Prior)
on Aug 04, 2010 at 06:01 UTC ( [id://852800]=note: print w/replies, xml ) Need Help??


in reply to Print a string X times?

This is my personal favorite:
local $, = ' '; print +('-') x $length,"\n";

Replies are listed 'Best First'.
Re^2: Print a string X times?
by targetsmart (Curate) on Aug 04, 2010 at 07:45 UTC
    in the statement print +('-') x $length , "\n";

    the +('-') does some magic which I don't understand, could you please explain that statement..


    Vivek
    -- 'I' am not the body, 'I' am the 'soul/consciousness', which has no beginning or no end, no attachment or no aversion, nothing to attain or lose.

      From perlop: Symbolic Unary Operators:

      "Unary "+" has no effect whatsoever, even on strings. It is useful syntactically for separating a function name from a parenthesized expression that would otherwise be interpreted as the complete list of function arguments."

      Try removing the + and ensure you use strictures (well, warnings anyway) and see what happens.

      True laziness is hard work
Re^2: Print a string X times?
by Skeeve (Parson) on Aug 04, 2010 at 07:52 UTC

    That's really usefull!

    ++ for that!


    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-25 18:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found