![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Unix Arithmatic operation issue , datatype issue | thambi | Shell Programming and Scripting | 23 | 02-19-2008 07:19 AM |
| issue with if loop in perl | amitrajvarma | Shell Programming and Scripting | 4 | 01-09-2008 12:02 AM |
| perl problem - another 'die' issue. | mjays | Shell Programming and Scripting | 4 | 08-15-2007 08:36 AM |
| perl help with pipes and file handles (simple issue) | the_learner | Shell Programming and Scripting | 1 | 05-06-2007 05:34 AM |
| Perl problem (compiling issue) | 01000101 | Shell Programming and Scripting | 3 | 05-24-2006 10:15 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
hi
one perl issue i have xml file with 2 values and one condition b.w them Code:
<rule>
<val1>12</val1>
<cond>and</cond>
<val2>13</val2>
</rule>
$one{val1} = 12 $one{cond} = and $one{val2} = 13 now i want to form query from this like if val >= val1 and val <= val2 then do something how to do this in code ? Code:
if ( val >= $one{val1} $one{cond} val <= $one{val2} )
|
|
||||
|
That's a pretty wicked idea, but if you really think you want to do it,
Code:
if (eval "$val => $one{val1} $one{cond} $val <= $one{val2}")
You should realize that with the double quotes, what eval sees is just a string, no variables. Compare: print "$val => $one{val1} $one{cond} $val <= $one{val2}" -- eval will evaluate what the corresponding print prints. |
|
||||
|
thanx for reply i think i should explain u whole situation
i have unix server monitor script in which i have many rules which are hard coded so even for slightest change i have to change code so i have created xml file with no of primary conditions , relation bw them like ( and / or ) actual condition and so on ... i spent entire day on new code architecture but i think i have to go with little hard coding even i thought its pretty wicked idea but thanx for ur reply i learned something new .... |
|
||||
|
You can use a look up hash that points to subrotuines depending on the operator, an short example:
Code:
%com = (
and => \&and,
);
$one{val1} = 9;
$one{cond} = 'and';
$one{val2} = 13;
$val = 10;
if ($com{$one{'cond'}}->($val,$one{'val1'},$one{'val2'})) {
print "true";
}
sub and {
my ($v0,$v1,$v2) = @_;
return(1) if ($v0 >= $v1 && $v0 <= $v2);
return(0);
}
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|