Here's some code:
#!/usr/bin/perl -wT
use strict;
open (FOO, '>/tmp/foobar') or die "Couldn't open /tmp/foo: $!\n";
my $self = { 'fh' => \*FOO};
print $self->{'fh'} "This is a test\n";
This fails with the following error:
String found where operator expected at ./foo.pl line 5, near "} "Thi
+s is a test\n""
(Missing operator before "This is a test\n"?)
syntax error at ./foo.pl line 5, near "} "This is a test\n""
Now, if i change the code a little bit, it works fine:
my $fh = $self->{'fh'};
print $fh "This is a test\n";
Why? I thought that
$self->{'fh'} wasn't being intepreted in the correct context. So i even tried this (which failed as well):
print scalar($self->{'fh'}) "This is a test\n";
Why is this? I realize that filehandle references are easier to deal with in 5.6, but we use 5.0053 at work, and there's no way we're switching anytime soon. So is this a known bug, or am i totally missing something?
BlueLines
Disclaimer:
This post may contain inaccurate information, be habit forming, cause atomic warfare between peaceful countries, speed up male pattern baldness, interfere with your cable reception, exile you from certain third world countries, ruin your marriage, and generally spoil your day. No batteries included, no strings attached, your mileage may vary.