Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Right shifted display

by zeni (Beadle)
on Jun 01, 2012 at 12:15 UTC ( #973745=perlquestion: print w/ replies, xml ) Need Help??
zeni has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I know this sounds trivial.

$proj_lib = "XYZ"; printf $xmlfile "%8s","<spirit:library>$proj_name\_lib</spirit:library +>\n"; Output: " <spirit:library>XYZ_lib</spirit:library>"

All i need is a 'right shifted'(8 spaces) display. I wonder what am i missing here!

Life is a box of chocolates.. Perhaps you get to eat very few best ones!!

Comment on Right shifted display
Download Code
Re: Right shifted display
by toolic (Chancellor) on Jun 01, 2012 at 12:21 UTC
    If this is not what you're looking for, show the exact output you need:
    use warnings; use strict; my $proj_name = 'foo'; printf "<spirit:library>%8s\_lib</spirit:library>\n", $proj_name; __END__ <spirit:library> foo_lib</spirit:library>

      I have shown it as

      Desired: '8spaces<spirit:library>XYZ_lib</spirit:library>

Re: Right shifted display
by choroba (Abbot) on Jun 01, 2012 at 12:28 UTC
    You probably want
    print $xmlfile ' ' x 8, "<spirit:library>$proj_name\_lib</spirit:libra +ry>\n";
    If not, please be more specific.
Re: Right shifted display
by johngg (Abbot) on Jun 01, 2012 at 12:28 UTC

    Perhaps you want

    printf $xmlfile ' %s', "<spirit:library>$proj_name\_lib</spirit:library>\n";

    but it is difficult to be sure from your description.

    Cheers,

    JohnGG

Re: Right shifted display
by FunkyMonk (Canon) on Jun 01, 2012 at 12:36 UTC
Re: Right shifted display
by Anonymous Monk on Jun 01, 2012 at 14:17 UTC

    Now that everybody else is commenting, I too recommend that you review how printf is supposed to be called. The correct syntax is:

    printf "%8s%s", "", "<spirit:library>$proj_name\_lib</spirit:library>\ +n";

    This is pretty obviously not the best way to generate eight spaces. Would using a "\t" be completely out of the question?

      This syntax works just fine. But using '\t' is not the best solution as i need some 40 white spaces.

Re: Right shifted display
by GrandFather (Cardinal) on Jun 02, 2012 at 09:49 UTC

    Maybe Perl's x operator is of interest to you? Consider:

    use strict; use warnings; print ' ' x 8, "<spirit:library>XYZ_lib</spirit:library>\n"; print "12345678^\n";

    Prints:

    <spirit:library>XYZ_lib</spirit:library> 12345678^
    True laziness is hard work

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (13)
As of 2014-11-29 09:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (204 votes), past polls