P
Paul Lalli
Greetings.
I'm noticing some bizzare behavior when use'ing the Switch.pm module.
It seems to be affecting how the < > operator behaves when the
filehandle enclosed is stored in a lexical reference. The behavior is
seen using perl v5.8.0 on solaris, with Switch.pm v2.09. An example:
#!/usr/bin/perl
use Switch;
use strict;
use warnings;
open my $fh, '<', $ARGV[0] or die "Cannot open $ARGV[0]: $!";
while (my $line = <$fh>){
print "Read: $line";
}
close $fh;
my $foo = 1;
switch ($foo){
case 1{
print "foo =1\n";
}
case 2 {
print "foo = 2\n";
}
}
__END__
Run this script passing any text file on the command line. (I cannot
post a self-contained example using __DATA__, as you'll see in a
moment). The output is not the lines of the file, but rather a GLOB
reference:
Read: GLOB(0x2496c)foo =1
Running the example through B:eparse shows the reason for the odd
output:
use Switch;
BEGIN {${^WARNING_BITS} = "UUUUUUUUUUUU"}
use strict 'refs';
die "Cannot open $ARGV[0]: $!" unless open my $fh, '<', $ARGV[0];
use File::Glob ();
while (defined(my $line = glob(' ' . $fh))) {
print "Read: $line";
}
close $fh;
[snip remaining code]
Why would C<<$fh>> be treated as C<glob(' ' . $fh)> rather than
C<readline($fh)>?
The example works fine when the use Switch; line and switch($foo) block
are all commented out. It will manifest the problem if the switch block
is commented out (either through POD blocks or multiple #'s) but use
Switch; remains. It will NOT manifest the problem if the switch block
is actually removed from the file.
If we change the example to use bareword filehandles instead of lexical
referenced filehandles, the problem does not manifest itself:
#!/usr/bin/perl
use Switch;
use strict;
use warnings;
open FH, '<', $ARGV[0] or die "Cannot open $ARGV[0]: $!";
while (my $line = <FH>){
print "Read: $line";
}
close FH;
my $foo = 1;
switch ($foo){
case 1{
print "foo =1\n";
}
case 2 {
print "foo = 2\n";
}
}
__END__
This code works fine.
Note that I do have access to another solaris system running perl 5.8.2
and Switch.pm v2.10, which does not manifest this issue, so I'm content
to call it a bug fix. The problem is that I have found no references to
this issue in the Switch.pm docs nor the perldelta's for 5.8.1 or 5.8.2.
Has anyone else ever seen this?
Thank you for your time,
Paul Lalli
I'm noticing some bizzare behavior when use'ing the Switch.pm module.
It seems to be affecting how the < > operator behaves when the
filehandle enclosed is stored in a lexical reference. The behavior is
seen using perl v5.8.0 on solaris, with Switch.pm v2.09. An example:
#!/usr/bin/perl
use Switch;
use strict;
use warnings;
open my $fh, '<', $ARGV[0] or die "Cannot open $ARGV[0]: $!";
while (my $line = <$fh>){
print "Read: $line";
}
close $fh;
my $foo = 1;
switch ($foo){
case 1{
print "foo =1\n";
}
case 2 {
print "foo = 2\n";
}
}
__END__
Run this script passing any text file on the command line. (I cannot
post a self-contained example using __DATA__, as you'll see in a
moment). The output is not the lines of the file, but rather a GLOB
reference:
Read: GLOB(0x2496c)foo =1
Running the example through B:eparse shows the reason for the odd
output:
use Switch;
BEGIN {${^WARNING_BITS} = "UUUUUUUUUUUU"}
use strict 'refs';
die "Cannot open $ARGV[0]: $!" unless open my $fh, '<', $ARGV[0];
use File::Glob ();
while (defined(my $line = glob(' ' . $fh))) {
print "Read: $line";
}
close $fh;
[snip remaining code]
Why would C<<$fh>> be treated as C<glob(' ' . $fh)> rather than
C<readline($fh)>?
The example works fine when the use Switch; line and switch($foo) block
are all commented out. It will manifest the problem if the switch block
is commented out (either through POD blocks or multiple #'s) but use
Switch; remains. It will NOT manifest the problem if the switch block
is actually removed from the file.
If we change the example to use bareword filehandles instead of lexical
referenced filehandles, the problem does not manifest itself:
#!/usr/bin/perl
use Switch;
use strict;
use warnings;
open FH, '<', $ARGV[0] or die "Cannot open $ARGV[0]: $!";
while (my $line = <FH>){
print "Read: $line";
}
close FH;
my $foo = 1;
switch ($foo){
case 1{
print "foo =1\n";
}
case 2 {
print "foo = 2\n";
}
}
__END__
This code works fine.
Note that I do have access to another solaris system running perl 5.8.2
and Switch.pm v2.10, which does not manifest this issue, so I'm content
to call it a bug fix. The problem is that I have found no references to
this issue in the Switch.pm docs nor the perldelta's for 5.8.1 or 5.8.2.
Has anyone else ever seen this?
Thank you for your time,
Paul Lalli