Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Switch.pm affecting < > operator

Reply
Thread Tools

Switch.pm affecting < > operator

 
 
Paul Lalli
Guest
Posts: n/a
 
      03-17-2005
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:eparse 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



 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      03-17-2005
"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.
 
Reply With Quote
 
 
 
 
Steven Sommer
Guest
Posts: n/a
 
      03-18-2005
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).

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
firewall/ICS service problems affecting wireless? =?Utf-8?B?S0c2R0ZR?= Wireless Networking 1 01-25-2005 07:55 PM
Changes to QoS for VoIP is affecting NFS Richard Lefebvre Cisco 0 01-14-2005 11:01 PM
Datagrid not sized for number of items. Trying to use Flow Layout, affecting row height. Kat ASP .Net 5 10-21-2004 08:13 PM
Cisco warns of router bug affecting OSPF VolatileAcid Cisco 0 08-19-2004 11:25 PM
CRAZY new problem I have never seen affecting 3750G and 2970G ccs Cisco 0 07-30-2004 02:38 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57