user1718586
user1718586

Reputation: 57

How to resolve variables in Perl

I need help resolving the following variable ${$mapusers[$index]->[1]}

See below... It prints find. But when I do a system($query_user) the variable is empty.

my $query_user = 'adquery user -w ${$mapusers[$index]->[1]}';

Upvotes: 1

Views: 101

Answers (2)

Sinan Ünür
Sinan Ünür

Reputation: 118166

If you want to run the adquery command and store its output in $query_user, use backticks or qx:

my $query_user = `adquery user -w ${$mapusers[$index]->[1]}`;

Upvotes: 0

pts
pts

Reputation: 87401

Use " instead of ':

my $query_user = "adquery user -w ${$mapusers[$index]->[1]}";
system($query_user);

Or, if that one doesn't work, try this:

my $query_user = "adquery user -w " . $mapusers[$index]->[1];
system($query_user);

The first one should be used if $mapusers[$index]->[1] is a scalar reference, and the second one should be used if $mapusers[$index]->[1] isn't a reference.

If you want to capture the stdout of the command, use readpipe instead of system, or use the backtick operator.

Upvotes: 3

Related Questions