I think I've just found a switch bug:

With this code:
<code>
use strict 'subs';
use warnings;
use Switch;

# get current config
sub getIfConfig(){
   my $GotConfig;
   my $Interface_no=0;
   return if defined $GotConfig;
   open(READ,"c:\\temp\\thing.txt") or die "Error!";
   my @ifconfig=<READ>;
   my $counter=-1;
   foreach my $line (@ifconfig){
      chomp $line;
      switch($line){
         case /^\s+DHCP habilitado.*$/ {
            my $dhcp=$line=~/No/?0:1;
            print "dhcp:\t\"$dhcp\"\n";
         }
         case /^Configuraci.n para la interfaz.*$/ {
            $counter++;
            # Get the interface name
            my ($name)=$line=~/^.*\"(.*)\".*$/;
            print "name:\t\"$name\"\n";
         }
         case /^\s+Servidores DNS configurados 
est.ticamente.*$|^\s+\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}.*$/ {
            my ($dns)=$line=~/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/;
            print "dns:\t\"$dns\"\n";
         }
         case /^\s+M.scara de subred.*$/ {
            my ($mask)=$line=~/^.*:\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/;
            print "mask:\t\"$mask\"\n";
         }
         case /^\s+Direcci.n IP.*$/ {
            my ($ip)=$line=~/^.*:\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/;
            print "ip:\t\"$ip\"\n";
         }
         case /^\s+Puerta de enlace predeterminada.*$/ {
            my ($gateway)=$line=~/^.*:\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/;
            print "gateway:\t\"$gateway\"\n";
         }
      }
   }
   $GotConfig="yes";
   $Interface_no=$counter+1;
}
&getIfConfig();
</code>

I get the following error:
C:\temp>perl kaka.pl dsadjsadljsafpsfjkpdsfj nidsafjdsfjnlds fdsfdsf 321312�
syntax error at kaka.pl line 25, near "}continue"
syntax error at kaka.pl line 46, near "}"
Execution of kaka.pl aborted due to compilation errors.


And as you can see in line 25 there is no continue... But if I move the first 
case
to the last one it works perfectly:



<code>
use strict 'subs';
use warnings;
use Switch;

# get current config
sub getIfConfig(){
   my $GotConfig;
   my $Interface_no=0;
   return if defined $GotConfig;
   open(READ,"c:\\temp\\thing.txt") or die "Error!";
   my @ifconfig=<READ>;
   my $counter=-1;
   foreach my $line (@ifconfig){
      chomp $line;
      switch($line){
         case /^Configuraci.n para la interfaz.*$/ {
            $counter++;
            # Get the interface name
            my ($name)=$line=~/^.*\"(.*)\".*$/;
            print "name:\t\"$name\"\n";
         }
         case /^\s+Servidores DNS configurados 
est.ticamente.*$|^\s+\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}.*$/ {
            my ($dns)=$line=~/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/;
            print "dns:\t\"$dns\"\n";
         }
         case /^\s+M.scara de subred.*$/ {
            my ($mask)=$line=~/^.*:\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/;
            print "mask:\t\"$mask\"\n";
         }
         case /^\s+Direcci.n IP.*$/ {
            my ($ip)=$line=~/^.*:\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/;
            print "ip:\t\"$ip\"\n";
         }
         case /^\s+Puerta de enlace predeterminada.*$/ {
            my ($gateway)=$line=~/^.*:\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/;
            print "gateway:\t\"$gateway\"\n";
         }
         case /^\s+DHCP habilitado.*$/ {
            my $dhcp=$line=~/No/?0:1;
            print "dhcp:\t\"$dhcp\"\n";
         }
      }
   }
   $GotConfig="yes";
   $Interface_no=$counter+1;
}
&getIfConfig();
</code>

I hope this helps to find the bug I think it has. I didn't found syntax
or semantics errors on this script but, anyway, if any of you find any error
that I didn't find just tell me.

T.I.A.

PS: Note that the file used to read c:\temp\thing.txt can contain anything as
the error occurs on compilation time as you can read in the error message.

Regards,
m4c.


-- 
,----------------------------------------------------------------------.
| "If you want to travel around the world and be invited to speak      |
| at a lot of different places, just write a Unix operating            |
| system."                                                             |
| (By Linus Torvalds)                                                  |
|----------------------------------------------------------------------|
| Labs. Technician                          |                          |
| Department of Telematic Engineering       | Debian GNU/Linux Powered |
| Universidad Carlos III de Madrid          |                          |
|-------------------------------------------|                .--.      |
|                                           |               |o_o |     |
|  _________                                |      .''`.    |:_/ |     |
| |~~      @| Marcos Lorenzo de Santiago    |     : :' :   //   \ \    |
| |  ====   | E-mail:  [EMAIL PROTECTED]    |     `. `'   (|     | )   |
| |  ====   | Telephone: (+34) 91-624-9959  |       `-   /'\_   _/`\   |
| |_________| Web: www.it.uc3m.es/marcos    |            \___)=(___/   |
|                                           |                          |
`----------------------------------------------------------------------'

Attachment: pgpyUkL94FJgV.pgp
Description: PGP signature

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to