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

Hey!

I have this code:

... my $chapter = shift; my $name = ( splitpath $chapter )[-1]; my $htmldir = catdir( qw( html ) ); $name =~ s/\.pod/\.html/; $name = catfile( $htmldir, $name ); open my $fh, '>:utf8', $name or die "Cannot write to '$name': $!\n"; print $fh; return $fh; }

And I get "GLOB(0x109ad10)" when printing "$fh" - how can I get the name of the file from $fh, not simply from "$name"

Replies are listed 'Best First'.
Re: GLOB & FILE (filehandle doesn't store filename)
by Anonymous Monk on Aug 12, 2013 at 07:24 UTC
Re: GLOB & FILE
by jakeease (Friar) on Aug 12, 2013 at 07:31 UTC

    File::Spec is object-oriented, so you don't want to call subroutines directly. Instead call them as class methods:

    File::Spec->catfile('a','b');

      File::Spec is object-oriented

      Not really :) It might be class-oriented though :)

      so you don't want to call subroutines directly

      You kind of do if you're using File::Spec::Functions

      OTOH, Path::Tiny has constructor path() with many methods :)