[19940] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2135 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 14 21:05:47 2001

Date: Wed, 14 Nov 2001 18:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1005789906-v10-i2135@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 14 Nov 2001     Volume: 10 Number: 2135

Today's topics:
    Re: Bandwidth meter in cgi/perl? <godzilla@stomp.stomp.tokyo>
    Re: Bandwidth meter in cgi/perl? <godzilla@stomp.stomp.tokyo>
    Re: Can not create new HTML page with cgi.pm (David Efflandt)
        DBI changing from CSV to mySQL probs <mikecook@cigarpool.com>
    Re: DBI changing from CSV to mySQL probs <mbudash@sonic.net>
    Re: DBI changing from CSV to mySQL probs <patrickolson@qwest.net>
    Re: dhcpdiscover <goldbb2@earthlink.net>
    Re: IBM AS/400 data queue access <dfosdike@nospam.elders.com.au>
    Re: Parsing speed (John Kenyon)
    Re: playing WAV file on unix and windows? <goldbb2@earthlink.net>
    Re: ranged arrays (Mark Jason Dominus)
    Re: ranged arrays (Logan Shaw)
    Re: setuid cgi? (David Efflandt)
        shift operator / large numbers <jens@irs-net.com>
    Re: shift operator / large numbers <krahnj@acm.org>
    Re: Trees, Memory mgt and GC in perl 5.005_3 (Logan Shaw)
    Re: using modules in subdirectories with a dash <goldbb2@earthlink.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 14 Nov 2001 15:37:09 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Bandwidth meter in cgi/perl?
Message-Id: <3BF30025.F33AD683@stomp.stomp.tokyo>

bozko wrote:

(snipped)
 
> I need to implement a bandwidth meter using cgi/perl

> Has anyone seen this done in perl before?

No.


> Can it be done?

Yes.


> Are there examples posted anywhere?
 
Yes, below my signature.

This toy script beneath my signature is something
I tinker with while suffering rainy day terminal
boredom. It is a toy only. Nonetheless, this script
does present the logic behind a Perl bandwidth meter.
I am not sure if Time High Resolution can be applied
to this toy; Time HR is not ported for my Win32 box.

Resolution is only one second and this toy does not
compensate for hour rollover during use. There is 
enough logic presented, however, you can easily
add in needed math to compensate for an hour change.

You will note a temporary file is written and deleted.
This is an alert you may need write permissions and
disk space will be used for a short period of time.
Currently, this script will write a temporary file
to the directory containing your script.

There is a sleep test harness if you want to try this
on your local machine and have a need to slow things
down to observe how it works.

If you want kilobytes instead of bytes, well, if you
cannot figure out how to do this I would suggest you
are in over your head.

An html form action interface would be very easy to add.
I would not use cgi.pm for your interface. Use of Stein's
module will make your script run extremely slow; an average
fifteen times slower than a custom read and parse routine.

You may run this script via a browser.


Godzilla!
--

#!perl

use LWP::Simple;

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

$start_minute = substr (localtime, -10, 2);
$start_second = substr (localtime, -7, 2);

# Insert site to fetch next line:

$fetch_file = get ("http://localhost/~test/godzilla.exe");

# sleep (2);  ## Test Rig For Fast Local Machine Server

if ($fetch_file)
 {
  $stop_minute = substr (localtime, -10, 2);
  $stop_second = substr (localtime, -7, 2);
 }
else
 { print "Failed To Connect"; exit; }

if ($start_minute < $stop_minute)
 {
  $second_multiplier = ($stop_minute - $start_minute) * 60;
  $elapse_time = ($stop_second + $second_multiplier) - $start_second;
 }
else
 { $elapse_time = $stop_second - $start_second; }

open (FILE_STAT, ">temp.txt");
print FILE_STAT $fetch_file;
close (FILE_STAT);

$file_size = (stat ("temp.txt")) [7];

unlink ("temp.txt");

print "Elapse Time: $elapse_time\n\n";
print "File Size: $file_size\n\n";

if ($elapse_time > 0)
 { 
  $bandwidth = $file_size / $elapse_time;
  print "Bandwidth Is $bandwidth Bytes Per Second";
 }
else
 { 
  print "Elapse Time Is Less Than One Second.\n\n",
        "  Bandwidth Exceeds $file_size Bytes Per Second";
 }

exit;


PRINTED RESULTS WITH TEST HARNESS:
__________________________________

Elapse Time: 2

