Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Reaped: print format

by NodeReaper (Curate)
on Oct 07, 2011 at 17:19 UTC ( #930219=perlquestion: print w/ replies, xml ) Need Help??
NodeReaper has asked for the wisdom of the Perl Monks concerning the following question:

This node was taken out by the NodeReaper on Oct 07, 2011 at 18:55 UTC
Reason: [ikegami]: Anonymous duplicate of formating the record. Reap?

You may view the original node and the consideration vote tally.

Comment on Reaped: print format
Re: print format
by ikegami (Pope) on Oct 07, 2011 at 17:41 UTC
    printf("%-10s %-10s %s\n", $name, $dob, $age);
    printf("%-${max_name_length}s %-10s %s\n", $name, $dob, $age);
    printf("%-*s %-10s %s\n", $max_name_length, $name, $dob, $age);
Re: print format
by armstd (Friar) on Oct 07, 2011 at 17:45 UTC

    Your code an output are kind of a mess, which really makes trying to understand what output you're looking for... try using code/blockquotes to clean it up. Also, that's not enough of your code to really understand your current format string. What are all those vars for? What does each one represent?

    Shooting in the dark, I think you're looking for something more like this:

    printf( "%-${name_length}s %-10s %-10d\n", "Name", "DOB", "AGE" ); printf( "%-${name_length}s %-10s %-10d\n", $std_name, $dob, $age );

    --Dave

Re: print format
by BrowserUk (Pope) on Oct 07, 2011 at 18:41 UTC

    The best tool for formatting fixed length records is pack:

    print pack 'A20 A10 A3', @$_ for ( [ qw[ Name DOB AGE ] ], [ qw[ Name111111 010190 30 ] ], [ qw[ Name222 020280 40 ] ], );; Name DOB AGE Name111111 010190 30 Name222 020280 40

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

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

    How do you remember the number of days in each month?











    Results (126 votes), past polls