[18825] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 993 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 26 11:10:31 2001

Date: Sat, 26 May 2001 08:10:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <990889812-v10-i993@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 26 May 2001     Volume: 10 Number: 993

Today's topics:
    Re: perl tattoo (Mark Jason Dominus)
    Re: Question about Const package <goldbb2@earthlink.net>
    Re: random numbers <godzilla@stomp.stomp.tokyo>
    Re: random numbers (Dave Bailey)
    Re: random numbers <godzilla@stomp.stomp.tokyo>
    Re: random numbers <goldbb2@earthlink.net>
        Reading a whole file in with one read() call <goldbb2@earthlink.net>
        Reading out keys from a hash <tlensing@chaoticarts.de>
    Re: Reading out keys from a hash <a.v.a@home.nl>
    Re: regexp to expand variables <goldbb2@earthlink.net>
    Re: SET-UP (free) (Bob Moose)
    Re: SET-UP (free) <joe+usenet@sunstarsys.com>
    Re: sounder <nobody@dev.null>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 26 May 2001 14:55:15 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: perl tattoo
Message-Id: <3b0fc3c2.3cde$69@news.op.net>

In article <nLXO6.63191$I5.13481940@news1.rdc1.tn.home.com>,
Todd Smith <todd@designsouth.net> wrote:
>
>"John Hall" <jhall@ifxonline.com> wrote in message
>news:0xSO6.27782$vf6.2760109@news1.rdc1.sdca.home.com...
>> If I got the 7 line perl DECSS code tattoo'ed on my chest, if I went to
>the
>> beach, would I be arrested by the feds?
>>
>
>What if you do, then later there's a shorter way to do it using Perl6?

There's already a shorter way to do it in Perl 5.  Winstein and
Horowitz have a 6-line version now that is also more efficient,
because it precomputes the translation table instead of recomputing it
for every block of data.



-- 
@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: Sat, 26 May 2001 10:30:03 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Question about Const package
Message-Id: <3B0FBDEB.809640C@earthlink.net>

Anno Siegel wrote:
> 
> According to Benjamin Goldberg  <goldbb2@earthlink.net>:
> > I don't have perl on my system, so I can't test it out right now,
> > but... Consider the following:
> >
> > use Tie::Const;
> >
> > my (%h);
> > const \%h, { 1 => 2, 3 => 4 };
> >
> > my $x = \$h{1};
> > $$x = 5;
> >
> > Unless I'm mistaken, this works without error.  Somebody please tell
> > me I'm wrong?
> 
> Is there a module Tie::Const, and what is its described behavior?  I
> can't find it on CPAN.  So I can't be sure what your gripe is about.
> 
> You probably expected everything declared "const" to be read-only.
> But if Tie::Const is anything like the standard const pragma, I
> wouldn't expect that.  Look at this:
> 
>     use constant HREF => { 1 => 2, 3 => 4 };
> 
>     my $before = ${ &HREF}{ 3};
>     ${ &HREF}{ 3} = 99;
>     my $after = ${ &HREF}{ 3};
> 
> When "use constant" happens, Perl evaluates the right side which
> happens to return a hashref.  This value is frozen in the constant
> HREF (which really is a parameterless sub) and can't be changed (or
> indeed accessed) later in the program.  The hash it points to,
> however, is a regular hash and can be changed at will.
> 
> If you want a read-only hash, you currently would have to tie it
> to a class that rejects write attempts.  Apparently Tie::Const
> doesn't do that.

It does reject write attempts... or at least, STORE attempts.  But if I
take a reference to a value returned by FETCH, and then assign to that
reference, does it call STORE?

I did a web search, and the module is available at
	http://www.perlpress.com/perl/Tie-Const-1.05.tar.gz

