sgrey has asked for the wisdom of the Perl Monks concerning the following question:
How do I get the if statement to evaluate the conditional I have placed into $var?
#!/usr/bin/perl -w use strict; my $hash_ref2={ this=>'that', some=>'thing', another=>'something', }; my $hash_ref1={ this=>'blarney', some=>'foo', chancy=>'at best', }; my @a=($hash_ref1,$hash_ref2); print "this is ".$$hash_ref2{'this'}."\n"; my $var='$$hash_ref{\'this\'} eq \'that\''; foreach my $hash_ref(@a){ if($$hash_ref{'this'} eq 'that'){ print "I only want to see case where: \"this really does equal " +.$$hash_ref{'this'}."\"\n"; } if("$var"){ print "this really does equal ".$$hash_ref{'this'}."\n\n"; } }
Results: this is that this really does equal blarney I only want to see case where: "this really does equal that" this really does equal that
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to pass a variable string as conditional argument to if statment
by ikegami (Patriarch) on May 17, 2011 at 17:23 UTC | |
|
Re: How to pass a variable string as conditional argument to if statment
by wind (Priest) on May 17, 2011 at 16:58 UTC | |
by sgrey (Novice) on May 17, 2011 at 20:42 UTC | |
by wind (Priest) on May 17, 2011 at 21:07 UTC | |
by Anonymous Monk on Feb 05, 2016 at 20:32 UTC | |
by poj (Abbot) on Feb 06, 2016 at 07:00 UTC | |
by choroba (Cardinal) on Feb 06, 2016 at 08:25 UTC |