File Size: 36943

Bandwidth Is 18471.5 Bytes Per Second


PRINTED RESULTS WITHOUT TEST HARNESS:
_____________________________________

Elapse Time: 0

File Size: 36943

Elapse Time Is Less Than One Second.

  Bandwidth Exceeds 36943 Bytes Per Second


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

Date: Wed, 14 Nov 2001 15:48:10 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Bandwidth meter in cgi/perl?
Message-Id: <3BF302BA.7B467152@stomp.stomp.tokyo>

Godzilla! wrote:
 
> bozko wrote:
 
 (snipped)
 
> > I need to implement a bandwidth meter using cgi/perl


I should add if you want greater accuracy run an independent
LWP test script several hundred times at random times of day
and night, then average out how long LWP takes to fetch
a file on your server. Subtract this amount from your
elapse time if it is significant. It would be prudent
of you to do this; LWP is known to be slow but dependable.

There would be no real benefit to factor out how long
Perl core takes to execute and complete; this will vary
greatly being directly proportionate to server load.

Do try to keep in mind negative numbers are for
imaginative mathematicians, not for bandwidth scripts.

Remember, this is a toy not a precision binary executable.


Godzilla!


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

Date: Thu, 15 Nov 2001 00:56:38 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Can not create new HTML page with cgi.pm
Message-Id: <slrn9v64m4.lel.efflandt@typhoon.xnet.com>

On Wed, 14 Nov 2001, Patrick Bennett <pbennett@mills.edu> wrote:
> This is a multi-part message in MIME format.
> --------------0C32157D06D3769C460D9369
> Content-Type: text/plain; charset=us-ascii
> Content-Transfer-Encoding: 7bit

We don't need any vcard.  Use plain text.

> Created a simple enter information and then print results script using
> cgi.pm.
> The results page is appended to the bottom of the original enter your
> information page.
> This behavior causes the results page not to be shown without scrolling
> down, if a 
> user is not aware of this behavior it seems as the page is doing
> nothing.  I have tried
> many things... can not get the results page to reprint.  New to cgi...
> thanks in advance,
> please reply to pbennett@mills.edu .

So fix your logic to either print the form after the content (if the user 
might want to further edit it) or to exit after printing the result 
(function method example):

if (param) {
    print header, start_html('Form Result');
    # output and process result
    exit;  # unless you also want to replicate the submitted form
} else {
    print header, start_html('Form');
}

# create the form (or could be within else section)

-- 
David Efflandt - All spam is ignored - http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Wed, 14 Nov 2001 17:16:24 -0700
From: "Michael Cook" <mikecook@cigarpool.com>
Subject: DBI changing from CSV to mySQL probs
Message-Id: <APDI7.1520$xO6.234964@news.uswest.net>

Hi folks!
    I am successfully running DBI using CSV files and am changing over to a
mySQL DB. Below is the code I am trying to use to insert test data and I get
the error:

var=|| Content-type: text/html
Software error:
Can't call method "do" on an undefined value at addpipe.pl line 188.

    Can anyone point me in the right direction?
        Thx a million!!!
            Michael

$db = 'pipes';
$dbuser='user';
$dbpasswd='password';
$dbh = DBI->connect("DBI:mysql:$db:host.domain.com", $dbuser, $dbpasswd);

$STATEMENT = "
INSERT INTO $db
VALUES 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0
";
print "<BR>var=|$dbh|\n";
$dbh->do( $STATEMENT );
--
== CigarPool ==
http://www.cigarpool.com




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

Date: Thu, 15 Nov 2001 01:05:36 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: DBI changing from CSV to mySQL probs
Message-Id: <mbudash-057759.17053914112001@news.sonic.net>

In article <APDI7.1520$xO6.234964@news.uswest.net>, "Michael Cook" 
<mikecook@cigarpool.com> wrote:

> Hi folks!
>     I am successfully running DBI using CSV files and am changing over to 
>     a
> mySQL DB. Below is the code I am trying to use to insert test data and I 
> get
> the error:
> 
> var=|| Content-type: text/html
> Software error:
> Can't call method "do" on an undefined value at addpipe.pl line 188.
> 
>     Can anyone point me in the right direction?
>         Thx a million!!!
>             Michael
> 
> $db = 'pipes';
> $dbuser='user';
> $dbpasswd='password';
> $dbh = DBI->connect("DBI:mysql:$db:host.domain.com", $dbuser, $dbpasswd);
> 
> $STATEMENT = "
> INSERT INTO $db
> VALUES 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0
> ";
> print "<BR>var=|$dbh|\n";
> $dbh->do( $STATEMENT );

