[22044] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4266 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Dec 15 14:05:44 2002

Date: Sun, 15 Dec 2002 11:05:09 -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           Sun, 15 Dec 2002     Volume: 10 Number: 4266

Today's topics:
    Re: Hashing several million rows of data <dtweed@acm.org>
    Re: Help with Assignment of Split Value from STDIN to H <tassilo.parseval@post.rwth-aachen.de>
    Re: Help with Assignment of Split Value from STDIN to H <krahnj@acm.org>
    Re: Help with Assignment of Split Value from STDIN to H <tassilo.parseval@post.rwth-aachen.de>
    Re: HTTP::Headers <flavell@mail.cern.ch>
        mod_perl installation problems (Todd Smith)
    Re: Need help with caret anchor at start of line (Tad McClellan)
    Re: Need help with caret anchor at start of line <No_Mail_Address@cox.net>
    Re: Need help with Script (Tad McClellan)
    Re: Odd pack() behavior <brian@gonzo.home>
    Re: Odd pack() behavior <brian@gonzo.home>
        Problem in Spacing entries in a File. <kasp@NO_SPAMepatra.com>
    Re: Problem in Spacing entries in a File. <jurgenex@hotmail.com>
    Re: Problem in Spacing entries in a File. <mbudash@sonic.net>
    Re: Syntax of subroutine declarations, relating to use  (Tad McClellan)
    Re: Test::More and overloading "==" (Daniel Berger)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 15 Dec 2002 15:21:01 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: Hashing several million rows of data
Message-Id: <3DFC9B7B.AFE7091B@acm.org>

Tad McClellan wrote:
> 
> T Conti <tconti@hotmail.com> wrote:
> 
> > I imagine that as more data is loaded into
> > a hash its search performance degrades.
> 
> Hashes have an O(1) bound on their running time.
> 
> (determining the bounds of an algorithm assumes that the number of
>  elements is "large enough" to drown out the constant time associated
>  with calculating the hash function and resolving collisions.
> )
> 
> That is fancy college talk that means that hashes have _constant_
> lookup time, the number of elements in the hash does not affect
> how long it takes to search for a particular element.
> 
> In other words, the reality is precisely the opposite of what
> you've imagined.  :-)
> 
> It should be obvious that that is a Really Cool Thing, which is
> why CS curriculums usually require students to spend a few weeks
> studying hashing.

In the default case, this is true only if lookups vastly outnumber stores.
But things aren't quite that simple for the OP's problem, determining
uniqueness, which involves just one lookup and one store per record.

Perl creates a hash with a certain number of "buckets", and whenever the
number of keys exceeds the number of buckets, the number of buckets is
doubled and the items are redistributed. This makes the execution time
O(log N) on the number of stores.

Fortunately, perl lets you preallocate buckets to avoid this. From
perldoc perldata:

   You can preallocate space for a hash by assigning to the
   keys() function.  This rounds up the allocated buckets to
   the next power of two:

      keys(%users) = 1000;                # allocate 1024 buckets

-- Dave Tweed


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

Date: 15 Dec 2002 11:52:47 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Help with Assignment of Split Value from STDIN to Hash Values (As  Arrays)
Message-Id: <athqef$83f$1@nets3.rz.RWTH-Aachen.DE>

Also sprach John W. Krahn:

