Date: 11 Sep 2001 08:24:12 -0400
From: stanb@panix.com (Stan Brown)
Subject: Really bizzare syntax error
Message-Id: <9nkvpc$m4c$1@panix1.panix.com>

I started off this morning by apllying some of my newfound (from this
group) perl wisdom. I was going through changin each occurence of:

my $argtmp =  join ', ', map { "Arg$_ ->$_[$_]<-" } 0 .. $#_;

At the entrance to each of my finctions to:


my $argtmp = join ', ', map {defined($_[$_])
	? "Arg$_ ->$_[$_]<-"
	: "Arg$_ ->*UNDEF*<-"
	} 0 .. $#_;

To handle the passing of 'undef's as arguments.

However the caused the following sunroutine to be declared to have a syntax
error by the compiler!



#!/usr/local/bin/perl

use Switch;

sub DoIt($$$) {
######################################################################
#
# DoIT
#
# main callback processing subroutine
#
# All state machine controls should be placed in here for ease of
# understanding the control flow
#
# Inpits
# 
# 1. the name of the button widget that was pressed
# 2. the name of the table we are working on
# 3. pointer to an hash of data column nmaes, and atributes
#
######################################################################
my ($widget,$ltable,$hash_pointer)=@_;
my $col;
my $cb;
my $rb;
my $rc;
my $cl;
my $junk;
my $entry;
my $date;
my $function_name = (caller(0))[3];
my $argtmp = join ', ', map {defined($_[$_])
	? "Arg$_ ->$_[$_]<-"
	: "Arg$_ ->*UNDEF*<-"
	} 0 .. $#_;

print_debug(2,"Entering $function_name()\n",0,0);
print_debug(3,"$argtmp\n",0,0);

  print_debug(3,"I am in DoIt called from widget $widget.\n",1,0);


  # Process state machine
  switch ($state) {
  case 'NO_ACTIVE_QUERY' {
	if ($widget eq 'enter')
	{
		# Set widgets to proper enabled/disabled state for the allowed
		# actions in this state
  		$execute_button->configure( -state => 'active');
  		$enter_button->configure( -state => 'disabled');
		foreach $entry (keys  %Entries) {
  			$Entries{$entry}->configure( -state => 'normal');
		}
		foreach $entry (keys  %Browsentries) {
  			$Browsentries{$entry}->configure( -state => 'readonly');
		}
		foreach $date (keys  %Dates) {
			$Dates{$date}->Walk(sub {
							  eval { $_[0]->configure(-state => 'normal') }
							   });
		}
	 	foreach $rb (@radiobuttons) {
			if(defined $rb)
			{
  				$rb->configure( -state => 'active');
			}
		}
		# Go to new state
		$state = 'ENTERING_QUERY';
	}
  }
  case 'ENTERING_QUERY' {
	if ($widget eq 'execute')
	{
		# Need to build query string
		# execute it store results in an array,
		# and update %data_fields with the first record returned
		# here
		#
		# Loop through %data_fileds looking for defined fileds that
		# are not equal to '', and build WHERE clause
		# If no %date_feilds are defined and not '', then don't add WHERE
		# cluae
		#
		# In all cases specify all cols explicitly to assure that we know
		# what order thay will be returned in
		fetch_records($ltable,$hash_pointer);

		# Go to new state
		# This will be reset asynchronously when the child returns to 
		# PROCESING_QUERY_RESULTS
		$state = 'IN_QUERY';
	}
  }
  case 'PROCESING_QUERY_RESULTS' {
    switch ($widget) {
    case 'enter' {
		# Prepare for a new query

		# Set widgets to proper enabled/disabled state for the allowed
		# actions in this state
		if(defined $insert_button)
		{
  			$insert_button->configure( -state => 'disabled');
		}
		if(defined $update_button)
		{
  			$update_button->configure( -state => 'disabled');
		}
		if(defined $delete_button)
		{
  			$delete_button->configure( -state => 'disabled');
		}
  		$next_button->configure( -state => 'disabled');
  		$prev_button->configure( -state => 'disabled');
		if(defined $save_button)
		{
  			$save_button->configure( -state => 'disabled');
		}
  		$execute_button->configure( -state => 'active');
  		$enter_button->configure( -state => 'disabled');

		print_debug(3,"Zaping Data Fields\n",0,0);
		$MW->focus();
		foreach my $key (keys %{$hash_pointer}) {
			$$hash_pointer{$key} = '';
		}
		# destroy widgets conating info about qty of currently
		# selected/displayed records
		if(defined $rec_spacer)
		{
			$rec_spacer->destroy();
		}
		if(defined $rec_label)
		{
			$rec_label->destroy();
		}
		if(defined $rec_entry)
		{
			$rec_entry->destroy();
		}
		if(defined $rec_label2)
		{
			$rec_label2->destroy();
		}
		# Reset compariosn selector menuuttons to default case for new
		# query
	 	foreach $rb (@radiobuttons) {
			if(defined $rb)
			{
  				$rb->configure( -state => 'active');
			}
		}
		while (($junk, $cb) = each %comparebuttons) {
			if(defined $cb)
			{
  				$cb->configure( -state => 'disabled');
				$cb->configure( -text => 'Ignore');
			}
		}
		while (($cl, $junk) = each %compare) {
			$compare{$cl} = 'Ignore';
		}
		foreach $entry (keys  %Entries) {
  			$Entries{$entry}->configure( -state => 'normal');
		}
		foreach $entry (keys  %Browsentries) {
  			$Browsentries{$entry}->configure( -state => 'readonly');
		}
		foreach $date (keys  %Dates) {
			$Dates{$date}->Walk(sub {
							  eval { $_[0]->configure(-state => 'normal') }
							   });
		}
		# Go to new state
		$state = 'ENTERING_QUERY';
	}
    case 'next' {
		# Update %data_fields with next record here
		# PopUp error message if already displaying last record
		$pos++;
		if($pos > $record_qty )
		{
			popup_msg("Already Displaying Last Record");
			$pos = $record_qty;
		}
		else
		{
			# We depend upon the order of the columns to retrieve
			# in the SELECT statement being created in this same order
			# I don't like this, but the alternative was copying
			# all the retrieved data rows, and this was prooblematic
			# on large (1 million row) record sets
			my $i = 0;
			foreach $col (sort keys  %cols)
			{
				if($cols{$col}{'DATA_TYPE'} eq 'DATE')
				{
					my $dt = ParseDate( $records_array_ref->[($pos - 1)]->[$i]);
					$data_fields{$col} = UnixDate($dt, "%s");
				}
				else
				{
					$data_fields{$col} = $records_array_ref->[($pos - 1)]->[$i];
				}
				$i++;
			}
			# Make a copy, BEFORE anyone can change this
			# Need this to use in UPDATE
			%this_record = %data_fields;
		}
	}
    case 'previous' {
		# Update %data_fields with previous record here
		# PopUp error message if already displaying first record
		$pos--;
		if($pos < 1)
		{
			popup_msg("Already Displaying First Record");
			$pos = 1;
		}
		else
		{
			# We depend upon the order of the columns to retrieve
			# in the SELECT statement being created in this same order
			# I don't like this, but the alternative was copying
			# all the retrieved data rows, and this was prooblematic
			# on large (1 million row) record sets
			my $i = 0;
			foreach $col (sort keys  %cols)
			{
				if($cols{$col}{'DATA_TYPE'} eq 'DATE')
				{
					my $dt = ParseDate( $records_array_ref->[($pos - 1)]->[$i]);
					$data_fields{$col} = UnixDate($dt, "%s");
				}
				else
				{
					$data_fields{$col} = $records_array_ref->[($pos - 1)]->[$i];
				}
				$i++;
			}
			# Make a copy, BEFORE anyone can change this
			# Need this to use in UPDATE
			%this_record = %data_fields;
		}
	}
    case 'insert' {
		# create and execute an SQL "INSERT" here
		# using all fileds of %data_fileds that are defined and not ''
		# Be sure and capture DB errors (Duplicate Key) and use PopUp
		# to display
		$rc = validate_record();
		if ($rc == 0)
		{
			my $stmt = create_insert_statement($ltable);
			print "->$stmt<-\n";
			print_debug(3,"Prepareing to execute\n->$stmt<-\n",0,0);
			execute_input_statement($stmt);
		}
	}
    case 'update' {
		# create and execute an SQL "UPDATE" here
		# using all fileds of %data_fileds that are defined and not ''
		# Be sure and capture DB errors (No Such Record) and use PopUp
		# to display
		#
		# Might want to try "INSERT", if "UPDATE" fails here ??
		$rc = validate_record();
		if ($rc == 0)
		{
			my $stmt = create_update_statement($ltable);
			print_debug(3,"Prepareing to execute\n->$stmt<-\n",0,0);
			# execute_input_statement($stmt);
		}
	}
    case 'delete' {
		# create and execute an SQL "DELETE" here
		# using all fileds of %data_fileds that are defined and not ''
		# Be sure and capture DB errors (No Such Record) and use PopUp
		# to display
		#
		# If DB returns success, be certain to remove this record from the
		# in memory records array, and decrement the record qty.
		$rc = validate_record();
		if ($rc == 0)
		{
			my $stmt = create_delete_statement($ltable);
			print "->$stmt<-\n";
			print_debug(3,"Prepareing to execute\n->$stmt<-\n",0,0);
			# execute_input_statement($stmt);
		}
	  }
	}
  }
}
print_debug(1,"State = $state.\n",0,0);

print_debug(3,"Returning from $function_name()\n",0,0);
}

It seems to be compalining about the first swithc statement.

What dumb user error have I made, here?