the error message is telling you that your 'connect' failed, so $dbh is 
not defined.
 
hth-
-- 
Michael Budash ~~~~~~~~~~ mbudash@sonic.net


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

Date: Wed, 14 Nov 2001 18:58:36 -0700
From: Patrick <patrickolson@qwest.net>
Subject: Re: DBI changing from CSV to mySQL probs
Message-Id: <3BF3214C.B9943ECD@qwest.net>

Michael Budash wrote:
> 
> In article <APDI7.1520$xO6.234964@news.uswest.net>, "Michael Cook"
> <mikecook@cigarpool.com> wrote:
> 
> > Hi folks!
> >     I am successfully running DBI using CSV files and am changing over to
> >     a
> > mySQL DB. Below is the code I am trying to use to insert test data and I
> > get
> > the error:
> >
> > var=|| Content-type: text/html
> > Software error:
> > Can't call method "do" on an undefined value at addpipe.pl line 188.
> >
> >     Can anyone point me in the right direction?
> >         Thx a million!!!
> >             Michael
> >
> > $db = 'pipes';
> > $dbuser='user';
> > $dbpasswd='password';
> > $dbh = DBI->connect("DBI:mysql:$db:host.domain.com", $dbuser, $dbpasswd);
> >
> > $STATEMENT = "
> > INSERT INTO $db
> > VALUES 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0
> > ";
> > print "<BR>var=|$dbh|\n";
> > $dbh->do( $STATEMENT );
> 
> the error message is telling you that your 'connect' failed, so $dbh is
> not defined.
> 
> hth-
> --
> Michael Budash ~~~~~~~~~~ mbudash@sonic.net

I would have to agree try like this

#Connect to DSN
my $serverTabl = "guestbook";
$DSN="DBI:mysql:database=$serverTabl";

$dbh = DBI->connect($DSN,$user,$password) or die "Couldn't connect to
database: $serverTabl " . DBI->errstr;


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

Date: Wed, 14 Nov 2001 18:57:30 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: dhcpdiscover
Message-Id: <3BF304E9.340D84BC@earthlink.net>

Please don't send private emails to people who have posted answers on
comp.lang.perl.misc, asking them [stupid] questions.  If you want help,
ask it on the newsgroup, not via email, unless the person says, "let's
take this discussion to private email."

[mailed and posted]
jack wrote:
> 
> How to send a DHCPDISCOVER broadcasting message to a subnet in PERL?

I responded:
> The same way you would send a DHCPDISCOVER broadcasting message in C,
> but do it in perl.  Where's your perl question?

Jack wrote:
[snip]
> I don't know how to construct a DHCPDISCOVER message and receive a
> DHCPOFFER message in return.

Then learn how, first, before trying to do it in perl.

[snip]
> I much appreciate your precious time and KIND ASSISTANCE!!

Is this sarcasm? :)

> If it is possibl, could you please offer some smaple code in perl
> related sending a DHCPDISCOVER broadcasting message.

Ok, here's some code in perl which provides information realted to
sending a dhcp discover message.  :)

#!/usr/local/bin/perl
use strict;
use warnings;
use LWP::Simple;
for my $i ( 1533, 1541, 2131, 2132, 2563, 3118 ) {
    getprint("http://www.faqs.org/rfcs/rfc$i.html");
}
__END__


In addition, I would suggest you learn about about indentation.

From the commandline, type:
    perldoc perlstyle

Your choice of sub names and variable names seems ok, but I can't read
code which is all flush left, and neither can anyone else.  Consider
downloading the 'perltidy' program, and using it on your code.

Lastly, since you sent it line-wrapped, the comments got wrapped, so the
code you sent isn't runnable.  Please don't resend it, I'm not
especially interested in your code, but keep it in mind for next time
you want help.

-- 
Klein bottle for rent - inquire within.


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

Date: Thu, 15 Nov 2001 11:58:41 +1030
From: "David Fosdike" <dfosdike@nospam.elders.com.au>
Subject: Re: IBM AS/400 data queue access
Message-Id: <VSEI7.18$Ns2.1178@nsw.nnrp.telstra.net>

A useful starting point for understanding AS/400 Data queues is
http://www.iseriesnetwork.com/Resources/ClubTech/TNT400/bo400ng/as400dat
aqs.htm