-- 
#! perl -- This took a heck of a lot of work to make.  I hope it works.
@p{split//,'justaperlhacker'}=map oct,qw(6b 71 83 1c1 43 2 3 5 79d 71db
7835 1ddf07 23a871 72656b63); print map {$e=1;for(split//){$e*=$_};pack
'V',$e} qw(ptk ppppprre pperrrlau ppppphc ppjsa r);


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

Date: Sat, 26 May 2001 05:33:52 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: random numbers
Message-Id: <3B0FA2B0.B3915D90@stomp.stomp.tokyo>

Benjamin Goldberg wrote:
 
> Godzilla! wrote:
> > Benjamin Goldberg wrote:
> > > Garry Williams wrote:
> > > >  Bart Lateur  wrote:
> > > > > sas wrote:

> > (snipped lots of codes all of which take forever to run)

> > > Would anyone like to suggest any other algorithms?

> > Yes.

> > use Time::Local;
> > $id_number = timelocal (localtime()); sleep (1);
 
> Considering that the OP wants a 5 digit number, this will get truncated
> by a mod 100_000, and padded on the left with 0s.

I've addressed this twice in this thread and numerous times
in other threads. You see? What I say is true; boys simply
do not pay attention nor remember anything.

 
> What happens if a new id is created exactly some multiple of 100_000
> seconds of some earlier used id?  Especially as the database approaches
> being full.  *Your* code breaks, that's what happens.  You get two
> people with the same id.

Oh my. Einstein's Theory of Relatively is absolutely true in all
aspects! Given enough time, we end up right back where we started,
even when travelling in a deliberate linear manner!

So your belief is every one-hundred-thousand seconds, time repeats
itself by winding back its own hands of time.

Say, is that Rod Serling standing next to you smoking a cigarette?

 
> Now, considering that rand is seeded using time,

Odd, I do not read any use of rand in my code. You feeling ok?


> please tell me why your [broken] code is any better than:
 
> $new_id = int rand 100_000;
> for( 1..100_000 ) {
>         if( unused( $new_id ) ) {
>                 return $new_id;
>         } else {
>                 $new_id = $new_id + 1 % 100_000;
>         }
> }
> return undef;


My code is better because it works.


#!perl

 $new_id = int rand 100_000;
 for( 1..100_000 ) {
         if( unused( $new_id ) ) {
                 return $new_id;
         } else {
                 $new_id = $new_id + 1 % 100_000;
         }
 }
 return undef;

exit;

PRINTED RESULTS:
________________

Undefined subroutine &main::unused called at test1.pl line 5.

 

> Especially since mine *works*, all the time, and yours doesn't unless if
> the database is nearly empty (and even then, there's a chance of yours
> not working).

That is pure mule manure. Are you a dung beetle in real life?

 
Godzilla!


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

Date: 26 May 2001 12:54:36 GMT
From: dave@sydney.daveb.net (Dave Bailey)
Subject: Re: random numbers
Message-Id: <slrn9guvma.1cc.dave@sydney.daveb.net>

On Sat, 26 May 2001 05:33:52 -0700, Godzilla! 
<godzilla@stomp.stomp.tokyo> wrote:
[...]
>Oh my. Einstein's Theory of Relatively is absolutely true in all
>aspects! Given enough time, we end up right back where we started,
>even when travelling in a deliberate linear manner!

No, that's Einstein's Theory of Absolutely, as in, what you just
said makes Absolutely no sense and has Absolutely nothing to do with
relativity.

--
Dave Bailey
davidb54@yahoo.com


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

Date: Sat, 26 May 2001 06:07:11 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: random numbers
Message-Id: <3B0FAA7F.D5B0FF0B@stomp.stomp.tokyo>

Dave Bailey wrote:
 
>  Godzilla! wrote:

> [...]

> >Oh my. Einstein's Theory of Relatively is absolutely true in all
> >aspects! Given enough time, we end up right back where we started,
> >even when travelling in a deliberate linear manner!
 
> No, that's Einstein's Theory of Absolutely, as in, what you just
> said makes Absolutely no sense and has Absolutely nothing to do with
> relativity.


You are mistaken. You are referencing Curly's Principle Of Unsointy.


Godzilla!


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

Date: Sat, 26 May 2001 09:55:44 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: random numbers
Message-Id: <3B0FB5E0.491CFEFC@earthlink.net>

Godzilla! wrote:
> 
> Benjamin Goldberg wrote:
[snip]
> > > use Time::Local;
> > > $id_number = timelocal (localtime()); sleep (1);
> 
> > Considering that the OP wants a 5 digit number, this will get
> > truncated by a mod 100_000, and padded on the left with 0s.
> 
> I've addressed this twice in this thread and numerous times
> in other threads. You see? What I say is true; boys simply
> do not pay attention nor remember anything.
> 
> > What happens if a new id is created exactly some multiple of 100_000
> > seconds of some earlier used id?  Especially as the database
> > approaches
> > being full.  *Your* code breaks, that's what happens.  You get two
> > people with the same id.
> 
> Oh my. Einstein's Theory of Relatively is absolutely true in all
> aspects!

Relatively states that an hour with a cute girl in your lap feels like
five minutes, and five minutes with your hand on a hot stove feels like
an hour.  I don't think this is relevant to the discussion at hand.
Relativity states that time goes slower as you move faster.  This can be
seen by observing that programs to take longer to complete as you try to
send more and more data in and out of the machine at high speed.

> Given enough time, we end up right back where we started,
> even when travelling in a deliberate linear manner!

Eventually, the number (time()%100_1000) will repeat.  I don't see how
you could possibly dispute that.  For that matter, since time() is only
a 32 bit value, then eventually, time() will repeat, even without the
mod.  Of course, as for *us* ending up back where we started, that's one
of the principles of re-incarnation... we all do (are fated to do) the
same things as we did before.  Now, while Einstein *did* study magic and
mysticism before coming up with quantum theory, I don't think that
reincarnation has aught to do with relativity (maybe with relatively,
though).

> So your belief is every one-hundred-thousand seconds, time repeats
> itself by winding back its own hands of time.

Nonsense.  "Winding back" would imply an analog clock.  You don't really
thing that god would use such an archaic technology, do you?

> Say, is that Rod Serling standing next to you smoking a cigarette?
> 
> 
> > Now, considering that rand is seeded using time,
> 
> Odd, I do not read any use of rand in my code. You feeling ok?

I use it in mine.  Is there any significant differnce between my code
doing $x = int rand 100_000; and your code doing $x = time % 100_1000; ?

[snip]
> PRINTED RESULTS:
> ________________
> 
> Undefined subroutine &main::unused called at test1.pl line 5.

Well, gee.  Really?  You mean that your program wasn't able to find the
code that Sara S. uses to find whether a number is in the log file or
not?  How about you show me where you include her code, and I'll tell
you how to fix it.

> That is pure mule manure. Are you a dung beetle in real life?

No, I'm an ass.  Just offhand, how much manure *does* a giant
fire-breathing dinosaur produce?  On second thought, I don't want to
know.

-- 
#! perl -- This took a heck of a lot of work to make.  I hope it works.
@p{split//,'justaperlhacker'}=map oct,qw(6b 71 83 1c1 43 2 3 5 79d 71db
7835 1ddf07 23a871 72656b63); print map {$e=1;for(split//){$e*=$_};pack
'V',$e} qw(ptk ppppprre pperrrlau ppppphc ppjsa r);


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

Date: Sat, 26 May 2001 10:00:06 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Reading a whole file in with one read() call
Message-Id: <3B0FB6E6.DFAA1F5@earthlink.net>

Dave Bailey wrote:
> 
> On Sat, 26 May 2001 06:31:11 -0400, Benjamin Goldberg
> <goldbb2@earthlink.net> wrote:
> [...]
> >I've a question which is OT for the thread...
> >
> >Suppose I open a file from a mounted system whose reads are very
> >slow, for example the following with a slow network link:
> >
> >       open( FILE, "/afs/something.jp/foo/blah.gif" );
> >
> >(With me being in the US).  If I then do:
> >
> >       read( FILE, $buf, -s FILE );
> >
> >Am I garunteed to get all of the file?  [...] Is there any chance
> >that read() will block until *some* data is there, and return it,
> >even if that amount is less than the amount I asked for?
> 
> POSIX allows read(2), which underlies Perl read() and sysread(),
> to return a short byte count without setting errno if it is
> interrupted after reading some data.  I think this means you could
> end up with just part of the file whether you use read() *or*
> sysread(), so in order to be sure what you've got, you have to
> check the return value from whichever function you choose to use.

But as long as there's no interrupt, there's no worries?
Or should I *always* check the return value of read, and loop if
necessary?

-- 
#! perl -- This took a heck of a lot of work to make.  I hope it works.
@p{split//,'justaperlhacker'}=map oct,qw(6b 71 83 1c1 43 2 3 5 79d 71db
7835 1ddf07 23a871 72656b63); print map {$e=1;for(split//){$e*=$_};pack
'V',$e} qw(ptk ppppprre pperrrlau ppppphc ppjsa r);


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

Date: Sat, 26 May 2001 13:22:52 +0200
From: "Tobias Lensing" <tlensing@chaoticarts.de>
Subject: Reading out keys from a hash
Message-Id: <9eo3pr$jp3$07$1@news.t-online.com>

Hi all,

assuming a hash %x is defined like the following:

%x = ("name","andy","age","19");

How can I read out the keys of the hash ("name" and "age" here)?

Thanks in advance.
Tobi





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

Date: Sat, 26 May 2001 13:06:09 GMT
From: AvA <a.v.a@home.nl>
Subject: Re: Reading out keys from a hash
Message-Id: <3B0F826B.A1775130@home.nl>

Tobias Lensing wrote:

> Hi all,
>
> assuming a hash %x is defined like the following:
>
> %x = ("name","andy","age","19");
>
> How can I read out the keys of the hash ("name" and "age" here)?

_______________________________

#!/usr/bin/perl -w

use strict;

my %Hash = qw (name Andy age 10);

foreach (keys(%Hash)){
 print "$_\n";
}
______________________________

or just:
 ....
print keys(%Hash);



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

Date: Sat, 26 May 2001 10:23:02 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: regexp to expand variables
Message-Id: <3B0FBC46.BDBEAE1@earthlink.net>

Joe Schaefer wrote:
[snip]
> That being said, I think Craig's can be tightened up to be safe on
> tainted data:
> 
>   s/(\$\w+(?:\[-?\d+\]|\{\w+\})?)/$1/eeg;
> 
> Can anyone find an way to exploit this?

Well, for one thing, if $_ = '$ENV{HOME}'; the attacker may be able to
get your home directory.  How bad an exploit is that?

A more minor that attack is $_ = '$_$_$_$_$_$_';  As a result, the
string might be significantly longer than your program expected,
possibly upsetting some logic or other.

To really tighten up the pattern:

	s/\$(\w+(?:\[-?\d+\]|\{\w+\})?)/'$Safe_x0001::'.$1/eeg;

Which only gets you variables from inside the package Safe_x0001 (I
haven't actually looked up how Safe names it's packages; I'm guessing).

-- 
#! perl -- This took a heck of a lot of work to make.  I hope it works.
@p{split//,'justaperlhacker'}=map oct,qw(6b 71 83 1c1 43 2 3 5 79d 71db
7835 1ddf07 23a871 72656b63); print map {$e=1;for(split//){$e*=$_};pack
'V',$e} qw(ptk ppppprre pperrrlau ppppphc ppjsa r);


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

Date: 26 May 2001 06:27:38 -0700
From: yogibearxx@bobmoose.com (Bob Moose)
Subject: Re: SET-UP (free)
Message-Id: <4ec914b1.0105260527.32094c1e@posting.google.com>

My Definition of Free is:

Free.
No Pay.
No Cost.

And to that person who said get in a room, NO


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

Date: 26 May 2001 10:03:24 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: SET-UP (free)
Message-Id: <m3lmnkqkb7.fsf@mumonkan.sunstarsys.com>

yogibearxx@bobmoose.com (Bob Moose) writes:

> My Definition of Free is:
> 
> Free.
> No Pay.
> No Cost.

Time is money, so as soon as I get some more free time,
I'd be glad to do it.  If you'd like to help me get
some free time in the near future, I'd be glad to sell
you some.

> And to that person who said get in a room, NO

No problem. I can fix that, too. For free, of course.

-- 
Joe Schaefer    "It is better to be feared than loved, if you cannot be both."
                                               -- Niccolo Machiavelli


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

Date: Sat, 26 May 2001 09:26:44 -0400
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: sounder
Message-Id: <3B0FAF14.4020608@dev.null>



Todd Smith wrote:

>>> i COULD, but not without learning them first. I'm a perl guy.
>>> 
>>> 
>> 
>> No, you're not.
>> 
> 
> 
> What gives you the authority to say that?
Article 72 of the Icelandic constitution. See http://www.richmond.edu/~jpjones/confinder/Iceland2.htm#72.
Your local jurisdiction probably has some sort of a similar stipulation; 
that's why you can post questions without thinking about them first, 
quote others without identifying them and expect others to do work you 
are too lazy to do yourself.




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

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


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