<> wrote in message
news:20070218224100.126$...
> "Dave Slayton" <> wrote:
>> I have a hash full of filehandles and a scalar variable containing a line
>> of text, and try to do this:
>>
>> print $fh_hash{$key} $line;
>>
>> which is rejected by the compiler, which says "Scalar found where
>> operator expected" near "} $line". It wants an operator before $line?
>
> Sure. For example, the comma operator would make it happy. perhaps
> you wouldn't be happy, but the parser would be.
>
> ...
>> Finally, if I surround
>> the file handle with curly braces like this:
>>
>> print {$fh_hash{$key}} $line;
>>
>> then it works as desired.
>>
>> Would someone please explain what's going on there?
>
> perldoc -f print
>
> I see no reason to think I could do a better job of explaining that
> is already done in the documentation. Have you already read it and
> want more explanation? If so, could you describe in more detail
> what you want explained?
Well, I see that the documentation states the curly braces must be there.
It doesn't begin to explain why. Also, some of the other things it offers
don't seem to work as it suggests, e.g.:
"(NOTE: If FILEHANDLE is a variable and the next token is a term, it may be
misinterpreted as an operator unless you interpose a "+" or put parentheses
around the arguments.)"
As I said, parentheses around $file make it think I'm invoking a subroutine,
and a + right before $file (or $file surrounded by parentheses) gives me a
very large number for output. Putting in a comma as you said does indeed
make the parser happy, but doesn't produce the desired result (which is why
I wouldn't be happy, I guess).
>
>
> Xho
>
> --
> -------------------- http://NewsReader.Com/ --------------------
> Usenet Newsgroup Service $9.95/Month 30GB