[23559] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 5767 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Nov 8 14:05:59 2003

Date: Sat, 8 Nov 2003 11:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 8 Nov 2003     Volume: 10 Number: 5767

Today's topics:
    Re: "pack" perldoc error? (J. Romano)
    Re: Checking environment variable existence <raisin@delete-this-trash.mts.net>
    Re: Checking environment variable existence <jwillmore@remove.adelphia.net>
    Re: count of 1s in a binary number <bik.mido@tiscalinet.it>
    Re: count of 1s in a binary number (Anno Siegel)
    Re: Logical Xor <pkent77tea@yahoo.com.tea>
    Re: math operations (J. Romano)
    Re: max of cardinality <raisin@delete-this-trash.mts.net>
    Re: max of cardinality <fJogham@yahoo.com>
    Re: max of cardinality <perl@my-header.org>
        ole, wmi, what the hell did I change? (woof)
    Re: Perl features <bik.mido@tiscalinet.it>
        problem using Mail::Audit::Attach under cygwin <mlwp@pacbell.net>
        Problem with CGI:Session <francofr@xxxtiscali.it>
    Re: Problem with CGI:Session <jwillmore@remove.adelphia.net>
    Re: Problem with CGI:Session <francofr@xxxtiscali.it>
    Re: subroutines return values (Tad McClellan)
    Re: subroutines return values <bmb@ginger.libs.uga.edu>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 8 Nov 2003 08:33:11 -0800
From: jl_post@hotmail.com (J. Romano)
Subject: Re: "pack" perldoc error?
Message-Id: <b893f5d4.0311080833.5f77fcf5@posting.google.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<bod6f1$n78$1@mamenchi.zrz.TU-Berlin.DE>...

> Yes, the equivalence seems to be restricted to the case where both
> formats are long enough to allow at least one trailing zero.  If it
> isn't, "Z" forces a null byte, but "a" doesn't.  This certainly
> deserves explicit mention, though it *is* described elsewhere in the
> doc.

   Thanks for your response, Anno.

   It looks like you're absolutely right about that...  If I had read
just one more paragraph, I would have seen the part where it mentions
that "Z" "...always packs a trailing null byte under all
circumstances."

   Oh, well... had I not asked the question, I may have been more
confused if I had read that paragraph after all (since the statements
appear to slightly contradict each other).

   So correct me if I'm wrong here:

   When I want to pack and unpack strings to/from a C structure that
requires that its strings be NULL-terminated, I should pack and unpack
with "Z".

   But when I want to pack and unpack strings to/from a record for use
with a Perl script (that doesn't require a NULL-terminator), I should
pack with "a" (to pad with null bytes) and unpack with "Z" (to strip
off trailing null bytes).  Although I unpack with "Z", packing with
"a" would allow me to make use of the extra character that would
otherwise get used as a null terminator.

   This will only work, of course, if I have no nulls in my string.

   -- J.


------------------------------

Date: Sat, 8 Nov 2003 08:20:41 -0600
From: Master Web Surfer <raisin@delete-this-trash.mts.net>
Subject: Re: Checking environment variable existence
Message-Id: <MPG.1a16b7b5609770899896c8@news.mts.net>

[This followup was posted to comp.lang.perl.misc]

In article <boggp9$q9$1@news.kodak.com>, victor.hannak@nospam.kodak.com 
says...
> Is there an >easy< way to tell if an environment variable exists without
> getting a "use of uninitialized variable" error in Perl?
> 
> I know I could probably cycle through the entire %ENV array and look for a
> match, but I was hoping there was a better way...


if ( exists $ENV{"name_of_var"} ) {
}


------------------------------

Date: Sat, 08 Nov 2003 16:46:36 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Checking environment variable existence
Message-Id: <20031108114624.3de95537.jwillmore@remove.adelphia.net>

On Fri, 7 Nov 2003 11:19:55 -0500
"Victor Hannak" <victor.hannak@nospam.kodak.com> wrote:

> Is there an >easy< way to tell if an environment variable exists
> without getting a "use of uninitialized variable" error in Perl?
> 
> I know I could probably cycle through the entire %ENV array and look
> for a match, but I was hoping there was a better way...

And checking for unset environmental variables, I'm thinking you were
going to need to set any unset values, right?

If so, then this little snipet might help as an example:
#no iteration through %ENV
$ENV{DISPLAY} = 'mydisplay:0.0' unless defined $ENV{DISPLAY};

In this example, you're setting $ENV{DISPLAY} to a value if the
DISPLAY environmental variable is not defined (meaning, it has no
value set).  This will work for other values as well.

Of course, you're post wnated to know how to find out if a
environmental variable existed *and* get rid of the "use of ..." error
message.  If you set an unset environmental variable, this will get
rid of the message.  But you need to know when this occurs (for
example - if the DISPLAY is always unset, then you know to check for
that and set as required and *not* mess with it if it is set).  And
you need to know what a sane value to set the unset environmental
variable to.  Just puting values in can be dangerious sometimes - at
the very least, break something that's working.  Setting the DISPLAY
to some improper value will cause the GUI apps to show up on someone
else's box somewhere else.  That's not only rude, but can cause
friction at work :-)

