Hi,
I have the following perl script working for me.I am accesing the database from my perl script using use Net::Telnet(); package.
I am not using DBI package.as I stated earlier the following program is printing the output in a nice form.However I want to pass
a variable in the - $t->cmd("SELECT * FROM TABLE_NAME WHERE INSTANCE_NAME LIKE '%hostname%' ;");
Here I want hostname to be replaced by a variable name like - $t->cmd("SELECT * FROM TABLE_NAME WHERE INSTANCE_NAME LIKE '%VARIABLE_NAME%' ;");.
I want just pass a variable in the above sql query so that I can change the VARIABLE_NAME.P lease help me out with it.
Thank You
Vivek - $IPAddress = " ";
-
$Login = " ";
-
$password = " ";
-
$Node = "hostname";
-
-
use Net::Telnet();
-
$t= new Net::Telnet (Timeout => 3000 , Prompt => '/[%#\$>?:] $/' );
-
$t->open("$IPAddress");
-
print "\nConected!";
-
$t->waitfor('/login: $/i');
-
$t->print($Login);
-
print "\nEntered the Username\n";
-
$t->waitfor('/assword: $/i');
-
$t->print($Password);
-
print "\nEntered the Password!\n";
-
@output=$t->cmd("export ORACLE_SID=$Node\n");
-
print @output;
-
print "\n Done with logging into the database\n";
-
@output= $t->cmd("bash\n");
-
print FILE @output;
-
print @output;
-
@output = $t->cmd("sqlplus username/pass\n");
-
print @output;
-
@output = $t->cmd("conn cusername/pass\n");
-
print @output;
-
@output = $t->cmd("SELECT * FROM TABLE_NAME WHERE INSTANCE_NAME LIKE '%hostname%' AND PARAM_KEY_NAME LIKE '%host';");
-
print FILE @output;
-
@output = $t->cmd("exit\n");
-
print @output;
-
@output = $t->cmd("exit\n");
-
print @output;
4 6634 numberwhun 3,509
Recognized Expert Moderator Specialist @sonu2die4
Why are you using % to specify a variable name? In Perl, a $ is for a scalar variable and a % is for a hash. If you have a $variable that you want to use, then use it in place of %hostname% as that is not correct. This is not dos scripting or any other like it.
So, you can write your statement like so: -
@output = $t->cmd("SELECT * FROM TABLE_NAME WHERE INSTANCE_NAME LIKE '$hostname' AND PARAM_KEY_NAME LIKE '$host';");
-
Also, please take note of the following:
1. Code tags are required around ANY code you post in the forums.
2. Any personal or private information (ie: usernames, passwords, IP addresses, url's, email addresses) are strictly forbidden in the general technical forums. This is for your safety and security and we expect you to please abide by this.
Regards,
Jeff
eWish 971
Recognized Expert Contributor
The % is a wildcard for MySQL. It can be used like he is using it.
--Kevin
numberwhun 3,509
Recognized Expert Moderator Specialist @eWish
Ok, but if he is trying to pass a variable from a Perl script, he should pass the variable itself, not using the syntax he is using. I have seen plenty of code where I work (and written some) to use a variable in place of a parameter in the SQL line of the code, but have never used the % in the Perl code.
eWish 971
Recognized Expert Contributor
Here is some code I wrote a while ago to illustrate how to use a placeholder in the LIKE clause, which could be practiced here as well. - my $var = 'Car';
-
my $like_var = '%' . $var . '%';
-
-
my $test = $dbh->prepare(qq|SELECT name FROM categories WHERE name LIKE ?|);
-
$test->execute($like_var);
-
-
while (my @rows = $test->fetchrow_array()){
-
foreach (@rows) {
-
print $_, '<br>' ;
-
-
}
-
}
-
$test->finish();
-
-
my $regex_test = qq|^Car|;
-
-
my $another_test = $dbh->prepare(qq|SELECT name FROM categories WHERE name REGEXP ?|);
-
$another_test->execute($regex_test);
-
-
while (my @rows = $another_test->fetchrow_array()){
-
foreach (@rows) {
-
print $_, '<br>';
-
}
-
}
-
$another_test->finish();
This way you don't lose the % wildcard and you make safer and don't have to worry about escaping the data. Helps reduce the sql injections.
--Kevin
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Wet Basement |
last post by:
I am passing data to a putcart.pl , parsing it, then building the query
string to put the item in the shopping cart:
$cartStr =
http://www.domain.com/cgi-bin/cart.pl?name=Book+Title&Stk=D123456&price=5.00
$co = new CGI;
print $co->redirect($cartStr);
print $co->start_html;
$co->end_html;
|
by: banz |
last post by:
Hello
I have a problem to resolve: I wrote a Perlscript which caches data from a
server (local on my machine) I would like to have a other connection to a
remote server but I don't know how to define the servername / hostname in
my Perl Progrem..
Here is the code:
|
by: Kirt Loki Dankmyer |
last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile
it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of
different switches, but I can't get it to compile. I need it to be
compiled with threads.
Anyone have any wisdom on how best to do this?
Here's a transcript of my latest attempt. It's long; you might want to
skip to the bottom, where I try "make" and the fatal errors start
happening.
|
by: billb |
last post by:
I installed a perl extension for PHP to use some perl inside my php
primarily because I have perl working with oracle and not php and
oracle. So I want to use my old perl scripts, and use the
functionality of php. The extension uses the '$perl->eval' function.
i am kind of stuck with the syntax or how to put the php variable into
the perl script. I have a form where the user puts in a grid
reference. Then a php script that gets the...
|
by: satish2112 |
last post by:
Hi,
I have a text-area which contains values from mysql database and 2
buttons, Edit and Update.
When I click on the Edit button, I can edit the text-area
(initially non-editable).
After this, if I click on the Update button, the values in the
text-area must be updated in the mysql database.
I am storing the values of the text-area in a variable. I am using
javascript to pass the variable.
| |
by: Rebles |
last post by:
I'm writing a PERL script to access and insert rows into a Microsoft SQL. i'm using MS SQL Server Management Studio Express (2005) to architect tables and queries.
I've inserted two records into my "Pools" table
One from MS SQL Manager as a test, and another from my PERL script.
The one inserted by MS SQL Manager shows up everytime. The row from my PERL script doesn't show up on MS SQL Manager and ONLY shows up on my PERL script and...
|
by: Rebles |
last post by:
Hi, I just posted this in the MS SQL Section, but maybe my problem is rooted in Perl, so it's more appropriate to post here instead (sorry for the double post)
I'm writing a PERL script to access and insert rows into a Microsoft SQL. i'm using MS SQL Server Management Studio Express (2005) to architect tables and queries.
I've inserted two records into my "Pools" table
One from MS SQL Manager as a test, and another from my PERL script....
|
by: happyse27 |
last post by:
Hi All,
I modified the user registration script, but not sure how to make it check for each variable in terms of preventing junk registration and invalid characters?
Two codes below :
a) html
b) perl script (print and inserting into database)
Cheers...
Andrew
|
by: sonu2die4 |
last post by:
Hi,
I have the following perl script working for me.I am accesing the database from my perl script using use Net::Telnet(); package.
I am not using DBI package.as I stataed earlier the following program is printing the output in a nice form.However I want to pass
a variable in the $t->cmd("SELECT * FROM TABLE_NAME WHERE INSTANCE_NAME LIKE '%hostname%' ;");
Here I want hostname to be replaced by a variable name like
$t->cmd("SELECT * FROM...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |