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

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]
[LanX]: I told you the story about the “new" currency trading system of Dresdner Bank
[LanX]: ?
[Corion]: No, or I don't remember the story ;)
LanX my favourite don't tell me the proof of concept is good enough for production anecdote
[ambrus]: ah, it's one of thos
[Eily]: what, there's a difference between proof of concept and production?
[LanX]: 20 years ago traders were complaining about the latency of the trading system...
[ambrus]: I'm currently in the process of rewriting my proof of concept programs. They sort of developped organically as I was experimenting, so now I've got an ugly mess of multiple programs and one-liners held together by nothing. I'll have to rewrite them to som
[ambrus]: ething that's both cleanly organized and mostly automated.

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (12)
As of 2017-03-29 11:45 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (350 votes). Check out past polls.