This is the script i call My::Package functions from:

use strict; use warnings; use My::Package (keys %My::Package::); # <-----why does this work? open (my $file, '<', shift); print_lines($file); test("hello world\n"); test_2("hello this is dog");

And this is my module I created for testing:

package My::Package; use Exporter qw(import); @EXPORT_OK = (keys %My::Package::); use strict; use warnings; sub print_lines{ my ($input) = shift; while(<$input>){ print; } close($input); } sub test{ my ($input) = shift; print $input; } sub test_2{ my ($input) = shift; print $input; }

Sample input data:

this is a test!!!!

I just want to know if this is safe to export with @EXPORT_OK = (keys %My::Package::); and import with use My::Package (keys %My::Package::);.

EDIT: Also am I right in thinking that the reason this works is because I am calling that specific module with keys %My::Package::. If i am wrong please help me understand... more better :)


In reply to Is this safe to export and import functions this way? by james28909

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.