Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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.

Replies are listed 'Best First'.
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.
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 );


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://930219]
and the monks are mute...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2017-12-16 00:22 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (446 votes). Check out past polls.