I basically need to communicate between different platforms and the
AS/400 for procedural control and Perl  access via data queues would
provide a standard way of doing it.  At present I know of three
different sources of API's (MS Host Integration Server, IBM Client
Access and a third party on which I cannot remeber at present) which
allow such access but they need to be coded in VBscript or C++ or the
like. Also there is nothing for Linux etc. AFAIK.

Thanx for your interest,

David
Jessica Bull wrote in message ...
>There are several ways to access data with in the AS/400.  I don't know
what
>you mean by data queues though.  Can you elaborate?
>
>"David Fosdike" <dfosdike@nospam.elders.com.au> wrote in message
>news:m5nI7.32$5c2.1560@nsw.nnrp.telstra.net...
>> Anyone know of  any scripts or modules to access AS/400 data queues
from
>> either  MS, Unix or Linux platform?
>>
>> Thanx in advance,
>>
>> David Fosdike
>> dfosdike@nospam.elders.com.au
>>
>>
>>
>
>




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

Date: 14 Nov 2001 17:03:48 -0800
From: johnkenyon@usa.net (John Kenyon)
Subject: Re: Parsing speed
Message-Id: <5dd9e581.0111141703.77cb2ff9@posting.google.com>

"Wyzelli" <wyzelli@yahoo.com> wrote in message news:<B4qI7.1> my $string = '"j","bob","tall","(","footy","rugby","golf","ski",")"';
> $string =~ s/.*\(",(.*),"\)/$1/;
> my @array = $string =~ m/"([^"]*)"/g;
> print "@array";
> Wyzelli

Ah. Still have a problem with " or , in the sport string. I was
previously splitting on " *, *" which minimised the chance of picking
up invalid data.

Using a combination of my initial attempt and suggestions from Wyzelli
I have come up with the following which seems to perform more quickly
than my initial attempt.

my $string = '"j","bob","tall","(","footy","rugby","golf","s,d
"ki",")"';
$string =~ s/.*\(",(.*",)"\)/$1/; 
my @array = split(/" *, *"/,$string);
$array[0] =~ s/ *^"//; #clean up leading "
print "@array";

This gives me
footy rugby golf s,d "ki

Cheers,
John


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

Date: Wed, 14 Nov 2001 19:14:26 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: playing WAV file on unix and windows?
Message-Id: <3BF308E2.AEE1A5C@earthlink.net>

Laocoon wrote:
> 
> > How do I play .wav file on both unix and windows?
> >
> > I'm not going to play a music, I just want to play simple and
> > small(about 30k) wav file.
> > It's ok if it sounds little different on another platform.
> >
> > Thanks for any help..
> 
> http://search.cpan.org/search?dist=Win32-Sound for Windows..
> dunno bout unix~

For unix, you can often simply copy the audio file over /dev/audio, and
it will play.

-- 
Klein bottle for rent - inquire within.


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

Date: Wed, 14 Nov 2001 23:16:14 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: ranged arrays
Message-Id: <3bf2fb3e.7044$c@news.op.net>

In article <9suoln$nak$06$1@news.t-online.com>,
Steffen Müller <tsee@gmx.net> wrote:
>- I'm not missing the point that in your example, there is never a value
>assigned to the internal array and

It wasn't a complete example.  You're supposed to fill in the blanks
(the comment marked "Do something with $n") to get the fetch and store
behavior you want.

>- I'm not missing the point that that's not possible without STORE either.

You can handle STORE the same way you handle FETCH.  

I agree that the for (@a) {} probably cannot be made to work.


        
-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: 14 Nov 2001 18:22:45 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: ranged arrays
Message-Id: <9sv1sl$evb$1@charity.cs.utexas.edu>

In article <9sug8o$nlp$07$1@news.t-online.com>,
Steffen Müller <tsee@gmx.net> wrote:
>"Logan Shaw" <logan@cs.utexas.edu> schrieb im Newsbeitrag
>news:9suc2g$cqv$1@charity.cs.utexas.edu...
>| Handling slices of the bounded array will be a little bit trickier, but
>| I think even that can be done if you define a function that returns an
>| lvalue array, and if that lvalue array is not the internal storage
>| itself but an array that happens to be tied back to your object.
>
>Worse yet, how would you realize a decent syntax for multi-dimensional
>BoundedArray's?
>
>use BoundedArray;
>
>$ba = BoundedArray->new(-5, 50);
>
>$ba->at(-3)         = BoundedArray->new(5,13);
>$ba->at(-3)->at(10) = "This is horrible\n";

