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.
In reply to Re: creating 2 file writing objects
by Joost
in thread creating 2 file writing objects
by postman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |