Switch.pm affecting < > operator

Discussion in 'Perl Misc' started by Paul Lalli, Mar 17, 2005.

  1. Paul Lalli

    Paul Lalli Guest

    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::Deparse 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
     
    Paul Lalli, Mar 17, 2005
    #1
    1. Advertising

  2. "Paul Lalli" <> wrote in
    news:_Nf_d.14070$FB6.4085@trndny09:

    > I'm noticing some bizzare behavior when use'ing the Switch.pm module.


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


    Paul:

    I have no clues to offer, but just the observation that your test script
    ran as expected on my system, Win XPSP2 and

    D:\Home\asu1\UseNet\clpmisc> perl -v

    This is perl, v5.8.6 built for MSWin32-x86-multi-thread

    Ditto for:

    asu1:~ > perl -v
    This is perl, v5.8.6 built for i386-freebsd-64int

    Sorry, can't be of more help.

    Sinan.
     
    A. Sinan Unur, Mar 17, 2005
    #2
    1. Advertising

  3. On Thu, 17 Mar 2005 13:41:14 GMT, "Paul Lalli" <>
    wrote:

    >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:
    >
    >Has anyone else ever seen this?
    >
    >Thank you for your time,
    >Paul Lalli
    >
    >


    I have also experienced seemingly random problems with Switch.pm,
    using ActiveState Perl 5.8.6 on Win32. Sometimes the compiler will
    produce an error message stating that it doesn't recognize "case,"
    even though the code is valid. I can usually prevent this error
    message by randomly inserting comment lines before the Switch
    statement and recompiling, until the error finally goes away.
    Sometimes I have to experiment to find the right place to put the
    comments.

    I have tried to create a small test file that reproduces this error,
    but because there is an element of randomness in the problem, the
    error goes away when I pare away the extraneous code. I suspect that
    if I posted the unmodified code that exhibited the problem, it would
    work fine when others tried it.

    The problem is frustrating, but it occurs rarely enough that I haven't
    yet given up on Switch.pm and replaced it with if ... elsif ... else
    constructs. I have experienced this problem ever since version 5.8.0
    (and I don't think I used Perl very much before that).
     
    Steven Sommer, Mar 18, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kat
    Replies:
    5
    Views:
    1,809
  2. =?Utf-8?B?d3J5dGF0?=

    Label in a Repeater affecting Javascript performance

    =?Utf-8?B?d3J5dGF0?=, Aug 10, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    738
    Karl Seguin
    Aug 10, 2005
  3. =?ISO-8859-1?Q?Tom=E1s_Hayes?=

    Java app affecting system clock

    =?ISO-8859-1?Q?Tom=E1s_Hayes?=, Jul 9, 2003, in forum: Java
    Replies:
    0
    Views:
    447
    =?ISO-8859-1?Q?Tom=E1s_Hayes?=
    Jul 9, 2003
  4. Tracey M.

    text size affecting link

    Tracey M., Jul 10, 2003, in forum: HTML
    Replies:
    2
    Views:
    393
    Sid Ismail
    Jul 10, 2003
  5. Switch Within A Switch

    , Apr 22, 2006, in forum: Javascript
    Replies:
    7
    Views:
    123
    Lasse Reichstein Nielsen
    Apr 22, 2006
Loading...

Share This Page