CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Getting variable from table and passing it to new script.

 



krixham
New User

Oct 12, 2015, 12:09 PM

Post #1 of 5 (1021 views)
Getting variable from table and passing it to new script. Can't Post

My issue is that in this table some of the variables will have spaces or parens in the name. That is not passing very well to the next script.

This is in the first script.

Code
       $projName = $jobFields[7]; 
if ($inVal eq "X" || $inVal eq "x") {
system("/data1/Scripts/KMRpoc_cleanfiles/ModifiedKMRpoc_cleanfiles99FRANK.pl $custDir $projName $logFile");
&do_exit($projName);


This is in the second script:

Code
my $customerCodes = $ARGV[0]; 
chomp($whoAmi = `/usr/xpg4/bin/id -un`);
$userID = `getent passwd $whoAmi | cut -d':' -f5`;
my $projName = $ARGV[1];
my $logFile = $ARGV[2];


I won't know in the script when there are spaces and when there are not. If there is only one word it works great. But when I run this now I am getting "sh: syntax error at line 1: `(' unexpected". The field does have parens in it.


FishMonger
Veteran / Moderator

Oct 12, 2015, 3:48 PM

Post #2 of 5 (1013 views)
Re: [krixham] Getting variable from table and passing it to new script. [In reply to] Can't Post

Have you tried putting quotes around the var?


krixham
New User

Oct 13, 2015, 4:39 AM

Post #3 of 5 (993 views)
Re: [FishMonger] Getting variable from table and passing it to new script. [In reply to] Can't Post

I've tried several things.


Code
		 
$projName = $jobFields[7];
if ($inVal eq "X" || $inVal eq "x") {
system("/data1/Scripts/KMRpoc_cleanfiles/ModifiedKMRpoc_cleanfiles99FRANK.pl $custDir $projName $logFile");
&do_exit($projName);


I have tried $projName = "$jobFields[7]"; and ($projName = $jobFields[7];) and also "$projName" and ($projName)

This is in the second script:

Code
my $customerCodes = $ARGV[0];  
chomp($whoAmi = `/usr/xpg4/bin/id -un`);
$userID = `getent passwd $whoAmi | cut -d':' -f5`;
my $projName = $ARGV[1];
my $logFile = $ARGV[2];


I have tried "$ARGV[0]", "$ARGV[1]", "$ARGV[2];"


(This post was edited by krixham on Oct 13, 2015, 4:42 AM)


FishMonger
Veteran / Moderator

Oct 13, 2015, 6:27 AM

Post #4 of 5 (988 views)
Re: [krixham] Getting variable from table and passing it to new script. [In reply to] Can't Post

No, that's not what I meant.

You need to put the quotes around the vars in the system call, not the var assignments.

Code
system("/data1/Scripts/KMRpoc_cleanfiles/ModifiedKMRpoc_cleanfiles99FRANK.pl '$custDir' '$projName' '$logFile'");

You may not need to put quotes around all 3 of those vars. They just need to be around the ones that have the problem characters i.e., the spaces.


(This post was edited by FishMonger on Oct 13, 2015, 7:06 AM)


krixham
New User

Oct 13, 2015, 7:41 AM

Post #5 of 5 (982 views)
Re: [FishMonger] Getting variable from table and passing it to new script. [In reply to] Can't Post

Worked like a charm, FishMonger. Thanks for all your help.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives