print to terminal

Discussion in 'Perl Misc' started by alexxx.magni@gmail.com, Nov 16, 2006.

  1. Guest

    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
     
    , Nov 16, 2006
    #1
    1. Advertising

  2. Guest

    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:

    > wrote:
    > > 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...;-)

    >
    > Have a look at the Text::Wrap module.
    >
    > -Chris
     
    , Nov 20, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sam
    Replies:
    5
    Views:
    334
    MrJean1
    Oct 10, 2006
  2. keto
    Replies:
    0
    Views:
    980
  3. gaurav kashyap
    Replies:
    3
    Views:
    6,664
    Paul Boddie
    Oct 31, 2008
  4. David Cournapeau

    print a vs print '%s' % a vs print '%f' a

    David Cournapeau, Dec 30, 2008, in forum: Python
    Replies:
    0
    Views:
    366
    David Cournapeau
    Dec 30, 2008
  5. Steve
    Replies:
    2
    Views:
    942
    edicionsdigitals.com edicions digitals xarxa socia
    Dec 7, 2010
Loading...

Share This Page