All of this makes the presumption that you're going the next step to
set an unset environmental variable.  Ignore this if that's not the
case.

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
Bugs, pl. n.:  Small living things that small living boys throw
on small living girls. 


------------------------------

Date: Sat, 08 Nov 2003 14:20:40 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: count of 1s in a binary number
Message-Id: <t1ipqv4bnva5u5nbubfa9mg1jdt01n9s11@4ax.com>

On Fri, 07 Nov 2003 18:36:24 +1100, Fred <fJogham@yahoo.com> wrote:

>the main issue is how to get the sub to deal with both data types and 
>give the expected results which is the count of "1" in the string or 
>array with out writeing 2 subs
>
>my $bit1 = "011001010";
>my @bit2 = qw /01 00 11 01 00/;

I know that this is not what you're asking, but is there any good
reason you use strings of chars v48.49 to represent your bit fields
instead of storing them into actual numbers? I'm not saying that there
is not, just asking!

OTOH Perl *does* support your choice by means of logical operators on
bitstrings, but unless you tell us what you *really* want to do, e.g.
reading huge amounts of binary data from file vs doing just a few
experiments on your own, one can't say what the best approach could
be.

If you choose to use numbers instead of bitstrings a less
Perl-specific way to count '1's is could be:

  sub size1 {
      # Recursive approach, terse and elegant IMHO.
      # An iterative one is OK as well.
      my $n=shift;
      return 0 unless $n;
      return ($n&1) + size1($n>>1);
  }
  
  sub size_many {
      return 0 unless @_;
      my $t;
      $t+=size1($_) for @_;
      $t;
  }

for just one number and for a list respectively.

But then I see you do *not* want to write two subs; personally I can't
see why: subs/functions/etc in *any* language are designed precisely
to factorize code. Anyway notice that this can be done, *even* with a
recursive approach quite similar to that of size1():

  sub size_many2 {
      return 0 unless @_;
      my $t;
      $t+=$_&1 for @_;
      $t+size_many2(grep $_, map $_>>1, @_);
  }

Said this, it is worth noticing that also in this case you can
painlessly use the approach suggested by other posters to do the
actual calculation:
  
  sub size {
      qq.@{[map sprintf('%b',$_),@_]}. =~ tr/1//;
  }
  
[I use qq.. rather than "" because of syntax highlighting reasons]


HTH,
Michele
-- 
# This prints: Just another Perl hacker,
seek DATA,15,0 and  print   q... <DATA>;
__END__


------------------------------

Date: 8 Nov 2003 17:26:21 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: count of 1s in a binary number
Message-Id: <boj8vt$iui$1@mamenchi.zrz.TU-Berlin.DE>

Michele Dondi  <bik.mido@tiscalinet.it> wrote in comp.lang.perl.misc:
> On Fri, 07 Nov 2003 18:36:24 +1100, Fred <fJogham@yahoo.com> wrote:
> 
> >the main issue is how to get the sub to deal with both data types and 
> >give the expected results which is the count of "1" in the string or 
> >array with out writeing 2 subs

[snip]

> If you choose to use numbers instead of bitstrings a less
> Perl-specific way to count '1's is could be:
> 
>   sub size1 {
>       # Recursive approach, terse and elegant IMHO.
>       # An iterative one is OK as well.
>       my $n=shift;
>       return 0 unless $n;
>       return ($n&1) + size1($n>>1);
>   }

