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.
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.
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.Perl version: 5.8.0 Redhat version: Red Hat 5.3
When the code is ran, this is what I get. The '111' is the content of the test_file.txt.#!/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; }
Now, if I comment out the following:GLOB(0x98dfbdc) 111
I get this result.use Switch; and sub test_switch { ... }
Now, if I try to run the original code in Perl 5.8.8, I would get the correct results.111 111
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.
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?$ perl -MO=Deparse test.pl ... die "Error: $!" unless open my $fh, '<', '/tmp/test_file.txt'; use File::Glob (); while (defined( my $line = glob( ' ' . $fh ))) { print "$line\n"; } close $fh
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Switch Module on Perl 5.8.0
by eyepopslikeamosquito (Archbishop) on Oct 14, 2011 at 20:48 UTC | |
by AnomalousMonk (Archbishop) on Oct 16, 2011 at 03:11 UTC | |
by eyepopslikeamosquito (Archbishop) on Oct 16, 2011 at 07:33 UTC | |
by Anonymous Monk on Oct 23, 2011 at 07:08 UTC | |
Re: Switch Module on Perl 5.8.0
by BrowserUk (Patriarch) on Oct 14, 2011 at 19:18 UTC | |
Re: Switch Module on Perl 5.8.0
by herveus (Prior) on Oct 14, 2011 at 18:11 UTC | |
by bichonfrise74 (Vicar) on Oct 14, 2011 at 18:35 UTC |
Back to
Seekers of Perl Wisdom