in reply to how to use packages as classes in perl?

our
#!/usr/bin/perl -w use strict; package Foo; # this creates a package called Foo our $bar = "Hello World"; package main; # goes back to default package of class print $Foo::bar; # this prints $bar form package Foo __END__ Hello World

Replies are listed 'Best First'.
Re^2: how to use packages as classes in perl?
by LanX (Saint) on Apr 04, 2011 at 23:44 UTC
    Just for completeness, our is like my not restricted to the scope of the package.

    So this example can be simplified as long as the packages are not enclosed in a block or in different files.

    #!/usr/bin/perl -w use strict; { package Foo; our $bar = "Hello World"; package Zoo; print $bar; # no "Foo::" necessary } print $Foo::bar; # now again in package main __END__ Hello WorldHello World

    Cheers Rolf

Re^2: how to use packages as classes in perl?
by The Elite Noob (Sexton) on Apr 05, 2011 at 18:04 UTC
    Thank you! This is just what i needed :)