Assign value to variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike

    Assign value to variable

    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=20041 008153445Z
    logindisabled=F ALSE

    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.
  • Tim Van Wassenhove

    #2
    Re: Assign value to variable

    In article <d3354680.04100 80907.4c50e18b@ posting.google. com>, Mike wrote:[color=blue]
    > 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=20041 008153445Z
    > logindisabled=F ALSE
    >
    > 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.[/color]

    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>

    Comment

    • Tim Van Wassenhove

      #3
      Re: Assign value to variable

      In article <2so03gF1nbi1qU 1@uni-berlin.de>, Tim Van Wassenhove wrote:[color=blue]
      > In article <d3354680.04100 80907.4c50e18b@ posting.google. com>, Mike wrote:[color=green]
      >> 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=20041 008153445Z
      >> logindisabled=F ALSE
      >>
      >> 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.[/color]
      >
      > The output looks like what i see in a ini file, so you could consider
      > using ini_get?[/color]

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

      --
      Met vriendelijke groeten,
      Tim Van Wassenhove <http://www.timvw.info>

      Comment

      • Geoff Berrow

        #4
        Re: Assign value to variable

        I noticed that Message-ID:
        <d3354680.04100 80907.4c50e18b@ posting.google. com> from Mike contained
        the following:
        [color=blue]
        >ie. somefunc("sn", "Shore")
        >
        >Would create the variable $sn and assign the value "Shore" to it.[/color]

        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/

        Comment

        • Mike

          #5
          Re: Assign value to variable

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

          Geoff Berrow <blthecat@ckdog .co.uk> wrote in message news:<qhcem098n p84rd76og0e2ngk qv9ro3u92c@4ax. com>...[color=blue]
          > I noticed that Message-ID:
          > <d3354680.04100 80907.4c50e18b@ posting.google. com> from Mike contained
          > the following:
          >[color=green]
          > >ie. somefunc("sn", "Shore")
          > >
          > >Would create the variable $sn and assign the value "Shore" to it.[/color]
          >
          > function somefunc($var,$ value){
          > global $$var;
          > $$var=$value;
          > }
          > somefunc("sn", "Shore");
          > print $sn;[/color]

          Comment

          • Geoff Berrow

            #6
            Re: Assign value to variable

            I noticed that Message-ID:
            <d3354680.04102 61044.11722022@ posting.google. com> from Mike contained
            the following:
            [color=blue]
            >Works like a charm. It was that double $$ that I could not wrap my
            >head around. Thanks very much![/color]

            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/

            Comment

            • Mike

              #7
              Re: Assign value to variable

              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 <blthecat@ckdog .co.uk> wrote in message news:<hsj7o0l89 39v88l7ma8geuoc ga2u2dnsa8@4ax. com>...[color=blue]
              > I noticed that Message-ID:
              > <d3354680.04102 61044.11722022@ posting.google. com> from Mike contained
              > the following:
              >[color=green]
              > >Works like a charm. It was that double $$ that I could not wrap my
              > >head around. Thanks very much![/color]
              >
              > Ah, variable variables. Yep they are fun. :-)[/color]

              Comment

              • Geoff Berrow

                #8
                Re: Assign value to variable

                I noticed that Message-ID:
                <d3354680.04110 11820.5eda5ad9@ posting.google. com> from Mike contained
                the following:
                [color=blue]
                >I need to convert a Perl LDAP query result to an array[/color]

                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/

                Comment

                • Mike

                  #9
                  Re: Assign value to variable

                  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 <blthecat@ckdog .co.uk> wrote in message news:<i7ceo09do 96ae26qb7ec6baj 8aurgoq5pp@4ax. com>...[color=blue]
                  > I noticed that Message-ID:
                  > <d3354680.04110 11820.5eda5ad9@ posting.google. com> from Mike contained
                  > the following:
                  >[color=green]
                  > >I need to convert a Perl LDAP query result to an array[/color]
                  >
                  > I don't suppose you could use the PHP LDAP functions and save some
                  > bother?[/color]

                  Comment

                  • Geoff Berrow

                    #10
                    Re: Assign value to variable

                    I noticed that Message-ID:
                    <d3354680.04110 21544.72504d97@ posting.google. com> from Mike contained
                    the following:
                    [color=blue]
                    >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 ***[/color]

                    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/

                    Comment

                    Working...