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

I put in an Icon box for script and it works where it gives output box saying "Script Completed" after a condition is met in the script. The problem is I want to put the Win32::MsgBox output in a variable and just put the variable in place each time I need it. It does output correctly on each condition but it also outputs the original declaration part so I get two outputs of "Script Completed". How can I correct this? Here is my example:
use Win32; use strict; my $output = Win32::MsgBox("Script completed.", MB_ICONINFORMATION); + #this part outputs all the time. #conditions here etc.. if(something){ $output; #if this condition is met it outputs and works as it s +hould } else { $output; if this condition is met it outputs and works as it shoul +d }

Replies are listed 'Best First'.
Re: Win32 MsgBox declaration
by tcf22 (Priest) on Sep 10, 2003 at 16:03 UTC
    You could just put the MsgBox() call in the END() routine.
    END{ Win32::MsgBox("Script completed.", MB_ICONINFORMATION); }
    Then it will run when the script ends automatically. You don't even have to call the function.

    - Tom

      Thanks to both of you!
Re: Win32 MsgBox declaration
by Thelonius (Priest) on Sep 10, 2003 at 15:56 UTC
    One of us is confused. The value returned from Win32:MsgBox is just an integer. The way you're calling it, it should always be "1". So the variable $output will just contain the value "1". Just saying:
    $output;
    doesn't do anything. In fact, if you run your program with "-w" or "use warnings", you'll get the message "Useless use of private variable in void context".

    Perhaps you want to make a subroutine like this:

    sub showend { Win32::MsgBox("Script completed.", MB_ICONINFORMATION); }
    Then you can call showend() where your are now doing $output.