> "Tassilo v. Parseval" wrote:
>> 
>> Here, I also changed the first argument to split from " " to / /.
>> Remember that this first argument is a regular expression and not a
>> string. Even if you pass a string, this string will get interpreted as a
>> regular expression. This can make quite a difference when passing "." as
>> argument or so. It has to be /\./ (or "\." if you insist to use quotes,
>> but don't do that).
> 
> You seem to forget (or haven't learned) that split( ' ' ) is a special
> case that is similar to split( /\s+/ ) except when there is leading
> whitespace.

Neither of that actually. I did leave it out on purpose to restrict the
scope of my reply to the relevant things.

Yet, I indeed missed that using ' ' would have been the most suitable
solution in the OP's case. Using this special feature of split() the OP
could have gotten rid of his clean_array() (or what it was called)
subroutine altogether.

Tassilo
-- 
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;


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

Date: Sun, 15 Dec 2002 11:24:14 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Help with Assignment of Split Value from STDIN to Hash Values (As  Arrays)
Message-Id: <3DFC6622.86305BEA@acm.org>

"Tassilo v. Parseval" wrote:
> 
> Here, I also changed the first argument to split from " " to / /.
> Remember that this first argument is a regular expression and not a
> string. Even if you pass a string, this string will get interpreted as a
> regular expression. This can make quite a difference when passing "." as
> argument or so. It has to be /\./ (or "\." if you insist to use quotes,
> but don't do that).

You seem to forget (or haven't learned) that split( ' ' ) is a special
case that is similar to split( /\s+/ ) except when there is leading
whitespace.

$ perl -e' $_ = "   a\t\t\tb   c\n";
print;                                    
print ">$_< " for split " ";   print "\n";
print ">$_< " for split /\s+/; print "\n";
print ">$_< " for split / /;   print "\n";
'
   a                    b   c
>a< >b< >c< 
>< >a< >b< >c< 
>< >< >< >a                     b< >< >< >c
< 




John
-- 
use Perl;
program
fulfillment


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

Date: 15 Dec 2002 11:58:38 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Help with Assignment of Split Value from STDIN to Hash Values (As Arrays)
Message-Id: <athqpe$8fh$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Rod:

> if (-e $config->{executable}->{config}){
> 
>     	my @temp=`$config->{executable}->{config} $config->{executable}->
> {flags}`;
>     	foreach (@temp){
>     	    	$_=clean($_);
>     	    	my ($name, $val) = split / /, $_;
>     	    	$config->{items}->{ $name }=$val;
>     	};
> 
> } else {
>     	logger(0,"Configuration Executable Not Found - Exiting Gracefully");
>     	&exithndlr(255);
> };
> 
> and added a "clean" subroutine to just clean for a single scalar
> 
> sub clean{
> 	
> 	chomp($_);
          ^^
> 	$_=~s/^\s+//;
> 	$_=~s/\s+$//;
> 	$_=~s/\s+/ /g;
> 	return $_;
> };

You are using the wrong variable in clean(). It accidently works in your
case because you call it like
    
    $_=clean($_);
    
and $_ is always a global variable. It wont however work with:

    $c = clean($c);

Subroutine parameters are stored in @_ (with the first parameter being
in $_[0] and not $_). The elements in @_ are aliases for the original
values so you don't even need a return value:

    sub clean {
        chomp $_[0];
        $_[0] =~ s/^\s+//;
        $_[0] =~ s/\s+$//;
        $_[0] =~ s/\s+/ /g;
    }

Call it like

    clean($_);

and it will change the passed variable in place.

Tassilo
-- 
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;


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

Date: Sun, 15 Dec 2002 16:34:48 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: HTTP::Headers
Message-Id: <Pine.LNX.4.40.0212151552460.23633-100000@lxplus072.cern.ch>

On Dec 14, Timothy Butler inscribed on the eternal scroll:

> > once again, if cgi, the HTTP_REMOTE_USER environment variable will
> > contain the value of the user authorized via basic authentication, if
> > any. the password cannot be gotten this way (for obvious security
> > reasons)
>
>   Well HTTP_REMOTE_USER does return the user, but also need the password...

I would counsel you that this is a risky thing to want.  It isn't for
nothing, for example, that the Apache software enables a feature of
this kind by means of a flag named SECURITY_HOLE_PASS_AUTHORIZATION

The generic requirement, if I deduce your needs right, might be better
stated as "I need to authenticate this user to some other service",
but I'd recommend that you look for a way to do that without having to
handle an actual user password token - which would put your process
into a quite different security category from what it was before.

(Sure, the details of that aren't Perl-specific, it's more an issue
for comp.security.* groups, and anyway would depend on what the target
service is prepared to accept.  One possible hint might be keypairs,
but a Google search for that token SECURITY_HOLE_PASS_AUTHORIZATION
might reveal some useful discussion and alternatives, I think.)





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

Date: 15 Dec 2002 10:22:53 -0800
From: smittod@auburn.edu (Todd Smith)
Subject: mod_perl installation problems
Message-Id: <ed3092e7.0212151022.b5054da@posting.google.com>

From Apache::Status I have this:

Embedded Perl version v5.6.0 for Apache/1.3.23 (Unix) PHP/4.1.2
mod_perl/1.25

and this 

mod_perl
1.27
Sat Jun 1 15:37:05 2002
/usr/lib/perl5/site_perl/5.6.0/i386-linux/mod_perl.pm

as you can see, it shows two different versions.

When i run a test script to list %ENV, i can't see $ENV{MOD_PERL}, but
it does show when Apache::Status does it's env list.

Also, I've been getting the 
Can't locate object method "module" via package "Apache"
error when i try to use Apache::DBI;

Can anyone help me with any of these problems?

thank you
-todd


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

Date: Sun, 15 Dec 2002 08:34:01 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Need help with caret anchor at start of line
Message-Id: <slrnavp4mp.aae.tadmc@magna.augustmail.com>

Fred <No_Mail_Address@cox.net> wrote:

> But I do not understand why the code is not working when I use a caret
> as "beginning of the line" anchor in the last two lines:


>    s/(.+?\@.+?), (.+?\@.+?)/$1\nTo: $2/ ;
                                ^^
                                ^^

Now you have more than one line in $_:

   I'm having trouble matching over more than one line.  What's wrong?


>    s/^(?:To:|CC:)\s*//ig ;		# Remove TO: and cc: at start of line


So you need another modifier:

    s/^(?:To:|CC:)\s*//igm;
                         ^
                         ^

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


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

Date: Sun, 15 Dec 2002 15:53:55 GMT
From: Fred <No_Mail_Address@cox.net>
Subject: Re: Need help with caret anchor at start of line
Message-Id: <3DFCA61F.8E319AF9@cox.net>


Tad McClellan wrote:
> 
> Fred <No_Mail_Address@cox.net> wrote:
> 
(snip)
> So you need another modifier:
> 
>     s/^(?:To:|CC:)\s*//igm;
>                          ^
> --
>     Tad McClellan                          SGML consulting

Oh - you opened my eyes ...
Thank you Tad,

---
Fred


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

Date: Sun, 15 Dec 2002 08:42:39 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Need help with Script
Message-Id: <slrnavp56v.aae.tadmc@magna.augustmail.com>

Way of the Kali <autochem@worldnet.att.net> wrote:

> Can somebody help me determine what was causing that error message?


No.

Format your code sensibly if you expect sensible people to look at it.


> flock(VOTES,8); close(VOTES);

You are not implementing file locking correctly.

Lose the flock() call there.


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


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

Date: Sun, 15 Dec 2002 13:59:53 -0000
From: "Brian C. Lane" <brian@gonzo.home>
Subject: Re: Odd pack() behavior
Message-Id: <slrnavp2il.tti.brian@gonzo.home>

In article <fplovu0r2u1b3ia5gtt8jl6fale1g2fofe@4ax.com>, Bart Lateur wrote:
> Brian C. Lane wrote:
> 
>>I've run into a strange problem with pack. It seems to be outputting a
>>single byte for 'H2' on one machine, which is the correct behavior. But on
>>another maching I'm getting 2 bytes, and they aren't what they are supposed
>>to be.
> 
> Hmm... Some automatic stealthed conversion to UTF-8? Are the bytes
> "\xC3\xBF"?
> 

Bingo! That's what hexdump shows on the resulting file. Any idea why this is
happening? And how to fix it?

Thanks,

Brian

-- 
 --[Inside 70.1F]--[Outside 44.8F]--[fozzy 68.8F]--[Drink 64.0F]--
Generated with DigiTemp http://www.digitemp.com


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

Date: Sun, 15 Dec 2002 14:31:40 -0000
From: "Brian C. Lane" <brian@gonzo.home>
Subject: Re: Odd pack() behavior
Message-Id: <slrnavp4e8.u8t.brian@gonzo.home>

In article <slrnavp2il.tti.brian@gonzo.home>, Brian C. Lane wrote:
> In article <fplovu0r2u1b3ia5gtt8jl6fale1g2fofe@4ax.com>, Bart Lateur wrote:
>> Brian C. Lane wrote:
>> 
>>>I've run into a strange problem with pack. It seems to be outputting a
>>>single byte for 'H2' on one machine, which is the correct behavior. But on
>>>another maching I'm getting 2 bytes, and they aren't what they are supposed
>>>to be.
>> 
>> Hmm... Some automatic stealthed conversion to UTF-8? Are the bytes
>> "\xC3\xBF"?
>> 
> 
> Bingo! That's what hexdump shows on the resulting file. Any idea why this is
> happening? And how to fix it?

Ok, after a bit of research it looks like I should be able to use either no
utf8 or use bytes at the top of the program to force byte behavior (normal
behavior in my thinking). But it doesn't work. I still get the same damn
unicode output.

I must not be the only one who has run into this, as I would expect anyone
who has been using perl for doing binary data manipulation would have run
into this.

Personally this seems like very dumb behavior on the part of Perl. Code
should be backwards compatible unless explicitly told to take on some new
feature. I shouldn't have to use no utf8; (which doesn't even work for me).

I think I'll recode this script in 'C', whose behavior is known and
predictable (at least for the most part <G>).

Brian


-- 
 --[Inside 70.5F]--[Outside 44.9F]--[fozzy 69.2F]--[Drink 64.1F]--
Generated with DigiTemp http://www.digitemp.com


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

Date: Sun, 15 Dec 2002 20:18:03 +0530
From: "Kasp" <kasp@NO_SPAMepatra.com>
Subject: Problem in Spacing entries in a File.
Message-Id: <ati4na$ejp$1@newsreader.mailgate.org>

HI,
consider this entry in a file:
"                        10800       ; refresh"
                         ^^^^^^^^^
The entry can be someother number like 1 or 10000000 too....but it will be
spaced as shown above"
"                        1           ; refresh"

Now I am supposed to replace this number with another given number....say
600.
I am able to "susbtitute" it, but I dont know how to cope with this spacing
requirement.

How can I maintian the spaceing?

Thanks.




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

Date: Sun, 15 Dec 2002 16:46:54 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Problem in Spacing entries in a File.
Message-Id: <2m2L9.6010$cR2.164@nwrddc04.gnilink.net>

Kasp wrote:
> HI,
> consider this entry in a file:
> "                        10800       ; refresh"
>                          ^^^^^^^^^
> The entry can be someother number like 1 or 10000000 too....but it
> will be spaced as shown above"
> "                        1           ; refresh"
>
> Now I am supposed to replace this number with another given
> number....say 600.
> I am able to "susbtitute" it, but I dont know how to cope with this
> spacing requirement.
>
> How can I maintian the spaceing?

Does 'perldoc -q pad' solve your problem?

jue




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

Date: Sun, 15 Dec 2002 16:45:21 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Problem in Spacing entries in a File.
Message-Id: <mbudash-C89B53.08451315122002@typhoon.sonic.net>

In article <ati4na$ejp$1@newsreader.mailgate.org>,
 "Kasp" <kasp@NO_SPAMepatra.com> wrote:

> HI,
> consider this entry in a file:
> "                        10800       ; refresh"
>                          ^^^^^^^^^
> The entry can be someother number like 1 or 10000000 too....but it will be
> spaced as shown above"
> "                        1           ; refresh"
> 
> Now I am supposed to replace this number with another given number....say
> 600.
> I am able to "susbtitute" it, but I dont know how to cope with this spacing
> requirement.
> 
> How can I maintian the spaceing?
> 
> Thanks.
> 
> 

one way:

my $entry = "                        10800       ; refresh";
my $newrefresh = 1234567;

if ($entry =~ /(\d+)(\s+);/) {
   my $required = length($1) + length($2);
   if (length $newrefresh > $required) {
      print "new data too long\n";
      exit;
   }
   $entry =~ s/$1$2/sprintf("%-${required}s", $newrefresh)/e;
}

print "$entry\n";

hth-


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

Date: Sun, 15 Dec 2002 08:51:39 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Syntax of subroutine declarations, relating to use and variable scope
Message-Id: <slrnavp5nr.aae.tadmc@magna.augustmail.com>

Koos Pol <NO.koos.JUNK.pol.MAIL@raketnet.nl> wrote:
> On zaterdag 14 december 2002 06:26 David B. Nagle wrote:
> 
>> I was looking at the code in News::Article and came across some syntax
>> that I had never encountered before. 
> 
>>     sub post;
>>     
>>     use Net::NNTP ();
>>     
>>     ; sub post
>>     {
>>         # Code removed
>>     }


>> I've never seen Perl code that duplicates the sub declaration like that
>> before, with statements in between. 


There is no duplication.

One of them is a "declaration", one of them is a "definition".


>> Plus, the use of the extra
>> semicolon before the duplicate sub statements is completely new (and
>> rather strange) to me.


You can have "empty statements" in Perl, which is what that is.

This is "useful" for job security:

   s/something//;

   s;something;;;                           # alternate delimiters

   s;something;;;;;;;;;;;;;;;;;;;;;;;;;;    # plus a bunch of empty stmts


:-)  I think I picked that up from Randal.


> I agree it seems unusual.


Ditto.


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


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

Date: 15 Dec 2002 08:50:06 -0800
From: djberg96@hotmail.com (Daniel Berger)
Subject: Re: Test::More and overloading "=="
Message-Id: <6e613a32.0212150850.1916d9db@posting.google.com>

Benjamin Goldberg <goldbb2@earthlink.net> wrote in message news:<3DFC0691.33047630@earthlink.net>...
> Daniel Berger wrote:
> > 
> > Hi all,
> > 
> > Perl 5.8 on Mandrake 9
> > 
> > While using Test::More, I came across a problem trying to test an
> > overloaded operator.  I have a class and created a "=="  instance
> > method using "overload", ala:
> > 
> > use overload
> >    "==" => is_equal,
> >    "fallback" => 1;
> > 
> > The is_equal method simply returns 0 if false, 1 if true.
> > 
> > While trying to test, I did:
> > 
> > ok($obj1 == $obj2);
> > 
> > This caused problems as I get this error:
> > 
> > Can't find string terminator "/" anywhere before EOF
> 
> Where did it say that this error occured?
> 
> It looks like something that is, or should be, a compile time error.
> 
> Could you give a minimal perl script which demonstrates this problem?


Disregard, over.  Stupid syntax error earlier in the test script.


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

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


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