That counts the bits of an n-bit number in n steps.  There is an old trick
in the dying art of bit-fiddling that allows to count them in as many steps
as there are one-bits.  That is a significant advantage if the numbers
involved are small (or sparse, bit-wise).

The trick is to isolate the least significant one-bit in a number
in one step.  This is essentially done by subtracting 1 from the number.
Beginning from the least significant bit, this builds a bridge of
one-bits until a one-bit is met in the original bit pattern. That one-bit
is set to zero, and the rest of the pattern is unchanged.

Comparing the bit patterns of the original and the decremented number from
the least significant side, we see that all bits are different up to,
and including, the first one-bit in the original number, and all bits are
the same in both from there onwards.  So, xor-ing both together, we arrive
at a mask that has one-bits up to, and including, the first one-bit in the
original, and zero-bits elsewhere.  The original number has exactly one
one-bit in the area of this mask: the least significant one-bit.  So
and-ing together the mask and the original number we arrive at the desired
isolated one-bit.  Another xor-operation sets this bit in the original to
zero, and we are ready to repeat the process.

While this certainly was lengthy to describe, in Perl terms the isolated
lowest one-bit of "$n" is "(($n - 1) ^ $n) & $n".  In particular, there
is no loop involved, the operation takes the same time whether there
are few or many initial zero-bits to bridge.

Putting it together:

    sub size2 {
        my $n = shift;
        my $size = $n ? 1 : 0;
        $size++ while $n ^= (($n - 1) ^ $n) & $n;
        $size;
    }

This is merely an algorithmic annotation which has nothing to do with
Perl.  Originally it was, of course, done in an assembler or another.
It's a cute little trick, and a pity there's no more use for it.  There
is nothing similar for the MSB, by the way.

To bring back some Perl content, the standard way of bit counting is
probably through pack and unpack.  Unpack does checksums, and the bit-count
can be seen as a checksum of a string of one bit data.  Since we are only
interested in the bit count, we don't have to worry about endian-ness --
any integer format can be used to pack the bit string.  So,

    sub size3 {
        my $x = shift;
        unpack '%32b*', pack 'I', $x;
    }

is more compact, and, presumably, faster, than the others.  No more
use for the bit-counting trick in Perl either.

Anno



------------------------------

Date: Sat, 08 Nov 2003 15:29:45 +0000
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: Logical Xor
Message-Id: <pkent77tea-631718.15294408112003@ptb-nnrpp01.plus.net>

[How do I XOR things in perl]

 ...the ^ operator is bitwise XOR:

$ perl
print 12 ^ 10;
print "\n";
__END__
6

P

-- 
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply


------------------------------

Date: 8 Nov 2003 09:40:18 -0800
From: jl_post@hotmail.com (J. Romano)
Subject: Re: math operations
Message-Id: <b893f5d4.0311080940.77cec85@posting.google.com>

Dear Fred,

   I've seen cases where users new to Perl (and in general to
programming) think that Perl has something to do exactly what they
want.  What they often don't understand is that Perl doesn't have a
built-in function of doing exactly what they want, but does have the
tools available for constructing the solution.  What is needed is a
little brain power, however.  When a well-thought-out solution is
used, Perl usually has no problem implementing it.

   So, let's take a look at some of the math operations you mentioned:

Fred <fJogham@yahoo.com> wrote in message news:<3FAAA5AB.5020307@yahoo.com>...

> I have many arrays with their elements being bits, e.g. "010000".
> I need to use bitwise operators ( and, or, xor ) to evaluate sections of 
> the arrays against each other as well as against other sections in the 
> same array.

   This is failry easy to do and understand:  all you do is create the
two lists (of ones and zeroes) and then traverse them, xor-ing their
values and placing them in a new list.  Here is an example program:

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

my @bigList = (0,0,1,1,0,0,1,0,1,0,1);

# First, extract the values that you want to use:
my @list1 = @bigList[0 .. 3];  # the first four elements
my @list2 = @bigList[-4 .. -1];  # the last four elements

# Then, make sure the list sizes are the same:
if (@list1 != @list2) {
   die "Unequal-sized lists!";
}

# Declare the list that will hold the answer:
my @list3;

