Filehandle Comparing? 
Author Message
 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  
 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  
 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  
 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  
 
 [ 4 post ] 

 Relevant Pages 

1. Using filehandles with compare

2. ARGV compared to a standard array/filehandle

3. Had trouble comparing 2 files using File::Compare

4. ref doesn't return FileHandle for FileHandles?

5. print to filehandle when filehandle is a $var

6. ANNOUNCE: FileHandle::Rollback - FileHandle with rollback and commit

7. Redirecting filehandle to multiple filehandles

8. Benchmark: local filehandle vs. Filehandle.pm

9. global filehandle, dereferencing filehandle

10. Ref.pm / Data::Compare / copy,compare refs / new module?

11. Compare integes is faster than compare strings also in perl?

12. compare object identity with "use overload".

 

 
Powered by phpBB® Forum Software