R
Richard Gration
Hi All,
I've happened on this situation and I'm wondering if I'm correct. The code
below illustrates my point, in the sub log_write. The commented out print
line (#1) generates a "String found where operator expected" error, but I
don't see why it has to. I don't see why print #1 shouldn't parse and
indeed execute, it seems to be a deficiency in the parser. Can anybody
please explain?
Cheers
Rick
------------------------------------
#!/usr/bin/perl
use strict;
use warnings;
my $c = config();
log_write($c,'Start run');
log_write($c,'End run');
sub config {
my $config = {};
open my $fh,'>','log.log' or die "Pants: $!\n";
$config->{log_fh} = $fh;
$config->{log_to_file} = 1;
return $config;
}
sub log_write {
my ($config,@log) = @_;
return unless $config->{log_to_file};
# print #1
# This is what I would like to be able to do
# but it generates an error
# print $config->{log_fh} "$_\n" for @log;
# print #2
# This is what I must do
my $fh = $config->{log_fh};
print $fh "$_\n" for @log;
}
I've happened on this situation and I'm wondering if I'm correct. The code
below illustrates my point, in the sub log_write. The commented out print
line (#1) generates a "String found where operator expected" error, but I
don't see why it has to. I don't see why print #1 shouldn't parse and
indeed execute, it seems to be a deficiency in the parser. Can anybody
please explain?
Cheers
Rick
------------------------------------
#!/usr/bin/perl
use strict;
use warnings;
my $c = config();
log_write($c,'Start run');
log_write($c,'End run');
sub config {
my $config = {};
open my $fh,'>','log.log' or die "Pants: $!\n";
$config->{log_fh} = $fh;
$config->{log_to_file} = 1;
return $config;
}
sub log_write {
my ($config,@log) = @_;
return unless $config->{log_to_file};
# print #1
# This is what I would like to be able to do
# but it generates an error
# print $config->{log_fh} "$_\n" for @log;
# print #2
# This is what I must do
my $fh = $config->{log_fh};
print $fh "$_\n" for @log;
}