Brothers,

I am having trouble with calling new within one package to create an object from a different one. Within the code below the call to new within the s1 subroutine gives me an error:

Bareword "T" not allowed while "strict subs" in use

but I don't see why that is different from the code 10 lines higher up. What am I missing?

use strict; use warnings; { # This works my $l2 = new T; my $l1 = new P; exit 0; } { package P; sub new { my $self = {}; bless $self,shift; # This call works my $t1 = new T; return $self; } sub s1 { # This call complains that # Bareword "T" not allowed # while "strict subs" in use my $t1 = new T; } } sub s2 { # Even this works my $t1 = new T; } { package T; sub new { return bless {},shift; } }

Update:Added s2 subroutine to prove that it is something to do with packages. Also this is on Perl 5.6.1 from ActiveState running on a Windows 2000 box (but I doubt that makes a difference)


In reply to Creating new objects from within a package by hawtin

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.