Gossamer Forum
Home : General : Perl Programming :

include file with use strict

Quote Reply
include file with use strict
 
Quote:
open (FILE, " path to file"; or die "Can't open: $!";
$include = join ("", <FILE> );
close FILE;

But how if my script uses: use strict ?
And can anyone tell me where i can find info about this "use strict" and what it does?

[This message has been edited by chrishintz (edited January 18, 1999).]
Quote Reply
Re: include file with use strict In reply to
Just make sure that you declare $include with either my() or make it a global using use vars.

Cheers,

Alex
Quote Reply
Re: include file with use strict In reply to
Using strict is a method to ensure you are using solid programming practices in your Perl. You can disable the use of strict, but its probably not the best idea in the world. When doing file operations using strict, I often find its difficult to ensure that my file handles are being opened and closed correctly. To resolve this issue, I usually use a Perl Module called FileHandle.pm. It not only makes it easier to handle file manipulation, but it also adds some nice features that work in conjunction with file locking (flock) that ensure file integrity.

I would say that if you only open one file in your entire program, that FileHandle.pm is not needed, just be sure to declare your variables. To enable FileHandle.pm, try the following code snippet as needed:

Code:
use strict;
use FileHandle;

my ($fh, $var1, $var2, $etc);
$fh = new FileHandle;
$fh->open("< file.txt") or die "Could not open file"; # Opens a file for reading
print <$fh>;
$fh->close;
There are alot of other nice functions with the module, so if you're looking for some extra power for your file handling functions, be sure to check your PERLDOC. Yes, learning from the PerlDoc is one of the best ways to learn Perl.

Hope this is useful,


------------------
Fred Hirsch
Web Consultant & Programmer


[This message has been edited by fhirsch (edited January 19, 1999).]