GLOB/FH/String

H

Hendrik GReving

Hi,

I have an FileHandle $fh; When I do "print $fh" the FileHandle is treated as
a String and it prints the filename. I need to have a scalar string (for a
list) now, how can I "cast" the FH into a String?


greetings Hendrik
 
A

Anno Siegel

Hendrik GReving said:
Hi,

I have an FileHandle $fh; When I do "print $fh" the FileHandle is treated as
a String and it prints the filename.

The file *name*? That is a strange filehandle indeed.

That it is interpreted as a string is normal. It's just the way Perl
resolves this particular ambiguity. Write "print $fh, $_" for the
other interpretation.
I need to have a scalar string (for a
list) now, how can I "cast" the FH into a String?

....but this is what happened, it was used as a string. To enforce
stringification (on any Perl variable), put it in double quotes: "$fh".

Anno
 
H

Hendrik Greving

Anno said:
The file *name*? That is a strange filehandle indeed.

That it is interpreted as a string is normal. It's just the way Perl
resolves this particular ambiguity. Write "print $fh, $_" for the
other interpretation.


...but this is what happened, it was used as a string. To enforce
stringification (on any Perl variable), put it in double quotes: "$fh".

Anno


Ok :) I should have tried this. Anyway, what happens when doing ""? Is this
a cast or can a Filehandle return its Filename implicitly?

greetings Hendrik
 
A

Anno Siegel

Hendrik Greving said:
Ok :) I should have tried this. Anyway, what happens when doing ""? Is this
a cast or can a Filehandle return its Filename implicitly?

A file can have any number of names, from zero to anything. A filehandle
knows nothing about them. There is no way to go from an open file to
(any of its) name(s) in the file system.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top