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

Sessions?

Expand Messages
  • webmaster@va.cjb.net
    Hey guys-- I m a total beginner in Perl and was wondering how to implement a session (or a kind of). A friend told me that using cookies is a way. Does anyone
    Message 1 of 6 , Jan 30, 2001
    • 0 Attachment
      Hey guys--
      I'm a total beginner in Perl and was wondering how to implement a
      session (or a kind of). A friend told me that using cookies is a way.
      Does anyone know another way? How do you implement it? And last but
      none the least, does anyone know a good tutorial on Perl? (cookies,
      form collecting, etc. etc. etc.)?

      Thanks.
    • Franki
      Hi all, If you reference a bunch of variables with local inside a sub,,, Like so, sub display_small_cart_table { local($reason_to_display_cart) = @_;
      Message 2 of 6 , Jan 30, 2001
      • 0 Attachment
        Hi all,

        If you reference a bunch of variables with local inside a sub,,,

        Like so,
        sub display_small_cart_table
        {
        local($reason_to_display_cart) = @_;
        local(@cart_fields);
        local($cart_id_number);
        local($quantity);
        local($unformatted_subtotal);
        local($subtotal);
        local($unformatted_grand_total);

        some stuff done here..

        } #end of display_small_cart_table.



        Does that mean that they will only retain those values in that sub?

        Many thanks...



        Frank Hauptle
        http://www.gshop.com.au/
        franki@...

        -----Original Message-----
      • daymobrew@yahoo.com
        ... From what I know from reading perldoc, the answer is yes. Having said that, why not write a small script to prove it to yourself. Here is what I tried
        Message 3 of 6 , Jan 30, 2001
        • 0 Attachment
          > Does that mean that they will only retain those values in that sub?
          From what I know from reading perldoc, the answer is yes.

          Having said that, why not write a small script to prove it to
          yourself.

          Here is what I tried (without much luck - notes below code):
          my $Number;

          sub UsingLocal
          {
          local $main::Number = 0;

          $main::Number++;
          print "\$Number in UsingLocal() is: $main::Number\n";
          }

          $Number = 7;
          print "\$Number in main is: $Number\n";
          UsingLocal();
          print "\$Number after UsingLocal is: $Number\n";

          If I used "$Number" in the subroutine I got a compilation error:
          Can't localize lexical variable $Number
          The code above ($main::Number) works and displays (as I'd expect)
          $Number in main is: 7
          $Number in UsingLocal() is: 1
          $Number after UsingLocal is: 7

          What am I doing wrong here?
          Since the "local" variable is initialized to undef, I don't see the
          use in "local".

          --- In perl-beginner@y..., "Franki" <frankieh@v...> wrote:
          > Hi all,
          >
          > If you reference a bunch of variables with local inside a sub,,,
          >
          > Like so,
          > sub display_small_cart_table
          > {
          > local($reason_to_display_cart) = @_;
          > local(@cart_fields);
          > local($cart_id_number);
          > local($quantity);
          > local($unformatted_subtotal);
          > local($subtotal);
          > local($unformatted_grand_total);
          >
          > some stuff done here..
          >
          > } #end of display_small_cart_table.
          >
          >
          >
          > Does that mean that they will only retain those values in that sub?
          >
          > Many thanks...
          >
          >
          >
          > Frank Hauptle
          > http://www.gshop.com.au/
          > franki@g...
          >
          > -----Original Message-----
        • Franki
          I wasn t using it, I am working on someone else s script, And I am sooo young with sooo much to learn.... I just stuck a huge sub into something called Perl
          Message 4 of 6 , Jan 30, 2001
          • 0 Attachment
            I wasn't using it, I am working on someone else's script,

            And I am sooo young with sooo much to learn....

            I just stuck a huge sub into something called Perl Builder 2 and it debugged
            it without being able to run it... (it required variables that were defined
            outside the sub)

            And it worked brilliantly,,

            I am not good enough myself to not consider that brilliant.

            Frank Hauptle
            http://www.gshop.com.au/
            franki@...

            -----Original Message-----
            From: daymobrew@... [mailto:daymobrew@...]
            Sent: Wednesday, 31 January 2001 1:31 AM
            To: perl-beginner@yahoogroups.com
            Subject: [PBML] Re: local

            > Does that mean that they will only retain those values in that sub?
            >From what I know from reading perldoc, the answer is yes.

            Having said that, why not write a small script to prove it to
            yourself.

            Here is what I tried (without much luck - notes below code):
            my $Number;

            sub UsingLocal
            {
            local $main::Number = 0;

            $main::Number++;
            print "\$Number in UsingLocal() is: $main::Number\n";
            }

            $Number = 7;
            print "\$Number in main is: $Number\n";
            UsingLocal();
            print "\$Number after UsingLocal is: $Number\n";

            If I used "$Number" in the subroutine I got a compilation error:
            Can't localize lexical variable $Number
            The code above ($main::Number) works and displays (as I'd expect)
            $Number in main is: 7
            $Number in UsingLocal() is: 1
            $Number after UsingLocal is: 7

            What am I doing wrong here?
            Since the "local" variable is initialized to undef, I don't see the
            use in "local".

            --- In perl-beginner@y..., "Franki" <frankieh@v...> wrote:
            > Hi all,
            >
            > If you reference a bunch of variables with local inside a sub,,,
            >
            > Like so,
            > sub display_small_cart_table
            > {
            > local($reason_to_display_cart) = @_;
            > local(@cart_fields);
            > local($cart_id_number);
            > local($quantity);
            > local($unformatted_subtotal);
            > local($subtotal);
            > local($unformatted_grand_total);
            >
            > some stuff done here..
            >
            > } #end of display_small_cart_table.
            >
            >
            >
            > Does that mean that they will only retain those values in that sub?
            >
            > Many thanks...
            >
            >
            >
            > Frank Hauptle
            > http://www.gshop.com.au/
            > franki@g...
            >
            > -----Original Message-----
          • Charles K. Clarkson
            ... From: ... local is used to localize a global variable. A variable declared with my is not global. Another way to write this is:
            Message 5 of 6 , Jan 30, 2001
            • 0 Attachment
              ----- Original Message -----
              From: <daymobrew@...>
              > Here is what I tried (without much luck - notes below code):
              > my $Number;
              >
              > sub UsingLocal
              > {
              > local $main::Number = 0;
              >
              > $main::Number++;
              > print "\$Number in UsingLocal() is: $main::Number\n";
              > }
              >
              > $Number = 7;
              > print "\$Number in main is: $Number\n";
              > UsingLocal();
              > print "\$Number after UsingLocal is: $Number\n";
              >
              > If I used "$Number" in the subroutine I got a compilation error:
              > Can't localize lexical variable $Number
              > The code above ($main::Number) works and displays (as I'd expect)
              > $Number in main is: 7
              > $Number in UsingLocal() is: 1
              > $Number after UsingLocal is: 7
              >
              > What am I doing wrong here?

              'local' is used to localize a global variable. A variable
              declared with 'my' is not global. Another way to write
              this is:

              $Number = 7;
              print "\$Number in main is: $Number\n";
              UsingLocal();
              print "\$Number after UsingLocal is: $Number\n";

              sub UsingLocal {
              local $Number = 0;
              $Number++;
              print "\$Number in UsingLocal() is: $Number\n";
              }

              Note that $Number is not declared with 'my'. Of course
              this means you can't 'use strict vars'.

              > Since the "local" variable is initialized to undef, I don't
              > see the use in "local".

              Since 'local' works on global variables, it is useful for
              preserving the value of a builtin perl variable. (Like $_)

              my $temp = $_;
              ( do some stuff to $_ )
              $_ = $temp;

              can be replaced by:
              {
              local $_;
              ( do some stuff to $_ )
              }

              When perl sees 'local $_' it saves a copy of '$_' and
              and retores it after '}'. This also avoids the overhead
              of declaring the variable '$temp'.


              HTH,
              Charles K. Clarkson
            • Kai Hintze
              ... From: Franki To: Date: Wed, 31 Jan 2001 01:41:43 +0800 Subject: RE: [PBML] Re: local ... That is
              Message 6 of 6 , Feb 2, 2001
              • 0 Attachment
                -----Original Message-----
                From: "Franki" <frankieh@...>
                To: <perl-beginner@yahoogroups.com>
                Date: Wed, 31 Jan 2001 01:41:43 +0800
                Subject: RE: [PBML] Re: local

                > I wasn't using it, I am working on someone else's script,
                >

                That is what test scripts are for. I keep a template script
                t.pl that has the bare bones for me to create a test script
                quickly:

                #!/usr/local/bin/perl -w

                $a = &ts();
                print $a, "\n";

                # -- subs --

                sub ts {
                my($b) = @_;
                1;
                }

                --- end script ---

                I just copy it to another name and put some real code in for
                the place holders.
              Your message has been successfully submitted and would be delivered to recipients shortly.