I don't even think it'd be possible to implement autovivification,
which I think is just about the only way to make that any better.  But
that's probably OK, because you probably don't want autovivification
with bounded arrays.  If you have autovivification, then the bounds are
undefined, and that seems just _slightly_ out of line with the spirit
of bounded arrays, don't you think?

So in that case, you probably want a normal array anyway[1].  And
although it's not a thing of beauty, it's not so terribly bad:

    ${$ba->at(-3)}[10] = "This is arguably less horrible\n";

At least, I think this should work.  I know it works if I replace
"$ba->at(-3)" with some random scalar variable, so I'd hope/assume it
works when I use a subroutine call that returns an lvalue.  (I don't
have a recent enough version of Perl handy to test it with.)

Another approach is to implement bounded arrays so they can have more
than one dimension, so you can do things like "$ba->at(-3,7)".  But an
approach I like better is to just make syntactic sugar for it, so that
at() would look like this:

    sub at : lvalue
    {
	my $self = shift;

	if (@_ > 1)
	{
	    # syntactic sugar

	    my $outer_index = shift;

	    die "too many dimensions!\n" unless
		UNIVERSAL::isa ($self->at($outer_index), "BoundedArray"));

	    return $self->at($outer_index)->at(@_);
	}
	else
	{
	    # regular implementation goes here
	}
    }

That way, "$ba->at(3,7)" gets reduced to "$ba->at(3)->at(7)".

