I'm trying to create what should be a simple little sub in Perl that preferably does not use any modules not found in the standard RedHat linux distribution. In other words the more portable the better because I cannot always control which system environment I'm working in. The obvious problem is passing the variables to the subroutine so that both the original variable name and the value can be used. I can get one or the other but can't figure out how to do both without a more complex input for the sub call as shown below. I could pass a string and a reference but that would be almost as messy as just printing it locally with a simple:
print "\$A = $A\n";
There are also potential scope issues but one step at a time. I'm now thinking maybe this isn't that simple.
(Yes this is absolutely lazy programmer code I'm looking for)
Example Pseudo Code:
my $A = 1;
my $secondVar = "something new";
my $XXX = 12345;
# Print a listing of the variables of interest in a nice easy to read listing
# with a minimum of typing.
printVars( $A, $secondVar, $XXX );
# Note I could settle for passing by reference \$A but no more complicated than this in
# the sub call. This is just a little utility sub to use to double check variables while
# coding something new.
Output:
$A = 1
$secondVar = something new
$XXX = 12345
A rough SUB:
sub printVars {
my @ListOfVars = @_;
my $i;
my ($theVarName, $theVarValue);
for( $i=0; $i<@ListOfVars; $i++) {
$theVarName = ??; # This is where things break down.
$theVarValue = $ListOfVars[$i];
print "$theVarName = $theVarValue\n";
}
}
Thanks for any help you can render..
Enjoy.. --Bryan