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 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
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?

In reply to Switch Module on Perl 5.8.0 by bichonfrise74

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.