Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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!!

Replies are listed 'Best First'.
Re: Right shifted display
by FunkyMonk (Canon) on Jun 01, 2012 at 12:36 UTC
Re: Right shifted display
by choroba (Chancellor) 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.



Re: Right shifted display
by GrandFather (Sage) 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";


    <spirit:library>XYZ_lib</spirit:library> 12345678^
    True laziness is hard work
Re: Right shifted display
by toolic (Bishop) 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 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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://973745]
Approved by toolic
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2016-12-04 08:43 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (63 votes). Check out past polls.