By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,695 Members | 1,338 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,695 IT Pros & Developers. It's quick & easy.

Assign value to variable

P: n/a
Is there any way I can use a function to create a variable and assign
a value to it? I have a Perl script that returns some LDAP
information:

sn=Shore
givenname=Mike
logintime=20041008153445Z
logindisabled=FALSE

Instead of parsing this text and assigning the values, I was wondering
if a function exists where I can pass a variable name and a value, and
the variable would be created.

ie. somefunc("sn", "Shore")

Would create the variable $sn and assign the value "Shore" to it.
Jul 17 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
In article <d3**************************@posting.google.com >, Mike wrote:
Is there any way I can use a function to create a variable and assign
a value to it? I have a Perl script that returns some LDAP
information:

sn=Shore
givenname=Mike
logintime=20041008153445Z
logindisabled=FALSE

Instead of parsing this text and assigning the values, I was wondering
if a function exists where I can pass a variable name and a value, and
the variable would be created.


The output looks like what i see in a ini file, so you could consider
using ini_get?
--
Met vriendelijke groeten,
Tim Van Wassenhove <http://www.timvw.info>
Jul 17 '05 #2

P: n/a
In article <2s*************@uni-berlin.de>, Tim Van Wassenhove wrote:
In article <d3**************************@posting.google.com >, Mike wrote:
Is there any way I can use a function to create a variable and assign
a value to it? I have a Perl script that returns some LDAP
information:

sn=Shore
givenname=Mike
logintime=20041008153445Z
logindisabled=FALSE

Instead of parsing this text and assigning the values, I was wondering
if a function exists where I can pass a variable name and a value, and
the variable would be created.


The output looks like what i see in a ini file, so you could consider
using ini_get?


I meant http://www.php.net/parse_ini_file

--
Met vriendelijke groeten,
Tim Van Wassenhove <http://www.timvw.info>
Jul 17 '05 #3

P: n/a
I noticed that Message-ID:
<d3**************************@posting.google.com > from Mike contained
the following:
ie. somefunc("sn", "Shore")

Would create the variable $sn and assign the value "Shore" to it.


function somefunc($var,$value){
global $$var;
$$var=$value;
}
somefunc("sn", "Shore");
print $sn;

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #4

P: n/a
Works like a charm. It was that double $$ that I could not wrap my
head around. Thanks very much!

Geoff Berrow <bl******@ckdog.co.uk> wrote in message news:<qh********************************@4ax.com>. ..
I noticed that Message-ID:
<d3**************************@posting.google.com > from Mike contained
the following:
ie. somefunc("sn", "Shore")

Would create the variable $sn and assign the value "Shore" to it.


function somefunc($var,$value){
global $$var;
$$var=$value;
}
somefunc("sn", "Shore");
print $sn;

Jul 17 '05 #5

P: n/a
I noticed that Message-ID:
<d3**************************@posting.google.com > from Mike contained
the following:
Works like a charm. It was that double $$ that I could not wrap my
head around. Thanks very much!


Ah, variable variables. Yep they are fun. :-)
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #6

P: n/a
Okay all you gurus, here is my next challenge :-)

I need to convert a Perl LDAP query result to an array. So far I have
been able to create an variable name; for example
$name = "ret[8]['givenname'][0]";
$value = "Mike"

What I want to do now is assign the $value to the $name, as in

$$name = $value;

but that does not work. I need the end result to be:
$ret[8]['givenname'][0] = "Mike";

Geoff Berrow <bl******@ckdog.co.uk> wrote in message news:<hs********************************@4ax.com>. ..
I noticed that Message-ID:
<d3**************************@posting.google.com > from Mike contained
the following:
Works like a charm. It was that double $$ that I could not wrap my
head around. Thanks very much!


Ah, variable variables. Yep they are fun. :-)

Jul 17 '05 #7

P: n/a
I noticed that Message-ID:
<d3**************************@posting.google.com > from Mike contained
the following:
I need to convert a Perl LDAP query result to an array


I don't suppose you could use the PHP LDAP functions and save some
bother?

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #8

P: n/a
Hi Geoff,

I originally had everything written in PHP and it worked fine on my
own test server, but then I tried it on the "official" test server it
would not work.

From what I have been told by our server guys, our Solaris server
comes with a built in LDAP module for Netscape directories, and does
not support PHP's LDAP module. So I needed to rewrite all my LDAP code
in Perl, which *is* supported by the Solaris server, and then call the
Perl code from LDAP, then parse the results back in PHP. *** sigh ***

Geoff Berrow <bl******@ckdog.co.uk> wrote in message news:<i7********************************@4ax.com>. ..
I noticed that Message-ID:
<d3**************************@posting.google.com > from Mike contained
the following:
I need to convert a Perl LDAP query result to an array


I don't suppose you could use the PHP LDAP functions and save some
bother?

Jul 17 '05 #9

P: n/a
I noticed that Message-ID:
<d3**************************@posting.google.com > from Mike contained
the following:
From what I have been told by our server guys, our Solaris server
comes with a built in LDAP module for Netscape directories, and does
not support PHP's LDAP module. So I needed to rewrite all my LDAP code
in Perl, which *is* supported by the Solaris server, and then call the
Perl code from LDAP, then parse the results back in PHP. *** sigh ***


Just an idea because I don't know much about Perl. I do know Perl
scripts echo html so why can't a perl script echo php? If this was
then saved as a file it could be simply included in any php script you
want.

Apologies if I am wildly wrong here.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.