473,387 Members | 1,398 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

store a command to a variable.

fetaelin
Hi
I need to store a command or a command combination to an Perl Variable, and then execute it in perl,
how to do that ?
I tried to put ls /etc/ tp $com and then store the result to $h but it did not wok.
the most importent part for me is the first row "$com=`ls /etc/`;" but it seams to be the wrong way to do it. please help

$com=`ls /etc/`;
$h=`$com`;
print $h;
May 24 '07 #1
4 1886
KevinADC
4,059 Expert 2GB
don't use backtiks when assigning a value to $com use single-quotes:



Expand|Select|Wrap|Line Numbers
  1. $com = 'ls /etc/';
  2. $h = `$com`;
  3. print $h;
May 24 '07 #2
numberwhun
3,509 Expert Mod 2GB
$com=`ls /etc/`;
Somebody please correct me if I am wrong, but doesn't the line above actually stores the result of the "ls /etc/" into the variable $com? There shouldn't be a need to assign the $com variable to another variable unless you really want to use the other variable for some reason.

Regards,

jlk
May 24 '07 #3
KevinADC
4,059 Expert 2GB
Hi numberwhun,

You are correct but it is also common to store the command in a variable to be used later in the script.

Welcome to TSDN,
Kevin (aka KevinR - perlguru forum)
May 24 '07 #4
numberwhun
3,509 Expert Mod 2GB
Kevin,

Hi numberwhun,

You are correct but it is also common to store the command in a variable to be used later in the script.

Welcome to TSDN,
Kevin (aka KevinR - perlguru forum)
Thanks! and Thanks for the Welcome! I was wondering if the two posters were one in the same person. :-)

Regards,

Jeff
May 25 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Jaime Rios | last post by:
Hi, I created a COM AddIn for Word that performs the functions that it needs to, but I needed to add the ability for the toolbar created by the COM AddIn to remember it's last position and...
4
by: Daniel Caetano | last post by:
Hi all, i have a store procedure that i use the return function . Ex. create procedute XX as (statement...) if @@error <> 0 return 1 else return 0 . Inside the vb net i wnat to call that...
3
by: Michelle Stone | last post by:
hi al i have "variab1 = window.open ("a.aspx", "helloworld"); i do this inside a RegisterStartupScrict ("key", "<script language=javascript>******</script>"); where ***** is hte javascript...
6
by: Mike Hoff | last post by:
I am trying to write a class that will store info about database fields for building UPDATE / INSERT commands later on. I cannot seem to get the sytax correct to pass and store the data type of...
1
by: Timothy Wang | last post by:
Hi everyone : Is there anybody know how to use a string store in a variable as command ? Like : str1='test...' str2='...test' str3='left(str1, 5) & Right((str2,3 ) ' How do we get...
5
by: Michal Táborský | last post by:
I am wondering, if it's effective to use text arrays to store multilanguage information. We used to do it like this: CREATE TABLE product ( id serial NOT NULL, price float4, ... )
11
by: c676228 | last post by:
Hi everyone, I am just wodering in asp program, if there is anybody writing store procedure for inserting data into database since there are so many parameters need to be passed into store...
1
by: iask | last post by:
Hi, I am a rookie to learn Tcl/Expect,I want to know how to store a expect output in a variable? when I using the command "send ",then maybe many output,I don't want just expect one all some...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.