http://www.perlmonks.org?node_id=732771

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

This might be a problem with my understanding with Curses more than with perl, but please help me out. I'm using Curses.pm which works quite well except when I try to create a curses "window". Example code:
use Curses; initscr; $w=newwin(1,1,40,40); $w->addstr(20,20,"Hello"); $w->refresh; refresh; endwin;
outputs nothing, not using a window works fine:
use Curses; initscr; $w=newwin(1,1,40,40); addstr(20,20,"Hello"); refresh; endwin;

Replies are listed 'Best First'.
Re: Curses problem
by FunkyMonk (Chancellor) on Dec 27, 2008 at 11:46 UTC
    I'm never played with Curses before, but it's been on my todo list for years...

    $w=newwin(1,1,40,40);
    You've got your arguments to newwin incorrect.
    $ man newwin ... WINDOW *newwin(int nlines, int ncols, int begin_y, int begin_x);

    use Curses; initscr; my $w = newwin(40,40,1,1); $w->addstr(20,20,"Hello"); $w->refresh; endwin; <>;

    Works for me.

    Update: Fixed borked link


    Unless I state otherwise, all my code runs with strict and warnings
      Duh! Thanks! Works now.
Re: Curses problem
by spadacciniweb (Curate) on Dec 27, 2008 at 11:40 UTC
    I have changed your code:
    use Curses; initscr; $win = new Curses; $win->addstr(20, 20, 'Hello'); $win->refresh; while (1) {}; endwin;

    Update: from here I read:
    Window newWin( Int lines, Int cols, Int beginy, Int beginx ) ... lines Number of lines in window cols Number of columns in window beginy Position of top of window beginx Position of left of window
    so the correct form (with function newwin) is:
    use Curses; initscr; $win = new Curses; $win = newwin(40,40,1,1); $win->addstr(20, 20, 'Hello'); $win->refresh; while (1) {}; endwin;

    Update II: FunkyMonk has just responded before my Update:

    (($_="Mzz ojjdloobnf jt uvy5502383")=~y~b-zg2-5c96-81~a-z0-9~s)=~s~~~s; print