|
Author |
Message |
Ki #1 / 4
|
 Filehandle Comparing?
Hello, all, I am opening a folder in which holds just .dat files. I set the filehandle DATFILE for all of the .dat files (or, more precisely, each of them). open REGFILE, "$ENV{'BASEFOLDER'}/$ENV{'DATFILES'}/"; my ($email,$password,$name) = <REGFILE>; Right now I need to compare one variable, $address, to the name of each dat file. How do I do this? I tried: if REGFILE eq $address { #Commands Quote: }
But perl did not seem to want the filehandle. What can I do?
|
Sun, 16 May 2004 08:49:57 GMT |
|
 |
Tassilo v. Parseva #2 / 4
|
 Filehandle Comparing?
Quote: > Hello, all, > I am opening a folder in which holds just .dat files. I set the > filehandle DATFILE for all of the .dat files (or, more precisely, each > of them). > open REGFILE, "$ENV{'BASEFOLDER'}/$ENV{'DATFILES'}/"; > my ($email,$password,$name) = <REGFILE>; > Right now I need to compare one variable, $address, to the name of > each dat file. How do I do this? I tried: > if REGFILE eq $address { > #Commands > } > But perl did not seem to want the filehandle. What can I do?
The filehandle is not a string. A filehandle is (non-technically speaking) a thing associated with a file that enables perl to do different things with it (write to, read from etc.). You will have to store the second argument to open in a variable and check this variable (containing a string) with $address. As far as I know there is no Perl-function that returns the filename belonging to a filehandle. Bear in mind that a filehandle does not have to represent a file on your disk. It can also be a socket or an anonymous file (such as what IO::File::new_tmpfile creates). These things don't even have a filename. Tassilo -- Teachers have class.
|
Sun, 16 May 2004 11:55:34 GMT |
|
 |
Bart Lateu #3 / 4
|
 Filehandle Comparing?
Quote:
>I am opening a folder in which holds just .dat files. I set the >filehandle DATFILE for all of the .dat files (or, more precisely, each >of them). >open REGFILE, "$ENV{'BASEFOLDER'}/$ENV{'DATFILES'}/"; >my ($email,$password,$name) = <REGFILE>;
You're not doing that. You try to open a directory as if it was a file. That won't work. You need a glob. That way, you can get a list ofthe paths of the .dat files, and you can process them all, one by one.
... } Quote: >Right now I need to compare one variable, $address, to the name of >each dat file. How do I do this? I tried: >if REGFILE eq $address { >#Commands >} >But perl did not seem to want the filehandle. What can I do?
That doesn't make any sense. What file do you want to read your ($email,$password,$name) from? You can compare your $address to each of
any positives unless your address includes the full file path and a ".dat" extension.
-- Bart.
|
Sun, 16 May 2004 14:07:07 GMT |
|
 |
Ki #4 / 4
|
 Filehandle Comparing?
Quote:
> ... > } > >Right now I need to compare one variable, $address, to the name of > >each dat file. How do I do this? I tried: > >if REGFILE eq $address { > >#Commands > >} > >But perl did not seem to want the filehandle. What can I do? > That doesn't make any sense. What file do you want to read your > ($email,$password,$name) from? You can compare your $address to each of
> any positives unless your address includes the full file path and a > ".dat" extension.
Thanks for the help. I will try working with glob and grep, then use a pattern match to take out just the name of the dat file to compare it with the $address.
|
Mon, 17 May 2004 02:34:26 GMT |
|
|
|