unholyangl
Programmer
What I've been writing is a module to process a string and execute code accordingly for a set of scripts i'm working on (ex: read data from sockets, hence making communication easier.) But heres my problem...
Heres actual code:
Everything is working perfect (or so it seems) in my module, accept for the array references.
I am calling them from within a foreach loop using the next command to jump through.
For example:
When the array is returned, everything works here... But once we goto the next loop block; heres some code:
Then I get an error like the following:
Can't use string ("ARRAY(0x18322e4)") as an ARRAY ref while "strict refs" in use at mods/parse.pm line 66.
I turn off strict refs to do testing and the array just doesn't exist. My guess is it's getting cleared in the foreach scope. Can someone help me work out a fix for this? I need the routines to be able to pass array references back and forth to eachother... Or am I gonna need to apply a hack thats gonna slow execution speed and open doors for bugs?
HELP!! THX!
Heres actual code:
Code:
sub trim {
my $str = shift;
$str =~ s/^\s+//;
$str =~ s/\s+$//;
return $str;
}
$_cmds{'trim'} = sub { # Wrapper to support arrays
my $val; my @ret;
while ($val = shift) { push(@ret, trim($val)); }
if ( @ret > 1 ) { return \@ret; } else { return shift @ret; }
};
Everything is working perfect (or so it seems) in my module, accept for the array references.
I am calling them from within a foreach loop using the next command to jump through.
For example:
Code:
# Execute a statement?
( $ccmd eq ";" ) && do {
@tarr = @{$parr} if $parr && $parr ne 'ARRAY'; # Check
$parr = \@carr; # reset
if ( @tarr ) {
$ecmd = $cmds->{shift(@tarr)}; # Retrieve command reference
$lcmd = &$ecmd(@tarr) if $ecmd; # Execute and store in $lcmd
# This part is added to test....
print("Returned from $ecmd: $lcmd\n");
if ($lcmd =~ 'ARRAY') {
@tarr = @{$lcmd};
print("addr: $lcmd; count: ".@tarr."; stringified: @tarr;\n");
}
@tarr = (); # Empty the array
}
next; };
When the array is returned, everything works here... But once we goto the next loop block; heres some code:
Code:
# Separator?
( $ccmd eq "," ) && do {
# This part is added to test....
if ($lcmd =~ 'ARRAY') {
@tarr = @{$lcmd};
print("addr: $lcmd; count: ".@tarr."; stringified: @tarr; -,,\n");
}
push(@carr, $lcmd); $lcmd = undef;
$parr = \@carr;
next; };
Then I get an error like the following:
Can't use string ("ARRAY(0x18322e4)") as an ARRAY ref while "strict refs" in use at mods/parse.pm line 66.
I turn off strict refs to do testing and the array just doesn't exist. My guess is it's getting cleared in the foreach scope. Can someone help me work out a fix for this? I need the routines to be able to pass array references back and forth to eachother... Or am I gonna need to apply a hack thats gonna slow execution speed and open doors for bugs?
HELP!! THX!