in reply to creating 2 file writing objects
Some pointers:
use strict; would have kicked your ass :-)
Your constructor should be something like:
use Symbol; sub new { my $class_name = shift; $classname = ref($classname) || $classname; my $self = { "output_file" => shift, "append" => shift, "file_handle" => gensym(), } bless ($self,$class_name); return $self; }
use Symbol; and gensym() are put in here for backward compatibility to perls before 5.6 - see the Symbol manpage
And methods should be called and constructed like:
$object->method($arg1,$arg2); sub method { my $self = shift; my $arg1 = shift; my $arg2 = shift; print "append is ",$self->{"append"},"\n"; $self->other_method($arg2); }
Take a look at perldoc perltoot and/or get your hands on the 'programming perl' book
Update: changed $append and friends to "append" - that should actually work :-)
also added some code to show the retrieval of object data.
-- Joost downtime n. The period during which a system is error-free and immune from user input.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: creating 2 file writing objects
by postman (Acolyte) on Jun 27, 2002 at 15:27 UTC | |
by postman (Acolyte) on Jun 27, 2002 at 20:01 UTC |