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

I have been playing around with Pugs ever since the project started. I have recently been looking over the examples and trying to write Perl6 scripts of my own. I've run into one frustration so far. When I assign a value to a variable like this:

$learning = 'perl6';

I get the following error message from Pugs:

*** Undeclared variable: "$learning"

Now if I change my code to:

my $learning = 'perl6';

it works fine. Are you not going to be able to simply declare variables by creating them as you were in Perl5? I now a lot of people recommend always using my anyway, but I really like the option of either way. Is there anyway to turn off the option in Pugs that causes an error with the first example?

Replies are listed 'Best First'.
Re: Variable Declaration in Perl6
by mrborisguy (Hermit) on Jun 01, 2005 at 22:04 UTC

    I think it has to do with the start of your file. If you say 'use v6;' - which I don't think is necessary in pugs right now - that defaults to strict. However, if you say 'v6' without the 'use', then that isn't strict, so you would be able to do what you want to do. I believe those are the rules in the perl6 language. However, as far as I know, pugs is just automatically in strict mode, no matter what you do.

        -Bryan

Re: Variable Declaration in Perl6
by duff (Parson) on Jun 02, 2005 at 05:28 UTC

    Read throught this for more background and for a way around the strictness. Though I'm not sure the pugs implements it yet.

Re: Variable Declaration in Perl6
by eric256 (Parson) on Jun 01, 2005 at 23:55 UTC

    I'm kinda curious why you wouldn't want it to require my. My definitly stops bugs, but what is the benefit of not needing it?

    my $learning = 'perl6'; say $laerning; # error with strict, silent bug without

    ___________
    Eric Hodges