Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

passing Curses object to subroutine

by emilford (Friar)
on Apr 13, 2004 at 22:33 UTC ( [id://344872]=perlquestion: print w/replies, xml ) Need Help??

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

How would I pass a Curses::UI object to a subroutine to be updated? I've tried several methods, each failed giving me an undefined. Suppose I have the following simplified code:
my $cui = Curses::UI; my $window = $cui->add('blahblahblah', 'Window'); # add the progressbars $window->add('p1', 'Progressbar'); $window->add('p2', 'Progressbar'); $window->add('p3', 'Progressbar');
How would I pass $window to a subroutine and then use that passed value as $window->getobj('p3')->{-text}="BlahBlahBlah" to update p3's text? I've tried passing it as a scalar and as a reference. Am I missing something?

Replies are listed 'Best First'.
Re: passing Curses object to subroutine
by kvale (Monsignor) on Apr 13, 2004 at 22:48 UTC
    Your constructor should be
    my $cui = new Curses::UI;
    This problem would stop the rest of your code in its tracks.

    Most (all?) objects are references, so passing them by value to subroutines should allow you to invoke methods on them while in the sub.

    -Mark

      In my actual code, I do use the new construct. My mistake.

      My code works fine until I attempt $window->getobj('p3')->{-text} = "Something"; on a variable passed to a subroutine as &UpdateP3($window). I get an error stating 'getobj' can't be used/called on an undefined variable. If all objects are references, I should be able to pass it to a subroutine and invoke the getobj method, right?
        The syntax you describe sounds valid (drop the & though, it does funky stuff), so you've probably screwed up actually doing it. I can't guess where or how though without seeing a small sample case that demonstrates the problem.
Re: passing Curses object to subroutine
by gmpassos (Priest) on Apr 14, 2004 at 05:56 UTC
    Hummm, how about show to us how you call this subroutine, and how it receives the object. I will be waiting the reply...

    Graciliano M. P.
    "Creativity is the expression of the liberty".

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://344872]
Approved by kvale
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-03-28 12:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found