This really depends on how your files are set up. Here's an example using accounts.pm module file, and a script.pl file that uses it.

Both files are in the same directory, so I use use lib '.'; so the script knows to look in the current directory for the module file. Then in the module file, I use Exporter to set things up so you can then import the results() sub properly from the module:

accounts.pm module file

package accounts; use strict; use warnings; require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw(results); sub account { my $file = shift; open my $fh, '<', $file or die $!; my @accounts = <$fh>; close $fh; chomp @accounts; return \@accounts; } sub results { my $file = shift; my $results = account($file); return $results; } 1;

script.pl script file

use strict; use warnings; use Data::Dumper; use lib '.'; use accounts qw(results); my $file = "accounts.txt"; my $newdata = results($file); print Dumper $newdata;

accounts.txt file:

a b c d e

Output:

$VAR1 = [ 'a', 'b', 'c', 'd', 'e' ];

In reply to Re: Returning data from a sub routine in a module. by stevieb
in thread Returning data from a sub routine in a module. by Anonymous Monk

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.