Sponsored Content
Top Forums Shell Programming and Scripting visibility of a variable in Perl script. Post 302269574 by Niroj on Thursday 18th of December 2008 04:42:50 AM
Old 12-18-2008
visibility of a variable in Perl script.

I am writing a script to cross check the dbscript. For that I am searching the SQL manipulators in the dbscript as shown below. But my problem is the variable $pattern is coming as null when comes out of the foreach loop.

File content:
=========
vi /home2/niroj_p/dbscript.sql
-------
.......................
......................
UPDATE ...............
.......................;

INSERT.........
..............;
UPADTE.................;

====================
My perl script:
--------
my @sql_manipulator_Q= ('UPDATE','INSERT','DELETE');
& get_sql_Query(\@sql_manipulator_Q);


sub get_sql_Query()
{
my $ref_pattern_Q=shift;
my $count=0;
my $pattern;
open FH0, "/home2/niroj_p/dbscript.sql" or die "Sorry, file doesn't exist !\n";

while ( my $line = <FH0>)
{
foreach $pattern (@{$ref_pattern_Q})
{

if ($line =~ m/^$pattern/ )
{
$count++;
print "Inside foreach->$count: $pattern\n"; #coming correct
last;
}
}

print "Inside while loop-> $pattern\n"; #Coming as NULL
}

}


output:
=========
Inside while loop->
Inside while loop->
Inside while loop->
Inside while loop->
Inside while loop->
Inside while loop->
Inside foreach->1: UPDATE
Inside while loop->
Inside while loop->
Inside while loop->
Inside while loop->
Inside while loop->
Inside while loop->
Inside foreach->2: INSERT
Inside while loop->
Inside while loop->
Inside while loop->
Inside while loop->
Inside foreach->3: UPDATE
Inside while loop->
Inside while loop->


I want the variable $pattern should retain its value as in foreach loop.
please help..

Last edited by Niroj; 12-18-2008 at 05:51 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to return a value of a variable from shell script to perl script

HI , Is there any way to return a value of variable from shell to perl script. Code: === Perl file my $diff1=system("sh diff.sh"); my $diff2=system("sh diff1.sh"); I need exit status of below commands i.e 0 and 1 respectively. Since in both the cases diff is working so system... (3 Replies)
Discussion started by: srkelect
3 Replies

2. Shell Programming and Scripting

Increment a date variable in perl script

Hi, I have a perl script which prints epoch value of date in milliseconds as the output. My reuirement is that once the output is printed,the day variable shld increment by 1 and when i execute the script for the second time the output shld be for the new day value. My script looks as... (11 Replies)
Discussion started by: jyothi_wipro
11 Replies

3. Shell Programming and Scripting

Replacing variable value in perl script

hi I have this line in my perl script if (($cookie =~ /^cookie(.*)\/(.*)/) && ($ !~ /^cookie(10)\/(.*)|/)) { $cookienumber = "$1.$2"; } now if the result is cookie1/0, my $cookienumber would be 1.0 but if the result is cookie1/0/0 ... (5 Replies)
Discussion started by: tententen
5 Replies

4. Shell Programming and Scripting

Perl Variable Check Script

I am working on a perl script that is used to update a list of hosts to a certain file but I am having an issue when I try to perform a check to make sure the user enters valid information. The following is what I have currently written for the script: IPINPUT: print "Enter IP Address: ";... (2 Replies)
Discussion started by: Takau
2 Replies

5. Shell Programming and Scripting

Script to convert csv file to html with good visibility

Hi, I have Below script which converts csv file to html succesfully.but the visiblity is simple in black n white. I want to have better visibilty of each columns in different colours(like green).As it is a Database report suppose some tablespace available space is less than 20% then it should... (7 Replies)
Discussion started by: sv0081493
7 Replies

6. Shell Programming and Scripting

Using variable from shell script in perl file

Hey, So I have a shell script that outputs some variables, call them $a and $b. I know in shell scripting if I wanted to use the variables in another shell script I'd do sh code.sh "$a" "$b" How can I do something similar with perl? (2 Replies)
Discussion started by: viored
2 Replies

7. Programming

Visibility of X11 windows

Does anyone know if it is possible to check whether a window in x11 (using xlib) is visible or not? I tried XGetWindowProperty, but that doesn't work, because the windows host (dtwm on Solaris 10) does not support EWMH. (5 Replies)
Discussion started by: JenniferKuiper
5 Replies

8. Shell Programming and Scripting

Error while reading variable from a file in perl script

I have a file abc.ini and declared many variables in that file, one of the variable(DBname) value I am trying to read in my perl script but getting error. File abc.ini content # database name DBname =UATBOX my $ex_stat; my $cmd_output; $ex_stat = "\Qawk '/^DBname/{print... (2 Replies)
Discussion started by: Devesh5683
2 Replies

9. Shell Programming and Scripting

Passing variable from bash to perl script

Hi All, I need to pass a variable from bash script to perl script and in the perl script i am using those variables in the sql query but its giving error : Use of uninitialized value $ENV{"COUNTRYCD"} in concatenation (.) or string at /GIS_ROOT/custom/tables/DBread_vendor.pl line 50. Can ... (6 Replies)
Discussion started by: NileshJ
6 Replies

10. Shell Programming and Scripting

Shell Variable visibility

Dear All, Saying, I have two distinct functions with the same goal (counting lines containing a specific pattern in a file MyFile). To perform that operation, I used a "while loop" with two different syntax ("grep" command would be much more better in that case but this is not the concern in... (8 Replies)
Discussion started by: dae
8 Replies
GRUB-RENDER-LABEL(1)                                               User Commands                                              GRUB-RENDER-LABEL(1)

NAME
grub-render-label - generate a .disk_label for Apple Macs. SYNOPSIS
grub-render-label [OPTION...] [OPTIONS] DESCRIPTION
Render Apple .disk_label. -b, --bgcolor=COLOR use COLOR for background -c, --color=COLOR use COLOR for text -f, --font=FILE use FILE as font (PF2). -i, --input=FILE read text from FILE. -o, --output=FILE set output filename. Default is STDOUT -t, --text=STRING set the label to render -v, --verbose print verbose messages. -?, --help give this help list --usage give a short usage message -V, --version print program version Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options. REPORTING BUGS
Report bugs to <bug-grub@gnu.org>. SEE ALSO
The full documentation for grub-render-label is maintained as a Texinfo manual. If the info and grub-render-label programs are properly installed at your site, the command info grub-render-label should give you access to the complete manual. grub-render-label (GRUB) 2.02-2ubuntu8.3 July 2018 GRUB-RENDER-LABEL(1)
All times are GMT -4. The time now is 02:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy