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

Re: python like named placeholders sprintf ?

by Jenda (Abbot)
on Jan 15, 2009 at 22:24 UTC ( [id://736697]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    use Interpolation '%:$$->$' => sub {sprintf '%'.$_[0], $_[1]};
    
    ...
    $x = 1.7;
    $name = "Leaveolus";
    print "Hello $%{'06d'}{$x} or $%{' 10.5f'}{$x}, $%{'20s'}{$name}, and 
    +so forth\n";
    
  2. or download this
    use Interpolation 'S' => sub {
        local $_ = sprintf("%.2f", shift());
    ...
    };
    #...
    print "And the total price is $S{$Price}.\n";
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-24 08:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found