develooper Front page | perl.perl6.users | Postings from August 2022

Re: BEGIN {} question

Thread Previous | Thread Next
From:
ToddAndMargo via perl6-users
Date:
August 29, 2022 20:03
Subject:
Re: BEGIN {} question
Message ID:
5afaf446-92c9-3785-76eb-230e4d69aab8@zoho.com
On 8/28/22 15:58, ToddAndMargo via perl6-users wrote:
> Hi All,
> 
> I am thinking of using
> 
>     BEGIN {}
> 
> to fire up a splash screen (libnotify).
> 
> Question: is what happens between the brackets
> isolated from the rest of the code?   If I set
> variable values or declare variables, are they
> wiped out, etc.?
> 
> Many thanks,
> -T

Follow up:

Thank you all for the help!

My splash screen pops up whilst the
rest of the program compiles.

Here is my BEGIN code.   If you are
wondering why all the variables when
I could just write it in the run line,
it is becasue the names of the variables
and the comments next to them tell me what
the parameters of notify-send are and
how to use them.  Much easier to maintain.



#!/usr/bin/env perl6

use RunNoShellLib :RunNoShell, :RunNoShellCode, :RunNoShellErr;

BEGIN {
    # Splash Screen

  ( my $ProgramName   = $?FILE ) ~~ s|.*"/"||;
    my Str $NotifyStr = "\nStarting $ProgramName\n";
    my Str $Icon      = "/home/linuxutil/Images/Info.png";
    my Str $Title     = "$ProgramName Splash Screen";
    my Str $Timeout   = "8000";  # milliseconds

    RunNoShell( "notify-send -u normal -t \"$Timeout\" -i \"$Icon\" 
\"$Title\" \"$NotifyStr\"" );
}



:-)

Love Raku!

-T

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About