How can I print a variable and its value with just core Perl on RedHat? -
I'm trying to create a simple sublanguage in Perl, which does not use any module standard Redhat Linux distribution is better in other words more portable because I'm always working in the system environment, I can not control it. The obvious problem is giving the alias the variable so that both the original variable name and value can be used. I can get one or the other but can not figure out how to do both without the more complicated input for the sub call, as I can pass a string and a reference as shown below but it is almost normal It would normally be messy in the form of a printing:
print "\ $ A = $ a \ n";
There are potential opportunities problems but one step at a time. Now I am thinking that this is not easy.
(Yes it's a lazy programmer code that I'm looking for)
example pseudo code:
my $ a = 1; My $ secondVar = "something new"; My $ XXX = 12345; # Print the list of variables of easy interest to read # listings with at least typing. Printers ($ a, $ sec, $ XXX); # Note I can arrange to pass the reference \ $ A, but in this comparison, there is no complexity in the #Day Call. This is just a bit of useful utility which doubles the check variable during some new coding.
Output:
$ A = 1 $ secondVar = new new $ XXX = 12345
A fat sub :
sub printVars {my @ListOfVars = @_; My $ i; My ($ theVarName, $ theVarValue); ($ I = 0; $ i & lt; @ListOfVars; $ i ++) {$ theVarName = ??; # This is where things break down $ theVarValue = $ listoffers [$ i]; Print "$ theVarName = $ theVarValue \ n";
Thank you for any help ..
Enjoy .. - Brian
If the use of variable names suggested by Paul Tomblin and John are acceptable, then you can order the Data :: Dumper
module In order to be able to print the data structures,
Data: Dumper
has been part of the standard pearl distribution for a long time (I just used CPA Is verified that the 5.6, 5.8, and 5.10). If your OS vendor has not split in a strange way, there is no need to worry about the data :: dumper
.
Comments
Post a Comment