perl - Passing a variable to a command in a script -
I am searching everywhere and since I am taking my first step in PERL, it can be one of those But it goes here.
So I am creating a script to manage my windows and later tie it on the keyboard shortcut, so I run an order and try to cross some variables:
my $ command = `wmctrl -r: ACTIVE: -e 0,0,0, $ monitor-> {1} - & gt; {'Width'} / 2, $ monitor-> {1} - & gt; {'Height'} `; But I get an error saying that I am not passing the correct parameter in the command, but if I do this, then everything works great:
my $ test = $ monitor-> {1} - & gt; {'Width'} / 2; My $ command = `wmctrl -r: active: -e 0,0,0, $ test, $ monitor- & gt; {1} - & gt; {'Height'} `; So do I really have to do this? First, allocate it in one variable and then pass it, or what is another great way to do it?
backtake operator (or qx {} ) A String (possibly) Interpolated ). So the string accepts and not $ variables ( $ var-> 1} - & gt; {some} is also expanded but does not have math expression. So your 2-step version works, but not the first.
If you want to evaluate an expression inside the string, then you can use the next:
my $ ans = 42; print "@ {[$ ans / 2]} Reply Only half of \ n "; Print
21 is only half of the answer But it is not very readable, it is better and elegant that you are already doing - And similarly calculate the command argument, and pass qx {} or backattics to $ variables .
Comments
Post a Comment