title: How can I call a package in the same Perl file as in SO q 2621225
body: <p>I'm working my way through <em>Higher Order Perl</em>, and want to try to execute some of its code, in this case <code>FlatDB.pm</code>.</p>
  
  <p>I tried to simulate the calling method outlined in the answers to <a href="https://stackoverflow.com/questions/2621225/how-can-i-call-a-perl-package-i-define-in-the-same-file">this question (2621225)</a>, but it's not working for me. To wit:</p>
  
  <pre><code>## HOP Chapter 4 section 3.4, p.140
  my $FIELDSEP = qr/:/; 
  
  package FlatDB; 
  
  sub new {
    my $class = shift;
    my $file = shift;
    open my $fh, "&lt; $file" or return;
    chomp(my $schema = &lt;$fh&gt;);
    my @field = split $FIELDSEP, $schema;
    my %fieldnum = map { uc $field[$_] =&gt; $_ } (0..$#field);
    print "\nfieldnum=",%fieldnum;
    bless { FH =&gt; $fh, FIELDS =&gt; \@field, FIELDNUM =&gt; \%fieldnum,
        FIELDSEP =&gt; $FIELDSEP }   =&gt; $class;
  }
  # More subs here - snipped
  </code></pre>
  
  <p>What I added to try to run the package:</p>
  
  <pre><code>package main;
  print "\nat 89";
  $obj= FlatDB-&gt;new("FlatDB","SampleDB.txt"); 
  print "\nat 91"; 
  </code></pre>
  
  <p>The prints at 89 &amp; 91 are executed, but the print in the 'new' subroutine is not. The 'new' subroutine works if I pull it out of the package, so the problem must be in how I'm trying to call it.</p>
  
  <p>I'm afraid it's something very simple, but I don't see it.</p>