for (my $i = 0; $i < @list1; $i++) {
   # xor the values (or use & for "and" or | for "or"):
   $list3[$i] = $list1[$i] ^ $list2[$i];
}

# Display the result:
print "\@list1:  @list1\n";
print "\@list2:  @list2\n";
print "\@list3:  @list3\n";
__END__

   This script will print the output:

@list1:  0 0 1 1
@list2:  0 1 0 1
@list3:  0 1 1 0


> some of the math functions I need to use are
> intersect
> element of
> summation
> and in the future, may be few more.

   Summation is not hard to do, either.  All you do is loop through
the values you want to sum up.  For example:

#!/usr/bin/perl -w

use strict;

my $firstIndex = 1;
my $lastIndex = 100;
my $sum = 0;

$sum += $_  for ($firstIndex .. $lastIndex);

print "The sum of the values from $firstIndex ",
      "to $lastIndex is $sum.\n";
__END__

   This prints:

The sum of the values from 1 to 100 is 5050.

   As for set theory, a common way of representing sets is through
hashes.  If you have the "Perl Cookbook", you can refer to recipes 4.7
and 4.8 for nice, concise examples.  If you don't have that book, let
me try explaining in my own words:

   You can create sets by declaring hashes, like this:

      my %firstSet = ();  # creates an empty set
      my %secondSet = ();  # creates another empty set

Suppose the firstSet contains the values "A", "B", 5, "car",
"airplane", and "broccoli" while se second set contains 3, "bird", and
"airplane".  You can write that like this:

      $firstSet{"A"}++;
      $firstSet{"B"}++;
      $firstSet{5}++;
      $firstSet{"car"}++;
      $firstSet{"airplane"}++;
      $firstSet{"broccoli"}++;

      $secondSet(3}++;
      $secondSet{"bird")++;
      $secondSet{"airplane"}++;

Once you have your sets populated, you can perform "element of" by
using "exists" on that set/element pair.  For example, if you want to
see if "car" is an element of a set, you can type:

      if ( exists($firstSet{"car"}) ) {
         print "\"car\" is an element of %firstSet.\n";
      } else {
         print "\"car\" is NOT an element of %firstSet.\n";
      }

For the intersection of the sets, you can loop through the keys of one
of the sets, and check to see if it exists in the other.  Whatever is
in common can be placed in a third set, whose keys will be the
intersection of the first and second sets:

      my %thirdSet = ();  # create an empty set

      foreach my $key (keys %firstSet) {
         if ( exists($secondSet{$key}) ) {
            $thirdSet{$key}++;
         }
      }

      print "Elements in common: ", keys %thirdSet, "\n";

   Keep in mind that there are many ways to do this in Perl (the way I
showed you is not the only way).  Plus, it's rumored that Perl 6 (the
next version of Perl) will have better ways to do set theory.  But
until Perl 6 comes out, you can use hashes for quick and efficient
representations of sets.

   Of course, if you are not familiar with Perl scalars, arrays, and
hashes, much of what I just said may not make sense.  I do not know
how familiar you are with Perl, since you did not say how familiar you
were.  If you have trouble understanding the Perl code I wrote, I
recommend that you consult a friend who is rather familiar with Perl
programming and who won't mind explaining to you what is happening in
the code.

   I hope this helps.

   Sincerely,

   Jean-Luc Romano


------------------------------

Date: Sat, 8 Nov 2003 08:26:44 -0600
From: Master Web Surfer <raisin@delete-this-trash.mts.net>
Subject: Re: max of cardinality
Message-Id: <MPG.1a16b91b958e88079896c9@news.mts.net>

[This followup was posted to comp.lang.perl.misc]

In article <3FACBCEF.1050206@yahoo.com>, fJogham@yahoo.com says...
> this code works good but I think I can be cleaner / faster.
> 
> thanks for all input
> 
> 
> my @bit1 = qw /01 00 10 11 00 11/;
> my @bit2 = qw /01 01 01 01 11/;
> print (max(\@bit1,\@bit2),"\n");
> 
> sub max {
>      my ($aref1, $aref2) = (shift, shift);
>      my $bit1 = card(@{$aref1});
>      my $bit2 = card(@{$aref2});
>      if ( $bit1 > $bit2 ) {
> 	return $bit1;
>      } elsif ( $bit1 > $bit2 ) {
> 	return $bit2;
>      } else {
> 	return $bit1; #both equal, return any
>      }
> }
> 
> sub card {
>      join("", @_) =~ tr/01//;
> }

