print to terminal

A

alexxx.magni

hi people,
I need to print to terminal a long $variable containing text, and of
course being longer than the terminal width it produces a truncated
word that continues on the next line - I'd like to go newline just on
spaces...

I wrote an approximated version to "prettyprint" it, but it's so awful
that I prefer not to show it in public...

Do you know of some elegant way to do it? (there should be more than
one way...;-)

thanks!

Alessandro Magni
 
A

alexxx.magni

thanks!
Of course I already had the module installed, and completely forgotten
it...
I had hope there was an even cleaner way (by some magick regex trick '
'=>'\n' at the appropriate places...) but it's OK enough this way.
But, one more small problem: I have to specify manually the number of
columns, since the module does not check it by itself.
Googling I found just 2 ways to do it:

use Text::Wrap qw(wrap $columns);

my $columns=`tput cols`;
# OR:
# $x=`stty -a`;$x=~/columns (\d+)/;$columns=$1;

but I dont like neither.
Do you know a better way? I tried to use $ENV{COLUMNS} but discovered
that this hash value does not exist, during execution - where can I
also find the number of columns value?

Thanks!

Alessandro

Christian Winter ha scritto:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top