Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found