Gossamer Forum
Home : General : Perl Programming :

how do i give a file name a Handle so i can open that file in another perl script?

Quote Reply
how do i give a file name a Handle so i can open that file in another perl script?
how would i go about giving a file (or script) a handle so i can open that file in another perl program...all i want is to open (or run the file) in another perl "program"...i bought Perl for Dummies, and it kind of explains it...i tried this:

Code:
$password_script = 'Name+password.txt'
open(INFILE,$password_script);
print "$password_script";


but that didnt work...all that happend when i ran it was a blank line and then thats it...the name of the program i ran it in is not Name+password.txt also, i put INFILE as the handle b/c thats what it says in the Perl for Dummies book....any help is appriciated Smile
Quote Reply
Re: [skateboarder83] how do i give a file name a Handle so i can open that file in another perl script? In reply to
Would require("file.txt"); do what you want? That will give you access to all the sub routines in the file.txt file...

Or am I misunderstanding what you are wanting? Unsure

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [skateboarder83] how do i give a file name a Handle so i can open that file in another perl script? In reply to
Using some error checking will help a great deal.

Code:
my $password_script = 'Name+password.txt'

open INFILE, $password_script or die "Can't open it: $!";

Are you sure you want the + there?
Quote Reply
Re: [Paul] how do i give a file name a Handle so i can open that file in another perl script? In reply to
the "+" is in the .txt file's name...should i remove that? i'd try now, but im at school
Quote Reply
Re: [skateboarder83] how do i give a file name a Handle so i can open that file in another perl script? In reply to
Removing it will make things clearer. I don't know off the top of my head if it will cause problems but it's best not to use obscure characters in file names if possible.
Quote Reply
Re: [Paul] how do i give a file name a Handle so i can open that file in another perl script? In reply to
do the .txt files have to be in the same folder as the Perl files? the perl files are in C:\Perl and my .txt's are on the desktop...do i have to move them to C:\Perl ?
Quote Reply
Re: [skateboarder83] how do i give a file name a Handle so i can open that file in another perl script? In reply to
They can be anywhere, you'll just have to make sure you use the full path.
Quote Reply
Re: [Paul] how do i give a file name a Handle so i can open that file in another perl script? In reply to
arrrgh...i am so horrible at this............whenever i do this:
Code:
require("array.txt");


i get a error saying "Can't locate array.txt in @INC (@INC contains: F:/Perl/the good one/lib F:/Perl/the good one/site/lib .) at - line 48, <STDIN> line 3." By the way, my Perl files are in F:/Perl/the good one i tried doing the following also, since array.txt is on the desktop
Code:
require("Desktop/array.txt"); #i used Desktop/ cuz i dont know what the "formal" address for the desktop is...
Quote Reply
Re: [skateboarder83] how do i give a file name a Handle so i can open that file in another perl script? In reply to
Hmm no offence intended but this seems like a real struggle for you. These questions aren't so much to do with perl as a basic understanding of computing and paths etc.

Every file has an associated system path in order for you to able to locate it. You can't just add something like "Desktop" that you think seems right and expect it to work. The path to the desktop on XP for example is:

E:\Documents and Settings\Administrator\Desktop

I think before you jump somewhat in the deepend with programming you need to learn the basics. As the old saying goes, don't run before you can walk. It will only save you headaches in the long run.
Quote Reply
Re: [Paul] how do i give a file name a Handle so i can open that file in another perl script? In reply to
how do i specify where the file is? I tried this...but it didnt work, i tried taking the quotes away, that didnt work...

Code:
require("C:\Documents and Settings\hunter\Desktop\array.txt")


im sorry, i know this is easy, i just cant figure this thing out.....

Last edited by:

skateboarder83: Feb 20, 2003, 4:42 PM
Quote Reply
Re: [skateboarder83] how do i give a file name a Handle so i can open that file in another perl script? In reply to
Do yourself a big favour and save your files to a directory with a shorter path, rather than on the desktop.

You should also stick to using letters and numbers, plus the _ and - characters for filenames and directories. The '.' character should also only appear once in a filename.

Windoze might accept other characters, but many other operating systems won't and at some point (if you persevere) you're going to want to upload programs to a Web server and most of those use UNIX which very definitely does care.

Using forward slashes instead of back slashes in paths will also help avoid problems.

i.e.

C:/files/thewords.txt

not

C:\files\thewords.txt

(in the latter, \f can look like a formfeed and \t can look like a tab escape character to Perl.)
Quote Reply
Re: [wysardry] how do i give a file name a Handle so i can open that file in another perl script? In reply to
In Reply To:
Using forward slashes instead of back slashes in paths will also help avoid problems.
that worked for "require" thanks!!!!!