Skip Menu |

This queue is for tickets about the Data-CTable CPAN distribution.

Report information
The Basics
Id: 66508
Status: new
Priority: 0/
Queue: Data-CTable

People
Owner: Nobody in particular
Requestors: artg [...] cs.nyu.edu
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 1.03
Fixed in: (no value)



Subject: calc() doesn't clear symbol table!
what should this print? i would expect joe sam red blue but it prints joe sam sam sam very popular guy, sam! the problem is that calc() doesn't clear the symbol table! use Data::CTable; $ct1 = Data::CTable->new( ); $ct2 = Data::CTable->new( ); $ct1->col('name', [qw(joe sam)]); $ct2->col('color', [qw(red blue)]); $ct2->calc( sub{ package main; no strict 'vars'; if( defined($name) ){ print "$name\n"; }else{ print "$color\n"; } }); $ct1->calc( sub{ package main; no strict 'vars'; print "$name\n"; });
From: artg [...] cs.nyu.edu
These patches to CTable v. 1.03 fix the bug and test the fix: Data/CTable.pm 2156,2161d2155 < ## Don't overwrite fields in package main. < ## First save them < no strict 'refs'; < my %tmp; < $tmp{$_} = \${$_} for(@$Fields); < 2179,2181d2172 < ## Restore fields in main < *{$_} = $tmp{$_} for(@$Fields); < Data/test.pl 11c11 < BEGIN { plan tests => 31, todo => [] } --- Show quoted text
> BEGIN { plan tests => 30, todo => [] }
71d70 < ok(test_calc_restore());## check that calc restores main vars 1590a1590 Show quoted text
>
1597,1616d1596 < sub test_calc_restore < { < my $People2 = Data::CTable->new("${TestDir}people.tabs.txt") or die; < no strict 'vars'; package main; < < # make sure that calc doesn't overwrite fields in Main < # especially important when calc is called repeatedly on tables with intersecting field names < $First = 'TEST'; < $Last = 'name with space'; < $State{'New York'} = 'NY'; < @age = ( '1' ); < $People2->calc(sub{ $First = $Last; }); < package main; < return(0) if ( $First ne 'TEST' ); < return(0) if ( $Last ne 'name with space' ); < return(0) if ( $State{'New York'} ne 'NY' ); < return(0) if ( $age[0] != 1 ); < return(1); < } <