in reply to Re^3: Regarding STDOUT and indirect object notation for print
in thread Regarding STDOUT and indirect object notation for print
Foo.pm:
package Foo; use strict; use warnings; sub new { return bless {}; } sub method { return 1; } 1;
script.pl:
#!/usr/bin/perl use strict; use warnings; require Foo; my $class = 'Foo'; my $obj = bless {}, $class; print $obj->method;
Works fine, but if you remove the require Foo; line, you get the error Can't locate object method "method" via package "Foo" at script.pl line 9. perl needs the require statement to find and compile the source files.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Regarding STDOUT and indirect object notation for print
by romandas (Pilgrim) on Dec 29, 2009 at 21:13 UTC | |
by kennethk (Abbot) on Dec 29, 2009 at 21:49 UTC | |
by ikegami (Patriarch) on Dec 29, 2009 at 22:02 UTC | |
by kennethk (Abbot) on Dec 29, 2009 at 22:17 UTC | |
by romandas (Pilgrim) on Dec 30, 2009 at 02:06 UTC |