Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: how to have / in FILEHANDLE?

by tobyink (Abbot)
on May 28, 2012 at 06:45 UTC ( #972784=note: print w/replies, xml ) Need Help??

in reply to how to have / in FILEHANDLE?

You can't have a slash in a filename for the same reason you can't have one in a sub name:

sub hello/world { say "Hello World"; }

Subs and non-lexical filehandles are declared using a "bareword", and barewords can't contain slashes. A better question is why in the name of all that is good and holy would you want to do this?!

You do know that the file handle and the file name have nothing to do with each other?

OK, I'll admit I lied earlier. It is possible to name a sub with a slash. You just need to declare it and call it using unusual syntax...

*{'hello/world'} = sub { print shift, "\n"; }; &{'hello/world'}("Hello World!");

And similarly it can be done with filehandles...

open *{'hello/world'}, '>', '/home/tai/tmp/helloworld.txt'; print {*{'hello/world'}} "Hello World!\n";

The "why in the name of all that is good and holy" question still stands though.

Nowadays there's rarely any excuse to not be using lexical file handles. (i.e. file handles declared using the my keyword.)

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Replies are listed 'Best First'.
Re^2: how to have / in FILEHANDLE?
by Anonymous Monk on May 28, 2012 at 07:26 UTC

    And similarly it can be done with filehandles...

    Like the OP shows, the globularness isn't required, just quote a string

    open '/ugly', 'foo.txt' or die $!; print readline '/ugly'; close '/ugly';

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://972784]
[choroba]: say unpack 'H*', pack 'B*', $mask =~ /0b([01]+)/;
[choroba]: use C instead of H to get the decimal number
[erix]: ( no love like f love )
[choroba]: f* love

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2018-02-20 16:38 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (272 votes). Check out past polls.