I'll try to post it, see if it makes more sense.

main

use strict; use warnings; use File::Basename qw(dirname); use Cwd qw(abs_path); use lib dirname(dirname abs_path $0); use Library; print STDOUT $hash{"key"} . "\n"; exit 0;

this works

Library.pm

package Library; use strict; use warnings; use Exporter qw(import); our @EXPORT = qw( %hash ); our %hash = ( "key" => "Hello world!" ); 1;

these don't work

Library2.pm

package Library2; use strict; use warnings; our @EXPORT = qw( return_string ); sub return_string { return "Hello embedded library"; }

Library.pm

package Library; use strict; use warnings; use Exporter qw(import); our @EXPORT = qw( %hash ); use File::Basename qw(dirname); use Cwd qw(abs_path); use lib dirname(dirname abs_path $0); use Library2; package Library2; our %hash = ( "key" => return_string() ); 1;

I can understand it looks like the namespaces are overlapping, but the definition isn't exported even with 'our'. Just fiddled around with it, I can do our %hash = (); BEFORE the package othernamespace, and export the modification. That'll work for my case, but I'd rather not have 3-4 places I need to put the hash instead of just export and our. It seems my gripe is that a variable declared before the package othernamespace trickles down, but a variable declared after the package othernamespace doesn't trickle up when it's the same file, even though there's no complaint about the definition in another namespace and not in the original.


In reply to Re^2: Export and use different package in module by chenhonkhonk
in thread Export and use different package in module by chenhonkhonk

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.