Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting a value

2 views
Skip to first unread message

Sakthi

unread,
Jul 24, 2009, 4:38:25 AM7/24/09
to
I am getting a string value from a function .A variable is exist by that
string value. Need to print the value using the second variable!
Example:

my $log_dir="hello";

my $name=function1(); // $name has value "log_dir"

I want the output as "hello" using the "name" variable. Is that possible?

TIA

Svel


Grant Taylor

unread,
Jul 25, 2009, 6:28:43 PM7/25/09
to
On 7/24/2009 3:38 AM, Sakthi wrote:
> I am getting a string value from a function .A variable is exist by
> that string value. Need to print the value using the second variable!
...

> I want the output as "hello" using the "name" variable. Is that
> possible?

Yes.

Below is a quick hack that I think does what you want to do.

--8<--8<--8<--8<--8<--
#! /usr/bin/perl -w
use strict;

my $log_dir="hello";

sub function1() {
return "$log_dir";
}

my $name = function1();
print "$name\n";
-->8-->8-->8-->8-->8--

Grant. . . .

André Pletschette

unread,
Apr 23, 2010, 2:22:04 AM4/23/10
to Sakthi
Hi,

you've tried those:

print $$name
print ${$name}

they should work both


On 7/24/2009 10:38 AM, Sakthi wrote:
> utput as "hello" u

0 new messages