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

Re: BEGIN {} question

Thread Previous | Thread Next
ToddAndMargo via perl6-users
August 30, 2022 01:38
Re: BEGIN {} question
Message ID:
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

My keeper on BEGIN.  That you for all the help
and tips!

Perl6: BEGIN {}

BEGIN is a special subroutine that runs at compile time.
It will see any code above it, such as variables and
imported modules, but not below it.

The idea is to run something at the start of compile before
the rest of compile completes.  A splash screen for example.

Perl 6's compile can take a very long time and users may not
realize it started and restart it several times.

Note that a space is required between `BEGIN and the `{}`

    # 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   = "8";       # zenity = seconds

    # Note: zenity seems to not detach when run without a shell
    shell "zenity --info --title \"$Title\" --text \"$NotifyStr\" 
--width=220 --timeout=$Timeout &";

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About