You are treating @contents as a global.
I would do this like:
use strict; use IO::File; my @contents = open_file('myfile.txt'); sub open_file { my $fh = IO::File->new($_[0], 'r') or die "Could not open file $_[0]:$!"; # slurp mode only if the don't want an array local $/ unless wantarray; return <$fh>; }
In reply to Re: Re: Modular Code
by DrZaius
in thread Modular Code
by Stamp_Guy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |