Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RE does not work with variables 1

Status
Not open for further replies.

rozecm

Programmer
Joined
May 21, 2007
Messages
7
Location
DE
Hello,
can someone help, RE does not work if I take string from shell command, last version is storing to the arrays, but still does not work.
If you will put directly $userid="uid=100(oracle)" and $homeowner="oracle" it works !!! Where is the error, please.

execution:
$ ./test.pl

your id output: uid=100(oracle)

owner of the directory: oracle

Test 3.1.1.1 failed

source code:
$cat ./test.pl
#!/usr/bin/perl
$awkcmd = "/usr/bin/awk";

@user = `id | $awkcmd '{ print \$1}'`;
@info = `ls -l $ENV{'ORACLE_HOME'} | grep bin | $awkcmd '{ print \$3}'`;

$userid=$user[0];
$homeowner=$info[0];

if ($userid =~ /${homeowner}/) {
print "your id output: ".$userid."\n";
print "owner of the directory: ".$homeowner."\n";
print "Test 3.1.1.1 successfull"."\n";
}
else{
print "your id output: ".$userid."\n";
print "owner of the directory: ".$homeowner."\n";
print "Test 3.1.1.1 failed"."\n";;
}
 
There's probably newlines at the end of all the elements of @user and @info.
 
This does not work as well, there is probably issue with converting to the string, I don't really know.:

#!/usr/bin/perl
$awkcmd = "/usr/bin/awk";
$user = `id | $awkcmd '{ print \$1}'`;
$info = `ls -l $ENV{'ORACLE_HOME'} | grep bin | $awkcmd '{ print \$3}'`;

if ($user =~ /${info}/g) {
print "your id output: ".$user."\n";
print "owner of the directory: ".$info."\n";
print "Test 3.1.1.1 successfull \n";
}
else{
print "your id output: ".$user."\n";
print "owner of the directory: ".$info."\n";
print "Test 3.1.1.1 failed \n";
}
 
What's contained in $user and $info after you've run the commands? It's pretty difficult to debug without knowing that. Can you show the output of your print statements?
 
Sorry, the output is same like in my first update

execution:
$ ./test.pl

your id output: uid=100(oracle)

owner of the directory: oracle

Test 3.1.1.1 failed

Details:

##############################################
### $user contains value "uid=100(oracle)" ###
print "your id output: ".$user."\n";

output from print command:
your id output: uid=100(oracle)

##############################################
### $info contains value "oracle" ###
print "owner of the directory: ".$info."\n";

output from print command:
owner of the directory: oracle
##############################################

Test 3.1.1.1 failed

BUT should not be, if I will put directly:
$user = "uid=100(oracle)";
$info = "oracle";
I will get : print "Test 3.1.1.1 successfull \n";

##################################################

Thanks for any idea, I did everything what I could imagine.

 
Thank you guys, the issue is solved.

Best Regards,
Martin Rozec.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top