Gurus,

I'm having a problem getting Switch to work. I have a subroutine which is just 
a large switch statement, and switch statements (including a nested one) in the 
mainline code. As separate programs (with the subroutine broken out into a stub 
program), they both work perfectly. When I put the switch version of the sub 
back into the program code, the thing breaks with the message: "Bad switch 
statement (problem in the code block?) near test.pl line 4294."  I should 
mention that line 4294 is the last line of the source file; so no help there.

This is the subroutine code:

sub get_software_data {

my ($line, $flag) = @_;



  my ($name, $vrsn) = (q{})x2;



   # Local (nested) subs for various products:

   local *dnet_sub = sub {

                           $line =~ /^.* Version (.*)$/;

                           $name = 'Wizards to adjust .NET Framework security';

                           $vrsn = (length( $1 ) > 0) ? $1 : "N/A";

                         };

   local *java_sub = sub {

                           $line =~ /^.* Version ((\d+).*)$/;

                           $name = 'Java Platform Standard Edition';

                           $vrsn = "1\.$2 ($1)";

                          };

   local *mcav_sub = sub {

                           $line =~ /^([^\d]*)\.(.*)$/;

                           $name = $1;

                           $vrsn = (length( $2 ) > 0) ? $2 : "N/A";

                         };

   local *perl_sub = sub {

                           $line =~ /^.* Build (.*) version (.*)$/;

                           $name = "ActiveState ActivePerl";

                           $vrsn = ($2 ne "N/A") ? sprintf( "%s (build %s)", 
$2, $1 ) : $2;

                         };

  local *dflt_sub = sub {

                           $line =~ /^(.*) Version (.*)$/;

                           $name = $1;

                           $vrsn = (length( $2 ) > 0) ? $2 : "N/A";

                         };

   local *misc_sub = sub {

                           $line =~ /^(.*)\s+(.*)$/;

                           $name = $1;

                           $vrsn = (length( $2 ) > 0) ? $2 : "N/A";

                         };



   switch ($line) {

      case /Java Platform Standard Edition/                                     
 { java_sub() }

      case /Sun Microsystems, Inc. - Java\(TM\) Platform SE \d* U\d+/           
 { java_sub() }

      case /Sun Microsystems, Inc. - Java\(TM\)\s*\d* Platform Standard 
Edition/ { java_sub() }

      case /Wizards to adjust \.NET Framework/ { dnet_sub() }

      case /Version/ { dflt_sub() }

      case /ActiveState, a division of Sophos - ActivePerl Build/ { perl_sub() }

      case /ActiveState Tool Corp\. - ActivePerl Build/           { perl_sub() }

      case /McAfee, Inc\. - VSCORE\./ { mcav_sub() }

      case /Access for Windows/    { misc_sub() }

      case /Client Access Express/ { misc_sub() }

      else {

         $name = $line;

         $vrsn = ($flag) ? "N/A" : "data";

      }

   }



   return( $name, $vrsn );

}

And here's a sample from the mainline code:


use Switch;

...



         if (defined( $key )) {

            switch ($col_ndx) {

               case 0 {

                  $col_data = $sw_data{$key};

               }

               case ($check_col) {

                  if (defined( $col_data )) {

                     $data_line =~ s{>[^<]*<}

                                    {>$col_data<}; # Insert new data

                     undef $col_data;

                  }

               }

            } # end switch ($col_ndx)



            ++$col_ndx;

         } # end if

What the deuce am I missing, or doing wrong? Again, as separate programs, both 
the subroutine and the mainline (with a different, non-"switch" version of the 
sub), work fine. Combined, I get the error above.

TIA,

Deane Rothenmaier
Programmer/Analyst - IT-StdCfg
Walgreens Corp.
2 Overlook Point #N51022D
MS 6515
Lincolnshire, IL 60069
224-542-5150

Never trust a computer you can't throw out a window. - Steve Wozniak

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to