Once again, I'm sort of on thin ice with my knowledge of lvalues.  I'm
only assuming an lvalue can be passed through multiple levels of
return.  (But then, it's not *actually* necessary to implement it
recursively.  It's just simpler and more fun.)

Hell, if you want, make at() check if any index is an array ref, and if
it is, it means a slice instead of an individual element, so you can
type

    $ba->at(2,4,[7..9])

and get back a slice bound to the elements at (2,4,7), (2,4,8), and
(2,4,9).  And if you're feeling really frisky, then

    $ba->at([2..3],4,[7,9])

can be a slice bound to the elements at (2,4,7), (2,4,9), (3,4,7), and
(3,4,9).  But now I'm just being silly[2].

  - Logan

[1]  Unless you are trying to get unbounded arrays with negative
     indices.  But the obvious implementation wouldn't support that
     anyway, because it would determine the index of the lowest
     possible element at object creation time and manage the storage
     accordingly.

[2]  But I do want to point out that if one actually does implement
     slices in an array class, then using the ".." to operator is
     probably not that great an idea.  Better to pass the *idea* of a
     range to the object than to pass it a list of all the elements in
     the range.  Unfortunately, "[2,'..',3]" is an ugly syntax.  Maybe
     "[2, 'thru', 3]" is a tiny bit better, although it's still bad.
-- 
"In order to be prepared to hope in what does not deceive,
 we must first lose hope in everything that deceives."

                                          Georges Bernanos


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

Date: Thu, 15 Nov 2001 01:09:48 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: setuid cgi?
Message-Id: <slrn9v65er.lel.efflandt@typhoon.xnet.com>

On Wed, 14 Nov 2001 07:42:28 GMT, Sean Hamilton <sh@planetquake.com> wrote:
>> Err, that should read:
>> Try an ISP with a cgi wrapper. Cobalt Linux comes with it built in.
> 
> Geez, how did you manage to do that?
> 
> I have root to this box, it's mine. Is it at all possible to do this with
> just configuration, no special installations? Ideally I could just set the
> setuid bit on the script, but then I just get "can't do setuid" in my Apache
> logs. (/usr/bin/suidperl is chmod 6555)
>
> Running FreeBSD 4.4R.

What is 6555.  I believe suidperl should be 4755 in order to work, or at
least that worked for me (even a test suid root CGI, but in the main
cgi-bin, not under suexec).  However, there are possible security concerns
about making suidperl suid root, so it was not suid root by default in my
SuSE Linux.  And of course any external input or %ENV you use has to be
untainted per 'perldoc perlsec'.

But if you are just trying to do CGI as a normal user, the apache suexec
option should be easy enough to set up, if it is not by default (for
virtual hosts under DocumentRoot with user and group spec'd or /~user/
URL's).

-- 
David Efflandt - All spam is ignored - http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Thu, 15 Nov 2001 00:24:31 +0100
From: Jens Luedicke <jens@irs-net.com>
Subject: shift operator / large numbers
Message-Id: <9suule$ge2$02$1@news.t-online.com>

Hi ...

I messed around with perl's shift operators and I would like to know why
those onliners have the same results:

jens@cello:~$ perl -le 'print 2 << 2 << 4 << 8 << 16'
2147483648

jens@cello:~$ perl -le 'print 2 << 2 << 4 << 8 << 16 << 32'
2147483648

-- 
Jens Luedicke
jens at irs dash net dot com



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

Date: Wed, 14 Nov 2001 23:54:59 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: shift operator / large numbers
Message-Id: <3BF30450.56A76AF3@acm.org>

Jens Luedicke wrote:
> 
> I messed around with perl's shift operators and I would like to know why
> those onliners have the same results:
> 
> jens@cello:~$ perl -le 'print 2 << 2 << 4 << 8 << 16'
> 2147483648
> 
> jens@cello:~$ perl -le 'print 2 << 2 << 4 << 8 << 16 << 32'
> 2147483648

Because on your platform integers are 32 bits wide so '<< 32' is a noop.



John
-- 
use Perl;
program
fulfillment


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

Date: 14 Nov 2001 18:39:41 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Trees, Memory mgt and GC in perl 5.005_3
Message-Id: <9sv2sd$f3b$1@charity.cs.utexas.edu>

In article <9sujds$2i9q$1@agate.berkeley.edu>,
Arvin Portlock <temp133@hotmail.com> wrote:
>Anyway, I guess now I'm confused by what exactly is meant by
>an external reference and why I would want or need to iterate through
>my data structure deleting references to parent nodes, or why you
>feel this might be easiest. All of my nodes are referenced as my
>variables within subroutines. So when the program finishes they
>should all pass out of scope. Only the root remains. Only the root
>is accessible to the outside world. There seems to me to be a bit
>of danger in this assumption, the user of the module assumes the
>burden, but assuming that is actually the case, would undef'ing the
>root be sufficient? Or do the references from one node to another
>constitute external references? Yes, they are definitely circular but
>are not "exposed."

Your confusion is understandable.

Deleting the root (i.e. all external references) IS sufficient to make
it possible in theory for a garbage collector to reclaim your entire
data structure.  In fact, there are real interpreters for other
languages that have a garbage collector that can do that.

But that kind of garbage collection is somewhat slow.  So, Perl uses a
different garbage collection algorithm that is fast but not
"thorough".  The particular algorithm that Perl uses works just great
unless there are cycles in the data structure.  If there are cycles,
then Perl's garbage collector is tricked into thinking that it can't
reclaim some of the storage when actually it could.

To put it a different way, a perfect garbage collector deletes all data
that is no longer reachable by the program.  Perl's garbage collector
deletes all data that has a reference count of zero.  The only time
when there's a difference is when the data has a cycle.

So the reason I suggest you break links from nodes to their parents is
that it's an easy way to eliminate all cycles.  And if you do that,
then Perl's imperfect garbage collector won't be tricked into thinking
that your data is still in use.

  - Logan
-- 
"In order to be prepared to hope in what does not deceive,
 we must first lose hope in everything that deceives."

                                          Georges Bernanos


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

Date: Wed, 14 Nov 2001 18:59:44 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: using modules in subdirectories with a dash
Message-Id: <3BF30570.625A3DE9@earthlink.net>

Mark Jason Dominus wrote:
> 
> In article <3BF1F9CB.F1D13948@earthlink.net>,
> Benjamin Goldberg  <goldbb2@earthlink.net> wrote:
> >Lee Rossey wrote:
> >[snip]
> >
> >BEGIN: {
> >    require UNIVERSAL::require;
> >    require UNIVERSAL::import;
> >    "me::exploits::CVE-2000-1131_GCI_Guestbook::gbook"->require;
> >    "me::exploits::CVE-2000-1131_GCI_Guestbook::gbook"->import;
> >}
> >
> >Don't leave out the quotes, or it won't work.
> 
> It doesn't work anyway.  Even omitting the spurious : after BEGIN, I
> get 'Can't locate UNIVERSAL/require.pm in @INC'.

Well, duh.  First download them from CPAN, as I said to do in my
response to your asking this same question in an earlier thread.

-- 
Klein bottle for rent - inquire within.


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

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 2135
***************************************


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