in reply to Package declaration in code block

Scope! The namespace is restricted to the block, you don't need to declare the package at the end to return to that older namespace again.

edit
> perl $x=42; { package Inner; $x=666; } print $x; __END__ 42

Cheers Rolf

( addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^2: Package declaration in code block
by tobyink (Canon) on Apr 23, 2014 at 16:51 UTC

    Another way to illustrate it would be:

    use 5.010; { package Foo; say __PACKAGE__; } say __PACKAGE__;

    If your Perl is recent enough, you can even do this:

    use 5.014; package Foo { say __PACKAGE__; } say __PACKAGE__;
    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
Re^2: Package declaration in code block
by McA (Priest) on Apr 23, 2014 at 16:29 UTC

    Hi Rolf,

    thank you for the fast reply.

    Is there an advantage in a classic package, one package per file?

    Regards
    McA

      If you're posting example code, it's useful for everything to be in one self-contained example file, so that people can just copy and paste it into their editor and run it, rather than them having to create a directory called Foo and make a file in there called Bar.pm and paste some code in there, and then create another folder called Boo and make a file in there called Far.pm and paste more code in there, and then...

      use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

        That's a very good argument. I haven't thought about that.

        But this is the "More-than-one-package-per-file"-case. I was wondering if there is a reason to do so in a package per file.

        Regards
        McA

      I use this form in my .t files when I need a quick class mock-up: it stands out more.