Here is another possibility for finding the maximum of an array :

$maxlen = (sort { $b <=> $a } @data_values)[0];


------------------------------

Date: Sun, 09 Nov 2003 01:41:31 +1100
From: Fred <fJogham@yahoo.com>
Subject: Re: max of cardinality
Message-Id: <3FAD009B.6040903@yahoo.com>


> 
> 
> Here is another possibility for finding the maximum of an array :
> 
> $maxlen = (sort { $b <=> $a } @data_values)[0];

thanks.

and here is another

my @bit1 = qw /01 00 10 11 00 11/;
my @bit2 = qw /01 01 01 01 11/;
print (sort{ $b <=> $a } (
	   join("", @bit1) =~ tr/01//,
	   join("", @bit2) =~ tr/01//
	   )
        [0],"\n");



------------------------------

Date: Sat, 08 Nov 2003 16:10:26 +0100
From: Matija Papec <perl@my-header.org>
Subject: Re: max of cardinality
Message-Id: <8d0qqv0dtgmacgigtrdqqcu4oc814rt4b8@4ax.com>

X-Ftn-To: Fred 

Fred <fJogham@yahoo.com> wrote:
>this code works good but I think I can be cleaner / faster.
>
>thanks for all input
>
>
>my @bit1 = qw /01 00 10 11 00 11/;
>my @bit2 = qw /01 01 01 01 11/;
>print (max(\@bit1,\@bit2),"\n");

Generally you will want to avoid building small subs which are called with
larger arrays/lists as they slow you down, so card() is out,

sub max {
  my ($aref1, $aref2) = @_;
  local $" = '';
  my $b1 = "@$aref1" =~ tr/01//;
  my $b2 = "@$aref2" =~ tr/01//;

  return ($b1 > $b2) ? $b1 : $b2;
}


-- 
Matija


------------------------------

Date: 8 Nov 2003 07:34:27 -0800
From: drubnone@yahoo.com (woof)
Subject: ole, wmi, what the hell did I change?
Message-Id: <7b21a826.0311080734.7ce56709@posting.google.com>

Here's my very first stab at wmi.  What did I change?  I was trying 
to change SystemStartupDelay in Win32_ComputerSystem.Name=WX4
The wmi browser says I changed nothing.  If I run this and read
only, it says I did.... change something.  I get the "55".
Thanks.

use Win32::OLE;

$wmi = Win32::OLE->GetObject("winmgmts:{impersonationLevel=impersonate,
(security)}//./") || die;

($obj = $wmi->Get("Win32_ComputerSystem")) || die;

# commented out and run again to check for change.
#$obj->{"SystemStartupDelay"} = "55";
#$obj->Put_();

$s = $obj->{"SystemStartupDelay"};
print qq(Is the new value $s\n);


------------------------------

Date: Sat, 08 Nov 2003 14:20:39 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Perl features
Message-Id: <vihpqvkq3anva764nqe135o40dr708h9kh@4ax.com>

On Fri, 07 Nov 2003 01:37:17 -0500, Matt Oliverius
<moliverius@w-link.net> wrote:

>new applications.  Does any know of any major shortcomings of Python that 
>Perl can handle?  I really want to beat on this guy a little.

(1) perldoc -q python
(2) Last year Derek Thomson wrote a detailed article on this issue, in
the thread "Switching from Python to Perl", that you will certainly be
able to find with Google. I strongly recommend you to do so, because
it is quite informative.


Michele
-- 
# This prints: Just another Perl hacker,
seek DATA,15,0 and  print   q... <DATA>;
__END__


------------------------------

Date: Sat, 08 Nov 2003 15:03:16 GMT
From: "Mark Wood-Patrick" <mlwp@pacbell.net>
Subject: problem using Mail::Audit::Attach under cygwin
Message-Id: <UA7rb.25461$kH6.12876@newssvr27.news.prodigy.com>

I am getting the following error with Attach:

