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
shift(1)							   User Commands							  shift(1)

NAME
shift - shell built-in function to traverse either a shell's argument list or a list of field-separated words SYNOPSIS
sh shift [n] csh shift [variable] ksh * shift [n] DESCRIPTION
sh The positional parameters from $n+1 ... are renamed $1 ... . If n is not given, it is assumed to be 1. csh The components of argv, or variable, if supplied, are shifted to the left, discarding the first component. It is an error for the variable not to be set or to have a null value. ksh The positional parameters from $n+1 $n+1 ... are renamed $1 ..., default n is 1. The parameter n can be any arithmetic expression that evaluates to a non-negative number less than or equal to $#. On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a vari- able assignment. This means that tilde substitution is performed after the = sign and word splitting and file name generation are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), ksh(1), sh(1), attributes(5) SunOS 5.10 15 Apr 1994 shift(1)
All times are GMT -4. The time now is 01:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy