You are not storing your user object data in your object and you are not calling methods as methods but as subroutines, using the &routine syntax that has some really nasty side-effects.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.