Can't locate auto/Mail/Audit/Attach/num_attachm.al in @INC (@INC contains:
/usr/
lib/perl5/5.6.1/cygwin-multi /usr/lib/perl5/5.6.1
/usr/lib/perl5/site_perl/5.6.1
/cygwin-multi /usr/lib/perl5/site_perl/5.6.1 /usr/lib/perl5/site_perl .) at
mail
 .pl line 22

Any ideas what I'm doing wrong? My program looks like

use Mail::POP3Client;
use Mail::Audit qw(Attach); # Mail::Audit::Attach

  $pop = new Mail::POP3Client( USER     => "mark_woodpatrick",
                               PASSWORD => "koolie_kat",
                               HOST     => "pop.pacbell.yahoo.com" );
  for( $i = 1; $i <= $pop->Count(); $i++ ) {
    foreach( $pop->Head( $i ) ) {
      my $mailHeader = $_;
      if ( /Subject: new pictures/ ) {
        my $fh;
        my @msg = $pop->HeadAndBody( $i );
        my $mail = Mail::Audit->new(emergency=>"~/emergency_mbox", data =>
\@msg);

        my $num_attachment = $mail->num_attachments;
        my $attachments = $mail->attachments;

        print $mailHeader, "\n";
        #print "XXXX ".$mail->from."num attachments:
".$mail->num_attachments."\n";
        print "XXXX "."num attachments: ".$mail->num_attachments()."\n";

        # remove_attachments(filename => "\.(exe|scr|pif)",
        # smaller_than => 20000);

        # $mail->remove_attachments(mime_type => "text/html");

        foreach (@$attachments) {
                # $_->save($attachdir)
            print "mime type: $_->mime_type\n";
            next;
            # if ($_->mime_type =~ |^image/|);
            # $_->remove ;
            # if ($_->filename =~ |\.(vcf)$|);
        }

        next;

        if ( open ($fh, ">msg_$i.txt")) {
            $pop->HeadAndBodyToFile( $fh, $i );
            close($fh);
        } else {
            print "can't save message $i\n";
        }
        }
    }
  }
  $pop->Close();




------------------------------

Date: Sat, 08 Nov 2003 14:54:29 GMT
From: Francesco <francofr@xxxtiscali.it>
Subject: Problem with CGI:Session
Message-Id: <pan.2003.11.08.15.00.23.318723@xxxtiscali.it>

Hi,

I'm in trouble with a CGI script : I use CGI:Session for the session
management, my problem is that sometimes the script lost the session ID
and so create a new session.
The problem occurs everytime I run the script from a computer behind a
proxy (the script is on a website) and occasionally when the pc is
connected directly to internet (or is inside the LAN of the webserver).

The script structure is quite simple, at top of the script I call
a sub for the session management, then I load a sub for the page 
requested.
The first page contains the login form (an hidden field contains the
session ID), then I create a frameset with 3 frames.

I print in each frame the session ID and is (sometimes/everytime)
different. 

I suppose that the problem is in the session management, this is my
routine :

sub session_manage {
 #my $sid = $CGI::Q->param('CGISESSID') || $CGI::Q->url_param('CGISESSID')
 	|| undef;
 my $sid = $CGI::Q->param('CGISESSID'); $session = new
 CGI::Session("driver:File",$sid, {Directory=>'/tmp'});
 $session->save_param( $CGI::Q);
 $session->expire(600);     # expire after 600 seconds $ParID =
 "?CGISESSID=".$session->id;	    
}

Is there something wrong ? 

Francesco
Freedev.it




------------------------------

Date: Sat, 08 Nov 2003 16:55:28 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Problem with CGI:Session
Message-Id: <20031108115519.31081bc9.jwillmore@remove.adelphia.net>

On Sat, 08 Nov 2003 14:54:29 GMT
Francesco <francofr@xxxtiscali.it> wrote:
<snip>
> I suppose that the problem is in the session management, this is my
> routine :
> 
> sub session_manage {
>  #my $sid = $CGI::Q->param('CGISESSID') ||
>  $CGI::Q->url_param('CGISESSID')
>  	|| undef;
>  my $sid = $CGI::Q->param('CGISESSID'); $session = new
>  CGI::Session("driver:File",$sid, {Directory=>'/tmp'});
>  $session->save_param( $CGI::Q);
>  $session->expire(600);     # expire after 600 seconds $ParID =
>  "?CGISESSID=".$session->id;	    
> }
> 
> Is there something wrong ? 

