Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Re: Modular Code

by DrZaius (Monk)
on Jun 14, 2001 at 22:30 UTC ( [id://88557]=note: print w/replies, xml ) Need Help??


in reply to Re: Modular Code
in thread Modular Code

Yes!

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>; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://88557]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-25 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found