tenya has asked for the wisdom of the Perl Monks concerning the following question:

How would I get Perl to print "c:/data.txt" instead of "FH"?
Thanks.
use strict; use diagnostics; open FH, "> c:/data.txt" or die; print "The file is FH";

Replies are listed 'Best First'.
Re: Retrieve path from file handle?
by AgentM (Curate) on Apr 03, 2001 at 22:44 UTC
    You'll need to store the filename in a string beforehand. Given a file handle, one cannot retrieve the filename without inode hopping which you're not interested in since the real solution is far simpler.
    my $stringy='c:/data.txt'; open FH,">$stringy" or die; print $stringy;
    Done.
    AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.
Re: Retrieve path from file handle?
by arturo (Vicar) on Apr 03, 2001 at 22:43 UTC

    I'd use print "c:/data.txt";

    But seriously ... why not use a variable to hold the filename and print that out?

    my $filename = "c:\data.txt"; open FH, $filename or die "Can't open $filename:$!\n"; print "The file is $filename\n";

    It's very useful indeed.

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor