Hello Corion,

This is actually the key point of my question. I want to find a way to pass/ inherit the value to my $firstName when the module will be called.

My intention is to use warnings on my script instead of die functions and store the error on a directory.

Sample of pseudo code Employee.pm:

So my question is how to pass the $fileDirectory into %WARNS so I can use it to print the error on correct location. I can pass it as a parameter through main.pl.

Sample of new main.pl:

#!/usr/bin/perl use Person; use strict; use warnings; use Employee; my $dirToBePassed = "/path/Dir"; my $object = new Person( "Thanos", "Test", 123456); my $firstName = $object->getFirstName(); print "This is the first name: $firstName\n"; my $secondObject = new Employee( "refToBeUsed" ); my $solution = $secondObject->somethingCalledFromMain(); print "This is the solution : $solution\n";

Sample of new Employee.pm

#!/usr/bin/perl use strict; use warnings; package Employee; sub new { my $class = shift; my $self = { refFromMain => shift, }; bless $self, $class; return $self; } sub somethingCalledFromMain { my( $self ) = @_; =comment do something here; warn "I was not able to complete the process!\n"; =cut return $self->{refFromMain}; } my %WARNS; local $SIG{__WARN__} = sub { my $message = shift; return if $WARNS{$message}++; logger('warning', $message); }; sub logger { my ($level, $msg) = @_; if (open my $out, '>>', 'log.txt') { chomp $msg; print $out "$level - $msg\n"; close $out; } } 1;

Sample of working output:

This is the first name: Thanos This is the solution : refToBeUsed

It is really easy to pass the my $dirToBePassed = "/path/Dir"; to Employee.pm as somethingCalledFromMain($dirToBePassed); with minor code modifications. The problem is how to pass this parameter to %WARNS. So I can print the warnings on the correct directory.

Thank you for your time and effort reading and replying to my question.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re^2: Inheritance without defining the object on inherited module by thanos1983
in thread Inheritance without defining the object on inherited module by thanos1983

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.