Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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]
[marto]: oddly the last time I was there I saw a zeppelin in flight for the first time
[Corion]: ambrus: I don't know how far the budget estimate has been overrun yet
[Corion]: marto: Heh ;) No, you were likely at Tegel or Schönefeld, the new one ("BER") will be somewhat outside of Berlin ;)
[marto]: Corion Schoenfeld, but my friend has been telling me about this new airport for about 7-8 years now :P
[marto]: I doubt it even exists as a building site :P
[ambrus]: Corion: does building airports "somewhat outside of" a city ever work? cities always grow around the airport quickly, because it's practical to be close to it, and after that, people start to complain that the airplanes land so close to their house and sh
[ambrus]: ould keep down the noise

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2017-02-23 12:01 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (346 votes). Check out past polls.