bichonfrise74 has asked for the wisdom of the Perl Monks concerning the following question:

I am working on an older Perl version. Here are some details.
Perl version: 5.8.0 Redhat version: Red Hat 5.3
I want to open a file and read its contents. Below is the code. There is nothing special about the test_file.txt, it is just an ordinary text file.
#!/usr/bin/perl use warnings; use strict; use Switch; file_version_1(); file_version_2(); sub file_version_1 { open( my $fh, '<', '/tmp/test_file.txt' ) or die( "Error: $!" ); while( my $line = <$fh> ) { print "$line\n"; } close( $fh ); } sub file_version_2 { open ( FH, '/tmp/test_file.txt' ) or die ("Error: $!" ); while ( my $line = <FH> ) { print $line; } close( FH ); } sub test_switch { my $id = shift; switch( $id ) { case 'add' { print 'aa' }; } return 1; }
When the code is ran, this is what I get. The '111' is the content of the test_file.txt.
GLOB(0x98dfbdc) 111
Now, if I comment out the following:
use Switch; and sub test_switch { ... }
I get this result.
111 111
Now, if I try to run the original code in Perl 5.8.8, I would get the correct results.

So, it looks like the Switch module is causing this 'issue' on Perl 5.8.0. I also noticed that the version of Switch is 2.09 on 5.8.0 and 2.10 on 5.8.8.

I went further and ran this and got this. I am posting the snippet related to this.
$ perl -MO=Deparse ... die "Error: $!" unless open my $fh, '<', '/tmp/test_file.txt'; use File::Glob (); while (defined( my $line = glob( ' ' . $fh ))) { print "$line\n"; } close $fh
Is this a known bug for this module? Is it correct to say that the Switch module is doing some kind of source code filtering? If not, does anyone know why the original code is mis-behaving?