ashutoshinbox has asked for the wisdom of the Perl Monks concerning the following question:

Hello, i need a help regarding text formating of array value,look at following code,
here i am forwarding process status to a file "process", 'ps -ef >process'(this is done by a cron job at every day) here is part my perl code my $uxinfo = "process"; open(INFO, $uxinfo); @uinfo = <INFO>; foreach my $line (@uinfo) { chomp($line); next if ($line eq "" ); print "$line";}} }
when ever i am trying to get it to an array using FH, its making the output to ugly, i mean is there anyway i can make it looks good, as we are getting true value/output at command file, i mean apropriate space and lines. . . . sorry for making earlier description skeptical, actually i want some thing like, all line and column will contain exact value, like
#ps -ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 2007 ? 00:00:02 init [3] root 2 1 0 2007 ? 00:01:34 [gration/0] root 3 1 0 2007 ? 00:00:01
but in the output all these things are messing up like following:
UID PID PPID C STIME TTY TIME CMD root 1 0 0 2007 ? 00:00:02 init [3] root 2 1 0 2007 ? 00:01:34 [gration/0] root 3 1 0 2007 ? 00:00:01
i want exact value should be in exact column!! thanks to all for your quick feedbacks..

Replies are listed 'Best First'.
Re: Text format array
by toolic (Bishop) on Jan 17, 2008 at 13:47 UTC
    I think your problem is that you are using chomp to remove the newline character, but when you use print you are effectively concatenating all the input lines into one long line. You need to add the newline back. Try this:
    print "$line\n";
Re: Text format array
by moritz (Cardinal) on Jan 17, 2008 at 13:42 UTC
    I don't really understand your question, but I guess you're looking for a method to generate some neatly formatted output.

    The Modules Text::Table or Perl6::Form might help you, or even formats.

      sorry for making earlier description skeptical, actually i want some thing like, all line and column will contain exact value, like
      #ps -ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 2007 ? 00:00:02 init [3] root 2 1 0 2007 ? 00:01:34 [gration/0] root 3 1 0 2007 ? 00:00:01
      but in the output all these things are messing up like following:
      UID PID PPID C STIME TTY TIME CMD root 1 0 0 2007 ? 00:00:02 init [3] root 2 1 0 2007 ? 00:01:34 [gration/0] root 3 1 0 2007 ? 00:00:01
      i want exact value should be in exact column!! thanks to all for your quick feedbacks..
Re: Text format array
by roboticus (Chancellor) on Jan 17, 2008 at 14:50 UTC
    ashutoshinbox:

    I think you're looking for either the printf function or the FORMAT statement. Try perldoc -f printf or perldoc perlform for more information...

    ...roboticus

Re: Text format array
by KurtSchwind (Chaplain) on Jan 17, 2008 at 16:32 UTC

    To re-iterate your question:

    You want the output columns to line up nicely.

    The answer you want to look into is probably printf as others have already pointed out. There are other ways to format the output, but I think you'll like printf.

    --
    I used to drive a Heisenbergmobile, but every time I looked at the speedometer, I got lost.
Re: Text format array
by chaos_cat (Scribe) on Jan 17, 2008 at 13:50 UTC
    Well, I'm not really sure exactly what you mean by 'ugly' here, but you'll probably get some millage out of adding a new line to the end of your print statement, since chomp removes the newline you read in from the file.
    print "$line\n";