open (F, "$fname") vs open $F, $fname;

G

Great Deals

what is the difference here? I can add my to open my $F, $fname, but
not open (my F, "$fname").

Can I use $F the same as F?
 
T

Tad McClellan

Great Deals said:
what is the difference here?


What is the difference _where_?

(please put the code in the body of your message too)


Subject: open (F, "$fname") vs open $F, $fname;

There are at least 3 differences, so I don't know which difference
is the one that you are asking about...

1) the 1st one has a useless use of double quotes,
the 2nd one doesn't.

2) the 1st one has parens around open's argument list,
the 2nd one doesn't.

3) The 1st one has a filehandle as the first argument,
the 2nd one has a scalar as the first argument.

I can add my to open my $F, $fname, but
not open (my F, "$fname").


Looks like you mean difference #3, so let's factor out
the first two differences:

open F, $fname vs open $F, $fname;

Can I use $F the same as F?


Yes and no, depending on what you mean by "use the same".

The best and most general answer is: No

See Abigail's followup regarding how a scalar and a filehandle differ.


OTOH, if you meant "use the same" as in doing input/output,
then the answer is: Yes

<F> # input with a filehandle
<$F> # input with a ref to anon filehandle (see: perldoc -f open)

print F "stuff\n" # output with a filehandle
print $F "stuff\n" # output with a ref to anon filehandle
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top