This may be an odd question, but do you recycle the web server when
this happens?  I ask because you're using the '/tmp' directory to
store the sessions.  When I recycle my box (running SuSE Linux), I
have it set to clean the '/tmp' directory on a recycle.  At work
(running RedHat Linux - notice a theme here :-) ), I use an
application to clear the '/tmp' directory every 6 hours.  I'm
wondering if this type of situation is happening there.

So, if this is the case, change where you store the sessions.  This
may prevent the removal of session information when you don't want the
information removed.  If possible, you could store the information in
a database (such as MySQL).  The module in question has documentation
to walk you through this.  That way, you're storing the important
session information in something that, hopfully, doesn't get cleared
out every so often.

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
Stult's Report:  Our problems are mostly behind us.  What we have
to do now is fight the solutions. 


------------------------------

Date: Sat, 08 Nov 2003 18:15:47 GMT
From: Francesco <francofr@xxxtiscali.it>
Subject: Re: Problem with CGI:Session
Message-Id: <pan.2003.11.08.18.21.41.467183@xxxtiscali.it>

Il Sat, 08 Nov 2003 16:55:28 +0000, James Willmore ha scritto:


> This may be an odd question, but do you recycle the web server when
> this happens?  I ask because you're using the '/tmp' directory to
> store the sessions.  When I recycle my box (running SuSE Linux), I
> have it set to clean the '/tmp' directory on a recycle.  At work
> (running RedHat Linux - notice a theme here :-) ), I use an
> application to clear the '/tmp' directory every 6 hours.  I'm
> wondering if this type of situation is happening there.

The sript run on a test server, I clean the '/tmp' manually :)

I have more session file than I desire...

Francesco
Freedev.it


------------------------------

Date: Sat, 8 Nov 2003 07:46:52 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: subroutines return values
Message-Id: <slrnbqpsuc.ale.tadmc@magna.augustmail.com>

Steve Grazzini <grazz@pobox.com> wrote:
> Brad Baxter <bmb@ginger.libs.uga.edu> wrote:

>> I ask only to get an idea of what might happen if the value of
>> $right we very large.  I.e., would there not only be a copy of
>> this hypothetical large value in $right and $left, but also in
>> this "holding area" (which I'm not sure actually exists).
> 
> But this won't happen.  Perl checks for that (very common) case
> in order to avoid copying the temporary string.


And what the OP calls the "holding area" is most usually
called "the stack".


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Sat, 8 Nov 2003 11:37:55 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: subroutines return values
Message-Id: <Pine.A41.4.58.0311081111360.16444@ginger.libs.uga.edu>

On Sat, 8 Nov 2003, LaDainian Tomlinson wrote:

> "Brad Baxter" wrote:
> > I ask only to get an idea of what might happen if the value of $right we
> > very large.  I.e., would there not only be a copy of this hypothetical
> > large value in $right and $left, but also in this "holding area" (which
> > I'm not sure actually exists).
>
> <snip text>
>
> When you say '$left = $right;', you're telling the compiler 'look in the
> address on the stack (or wherever) pointed to by $right, take that value,
> and stick it in the spot on the stack (or wherever) pointed to by $left'.
> The exact way that you 'stick it' varies depending on the data type:
> sometimes a copy of the data is made, sometimes you get a reference to the
> original data.
>
> <...> So your 'holding area' doesn't exist as you mean it, but
> there is a short time period where $left does not necessarily contain the
> value returned by right() (a few clock cycles at most).  After that, the
> memory that was occupied by right() is available for allocation again, and
> so the slot for the return value is garbage.
>
> I hope this clears things up a little, since it's awfully long-winded.

Yes, thanks to all for the answers.  I conclude that I can likely not
worry about the details and trust perl (the program) to do the right/best
thing in a situation like this.

What prompted this was my desire to make access methods for a class as
efficient as possible.  For instance, if I know an object's attribute is
very large, I might choose to return a reference to it instead of
returning it's value.  I think now it's probably a bad idea in general,
and the instances where this will happen rare.

Regards,

Brad


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 5767
***************************************


home help back first fref pref prev next nref lref last post