Loading ...
Sorry, an error occurred while loading the content.
 

[PBML] simple perl giving big headache!

Expand Messages
  • Maisha Walker
    i am having what seems to me a very strange problem with a very simple perl script. im just trying to get 2 name=value pairs into a hash called %crumbs, then
    Message 1 of 3 , Dec 16, 1999
      i am having what seems to me a very strange problem with a very simple perl
      script.

      im just trying to get 2 name=value pairs into a hash called %crumbs, then
      assign the keys to variables and use the variables to print the values.
      pretty basic right? ive done it a hundred times.

      password=test1
      secondpassword=test2

      THIS time however, it seems that only the FIRST name & value pair gets
      recognized when i try to call the value using the name.

      so i have:

      if ($ENV{'HTTP_COOKIE'}) {
      @cookies=split(/;/,$ENV{'HTTP_COOKIE'});

      foreach $cookie (@cookies) {
      ($name, $value) = split (/=/,$cookie);
      $crumbs{$name}=$value;
      } #end of foreach loop


      this works fine - printing my two pairs:
      foreach $key (keys %crumbs) { print $key; print " "; print $crumbs{"$key"};
      print "<BR>"; }


      but then this works, printing the value test1:
      print $password;


      and this prints a blank space:
      print $secondpassword


      in addition, this works, printing the sentence:
      if (exists $crumbs{'password'}) {
      print "the secondpassword key exists";
      }


      while this returns nothing:
      if (exists $crumbs{'secondpassword'}) {
      print "the secondpassword key exists";
      }



      can anyone find what i am missing here?

      - befuddled
    • Jeff Boes
      ... Maybe I m missing something, but I don t see how the variable $secondpassword gets set by this code. You set $crumbs{ secondpassword }, and you set $key
      Message 2 of 3 , Dec 16, 1999
        > -----Original Message-----
        > From: Maisha Walker [mailto:maisha@...]
        > Sent: Thursday, December 16, 1999 11:53 AM
        > To: perl
        > Subject: [PBML] simple perl giving big headache!
        >
        >
        > i am having what seems to me a very strange problem with a very
        > simple perl
        > script.
        >
        > im just trying to get 2 name=value pairs into a hash called %crumbs, then
        > assign the keys to variables and use the variables to print the values.
        > pretty basic right? ive done it a hundred times.
        >
        > password=test1
        > secondpassword=test2
        >
        > THIS time however, it seems that only the FIRST name & value pair gets
        > recognized when i try to call the value using the name.
        >
        > so i have:
        >
        > if ($ENV{'HTTP_COOKIE'}) {
        > @cookies=split(/;/,$ENV{'HTTP_COOKIE'});
        >
        > foreach $cookie (@cookies) {
        > ($name, $value) = split (/=/,$cookie);
        > $crumbs{$name}=$value;
        > } #end of foreach loop
        >
        >
        > this works fine - printing my two pairs:
        > foreach $key (keys %crumbs) { print $key; print " "; print
        > $crumbs{"$key"};
        > print "<BR>"; }
        >
        >
        > but then this works, printing the value test1:
        > print $password;
        >
        >
        > and this prints a blank space:
        > print $secondpassword


        Maybe I'm missing something, but I don't see how the variable
        '$secondpassword' gets set by this code. You set $crumbs{'secondpassword'},
        and you set $key = 'secondpassword', but not the variable of that name.


        ----
        ~~~~~~~~~~~~~~~~|Glory to God in the highest; and on
        Jeffery Boes |earth peace, good will toward men.
        jboes@... |Merry Christmas, everyone!
      • Maisha Walker
        sorry here is the full script . . . ... print Content-type: text/html n n ; if ($ENV{ HTTP_COOKIE }) { @cookies=split(/;/,$ENV{ HTTP_COOKIE }); foreach
        Message 3 of 3 , Dec 16, 1999
          sorry here is the full script . . .
          ----------------------

          print "Content-type: text/html\n\n";

          if ($ENV{'HTTP_COOKIE'}) {
          @cookies=split(/;/,$ENV{'HTTP_COOKIE'});


          foreach $cookie (@cookies) {
          ($name, $value) = split (/=/,$cookie);
          $crumbs{$name}=$value;
          } #end of foreach loop


          foreach $key (keys %crumbs) { print $key; print " "; print $crumbs{"$key"};
          print "<BR>"; }
          foreach $key (keys %crumbs) { $$key=$crumbs{"$key"}; }

          print "The cookie in your files says that your username is $password and
          your password is $secondpassword.<BR>";

          if (exists $crumbs{'secondpassword'}) {
          print "the secondpassword key exists";
          }
          }#end of if ENV
          ----------------------


          please note that even when i call $crumbs{'secondpassword'} directly, it
          prints nothing and the if exists statement comes back false. whereas when i
          call $crumbs{'password'} directly it prints the value and the if else
          statement comes back true

          thanks!

          maisha
          -----Original Message-----
          From: Jeff Boes <jboes@...>
          To: perl-beginner@... <perl-beginner@...>
          Date: Thursday, December 16, 1999 12:49 PM
          Subject: [PBML] Re: simple perl giving big headache!




          > -----Original Message-----
          > From: Maisha Walker [mailto:maisha@...]
          > Sent: Thursday, December 16, 1999 11:53 AM
          > To: perl
          > Subject: [PBML] simple perl giving big headache!
          >
          >
          > i am having what seems to me a very strange problem with a very
          > simple perl
          > script.
          >
          > im just trying to get 2 name=value pairs into a hash called %crumbs, then
          > assign the keys to variables and use the variables to print the values.
          > pretty basic right? ive done it a hundred times.
          >
          > password=test1
          > secondpassword=test2
          >
          > THIS time however, it seems that only the FIRST name & value pair gets
          > recognized when i try to call the value using the name.
          >
          > so i have:
          >
          > if ($ENV{'HTTP_COOKIE'}) {
          > @cookies=split(/;/,$ENV{'HTTP_COOKIE'});
          >
          > foreach $cookie (@cookies) {
          > ($name, $value) = split (/=/,$cookie);
          > $crumbs{$name}=$value;
          > } #end of foreach loop
          >
          >
          > this works fine - printing my two pairs:
          > foreach $key (keys %crumbs) { print $key; print " "; print
          > $crumbs{"$key"};
          > print "<BR>"; }
          >
          >
          > but then this works, printing the value test1:
          > print $password;
          >
          >
          > and this prints a blank space:
          > print $secondpassword


          Maybe I'm missing something, but I don't see how the variable
          '$secondpassword' gets set by this code. You set $crumbs{'secondpassword'},
          and you set $key = 'secondpassword', but not the variable of that name.


          ----
          ~~~~~~~~~~~~~~~~|Glory to God in the highest; and on
          Jeffery Boes |earth peace, good will toward men.
          jboes@... |Merry Christmas, everyone!


          ------------------------------------------------------------------------
          The only fruitcake at overstock.com is our manager.
          He’s giving away a $20 coupon, plus our everyday Free Shipping.
          Take advantage of the savings and selection now.
          http://clickhere.egroups.com/click/2134

          -- Create a poll/survey for your group!
          -- http://www.egroups.com/vote?listname=perl-beginner&m=1
        Your message has been successfully submitted and would be delivered to recipients shortly.