Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Including text files in Modules

by tfrayner (Curate)
on Nov 05, 2004 at 16:58 UTC ( [id://405548]=note: print w/replies, xml ) Need Help??


in reply to Including text files in Modules

Hi,

I've just had to figure this out myself recently. The following feels like a bit of a hack, but it does work:

use File::Spec # NB. File::Spec isn't actually required, # but it's a good cross-platform solution my @module_dir_array = File::Spec->splitpath(__FILE__); my $filename = File::Spec->catpath(@module_dir_array[0,1],'file.txt'),
It uses the __FILE__ literal which always points at the current filename (see perldoc perldata). So you can put your file.txt file in the same directory as your module.pm and the module should always be able to find it.

Tim

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-23 11:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found