[19137] in Perl-Users-Digest
Perl-Users Digest, Issue: 1332 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 19 03:05:37 2001
Date: Thu, 19 Jul 2001 00:05:09 -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: <995526308-v10-i1332@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 19 Jul 2001 Volume: 10 Number: 1332
Today's topics:
Capitalone and LWP <mail@enricong.com>
FAQ: How can I make my CGI script more efficient? <faq@denver.pm.org>
Re: FAQ: Is it unsafe to return a pointer to local data (Martien Verbruggen)
Re: forking ChangeNotify's <goldbb2@earthlink.net>
Re: GnuPG encrypting from STDIN in CGI <bootsy52@gmx.net>
Re: Including flock in code while developing in Windows <pne-news-20010719@newton.digitalspace.net>
Re: Iterating Nested Hashes <jkline@one.net>
Re: map and split combination slow (Eric Bohlman)
Re: map and split combination slow <rpdaly@bigfoot.com>
Re: map and split combination slow (Eric Bohlman)
Re: map and split combination slow <krahnj@acm.org>
Re: map and split combination slow <uri@sysarch.com>
Re: Obtaining remote users ip <cmicallef@playground.net>
Re: Parsing an html document for the title (don't flame (David Combs)
Re: Replacing a specific line <confused@times.doh>
Re: Request for Comments ... ConvertColorspace.pm <hafner-usenet@ze.tu-muenchen.de>
Re: Scrollable lists in console <bwalton@rochester.rr.com>
Re: Scrollable lists in console (David Efflandt)
where is the "standard library" <seandarcy@hotmail.com>
Re: where is the "standard library" <ayamanita.nospam@bigfoot.com>
Re: Yet Another use/require Question (Martien Verbruggen)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 18 Jul 2001 22:56:41 -0500
From: "Enrico Ng" <mail@enricong.com>
Subject: Capitalone and LWP
Message-Id: <9j5lqt$5tp$1@info1.fnal.gov>
I am trying to get info from capitalone.com but am having trouble.
a page sets two cookies via javascript, then redirects me to the login
screen, where there are two hidden form fields with session ids.
It looks like the two javascript cookies are just random numbers, so I
tried making up my own.
and doing a POST to the login screen, but I get nothing
my code:
use LWP::UserAgent;
use Crypt::SSLeay;
use HTTP::Cookies;
use LWP::Debug '+';
$ua = new LWP::UserAgent;
$ua->agent("Mozilla/4.61 [en] (WinNT; U) " . $ua->agent);
$cookie_jar=new HTTP::Cookies;
#my $req = new HTTP::Request POST =>
'https://service.capitalone.com/cgi/Home?Login';
my $req = new HTTP::Request POST =>
'https://service.capitalone.com/ndconfig.nd/CapOneIAS/pgLogin';
$cookie_jar->add_cookie_header($req);
$req->header('Set-Cookie' => "OAS_COOKIE_ENABLE=\"4234634342\";
path=\"/\"; domain=\".capitalone.com\"; path_sp
ec; secure; version=0");
$req->header('Set-Cookie2' => "OAS_SPLASH_COOKIE=\"4234634342\";
path=\"/\"; domain=\".capitalone.com\"; path_s
pec; secure; version=0");
$req->content_type('application/x-www-form-urlencoded');
$req->content('tbUserId=mylogin&tbPassword=mypassword');
my $res = $ua->request($req);
print $res->content();
this is the DEBUG:
LWP::UserAgent::new: ()
HTTP::Cookies::add_cookie_header: Checking service.capitalone.com for
cookies
HTTP::Cookies::add_cookie_header: Checking .capitalone.com for cookies
HTTP::Cookies::add_cookie_header: Checking capitalone.com for cookies
HTTP::Cookies::add_cookie_header: Checking .com for cookies
LWP::UserAgent::request: ()
LWP::UserAgent::simple_request: POST
https://service.capitalone.com/ndconfig.nd/CapOneIAS/pgLogin
LWP::UserAgent::_need_proxy: Not proxied
LWP::Protocol::http::request: ()
LWP::Protocol::http::request: POST /ndconfig.nd/CapOneIAS/pgLogin
HTTP/1.0
Host: service.capitalone.com
User-Agent: Mozilla/4.61 [en] (WinNT; U) libwww-perl/5.53
Content-Length: 37
Content-Type: application/x-www-form-urlencoded
Set-Cookie: OAS_COOKIE_ENABLE="4234634342"; path="/";
domain=".capitalone.com"; path_spec; secure; version=0
Set-Cookie2: OAS_SPLASH_COOKIE="4234634342"; path="/";
domain=".capitalone.com"; path_spec; secure; version=0
LWP::Protocol::http::request: POST /ndconfig.nd/CapOneIAS/pgLogin
HTTP/1.0
Host: service.capitalone.com
User-Agent: Mozilla/4.61 [en] (WinNT; U) libwww-perl/5.53
Content-Length: 37
Content-Type: application/x-www-form-urlencoded
Set-Cookie: OAS_COOKIE_ENABLE="4234634342"; path="/";
domain=".capitalone.com"; path_spec; secure; version=0
Set-Cookie2: OAS_SPLASH_COOKIE="4234634342"; path="/";
domain=".capitalone.com"; path_spec; secure; version=0
LWP::Protocol::http::request: reading response
LWP::Protocol::http::request: HTTP/1.1 302 Moved Temporarily
LWP::Protocol::http::request: HTTP/1.1 302 Moved Temporarily
LWP::Protocol::http::request: need more header data
LWP::UserAgent::request: Simple response: Found
--
--
Enrico Ng <mail@enricong.com>
------------------------------
Date: Thu, 19 Jul 2001 06:17:00 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How can I make my CGI script more efficient?
Message-Id: <wXu57.13$EW5.180612608@news.frii.net>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.
+
How can I make my CGI script more efficient?
Beyond the normal measures described to make general Perl programs
faster or smaller, a CGI program has additional issues. It may be run
several times per second. Given that each time it runs it will need to
be re-compiled and will often allocate a megabyte or more of system
memory, this can be a killer. Compiling into C isn't going to help you
because the process start-up overhead is where the bottleneck is.
There are two popular ways to avoid this overhead. One solution involves
running the Apache HTTP server (available from http://www.apache.org/)
with either of the mod_perl or mod_fastcgi plugin modules.
With mod_perl and the Apache::Registry module (distributed with
mod_perl), httpd will run with an embedded Perl interpreter which
pre-compiles your script and then executes it within the same address
space without forking. The Apache extension also gives Perl access to
the internal server API, so modules written in Perl can do just about
anything a module written in C can. For more on mod_perl, see
http://perl.apache.org/
With the FCGI module (from CPAN) and the mod_fastcgi module (available
from http://www.fastcgi.com/) each of your Perl programs becomes a
permanent CGI daemon process.
Both of these solutions can have far-reaching effects on your system and
on the way you write your CGI programs, so investigate them with care.
See
http://www.perl.com/CPAN/modules/by-category/15_World_Wide_Web_HTML_HTTP
_CGI/ .
A non-free, commercial product, ``The Velocity Engine for Perl'',
(http://www.binevolve.com/ or http://www.binevolve.com/velocigen/ )
might also be worth looking at. It will allow you to increase the
performance of your Perl programs, running programs up to 25 times
faster than normal CGI Perl when running in persistent Perl mode or 4 to
5 times faster without any modification to your existing CGI programs.
Fully functional evaluation copies are available from the web site.
-
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to
news:news.answers
or to the many thousands of other useful Usenet news groups.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-1999 Tom Christiansen and Nathan
Torkington. All rights reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
03.20
--
This space intentionally left blank
------------------------------
Date: Thu, 19 Jul 2001 03:01:05 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: FAQ: Is it unsafe to return a pointer to local data?
Message-Id: <slrn9lcjbh.1rf.mgjv@verbruggen.comdyn.com.au>
On Wed, 18 Jul 2001 18:17:01 GMT,
PerlFAQ Server <faq@denver.pm.org> wrote:
> +
> Is it unsafe to return a pointer to local data?
^^^^^^^
Shouldn't that be "reference"?
Martien
--
Martien Verbruggen |
Interactive Media Division | +++ Out of Cheese Error +++
Commercial Dynamics Pty. Ltd. | Reinstall Universe and Reboot +++
NSW, Australia |
------------------------------
Date: Thu, 19 Jul 2001 00:12:33 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: forking ChangeNotify's
Message-Id: <3B565E31.3C17B2E8@earthlink.net>
Neil wrote:
>
> Thanks ! I will dig out my IO::Select docs and see what I can get
> accomplished !
>
> I am not entirely sure what the code you supplied does - so that is my
> first task....
>
> The second is to see if I can use it for other "watcher" events as I have
> some that watch a directory for any new files (messages) and then processes
> those....
>
> I guess what I am trying to say is that I am attempting to "spawn" a number
> of seperate autonamous processes - that I want to be able to interact, at
> the least by a gracious shutdown, at the most by "message" passing. They
> don't need to share variables etc with the parent. The "message passing" can
> be accomplished by dropping a file in the msg directory, if I can spawn a
> "message watcher".
>
> All of the watcher segments work perfectly as stand alone scripts - I would
> just like to create a "manager script" that can start a "bunch" of "
> watchers - except they seem to wait indefinitely on each other, as expected,
> or I can set the timeout, and create a change that an event occurs between
> "lookups".
Ahhhh... why didn't you say so?
Passing messages should be done with pipes, not through the filesystem.
Here's a template which should allow you to create a manager and
children and have them interact with each other with relative ease.
Yes, it's a bit big, but it's designed for you to read and learn from,
as much as anything else.
#! perl -w
use strict;
sub spawned { # this is the child spawned by the parent
my ($parent2child_r, $child2parent_w, @args) = @_;
my ($my_identifyer) = $$;
# do stuff, possibly including:
# reading from $parent2child_r
# writing to $child2parent_w
close $_ for ($parent2child_r, $child2parent_w);
exit;
}
sub spawn { # this spawns a new child.
pipe my ($parent2child_r, $parent2child_w) or die $!;
pipe my ($child2parent_r, $child2parent_w) or die $!;
if( my $pid = fork ) {
close $_ for ($parent2child_r, $child2parent_w);
return ($child2parent_r, $parent2child_w, $pid);
} elsif( defined $pid ) {
close $_ for ($child2parent_r, $parent2child_w);
spawned($parent2child_r, $child2parent_w, @_);
die "Expected spawned process to exit\n";
} else {
die "Couldn't fork: $!\n";
}
}
use IO::Select;
manager: {
my @kids;
my %handles;
my $rs = IO::Select->new;
my $ws = IO::Select->new;
my $er = IO::Select->new;
for my $count ( 1..10 ) {
my ($r, $w, $p) = spawn( $count );
my $kid = [$r, $w, $p, $count];
push @kids, $kid;
$handles{ $r } = $kid;
$handles{ $w } = $kid;
$rs->add( $r );
$ws->add( $w );
$er->add( $r, $w );
}
while( 1 ) {
my @ready = IO::Select->select( $rs, $ws, $er )
or die "select: $!\n";
my ($readready, $writeready, $errrored) = @ready;
foreach my $fh ( @$errored ) {
my $kid = $handles{$fh};
my ($r, $w, $p, $i) = @$kid;
if( $fh = $r ) {
$r->getc and die "Expected an error!";
print "Error reading from kid $i: $!\n";
} else {
print $w "x" and die "Expected an error!";
print "Error writing to kid $i: $!\n";
}
@$readready = grep { $_ != $r } @$readready;
@$writeready = grep { $_ != $w } @$writeready;
close $_ for ($r, $w);
$kids[$i] = undef;
delete $handles{$r};
delete $handles{$w};
$rs->remove( $r );
$ws->remove( $w );
$er->remove( $r, $w );
kill $p or die "Couldn't kill pid $p: $!\n";
}
foreach my $fh ( @$readready ) {
my $kid = $handles{$fh};
my ($r, $w, $p, $i) = @$kid;
# read from $fh
}
foreach my $fh ( @$writeready ) {
my $kid = $handles{$fh};
my ($r, $w, $p, $i) = @$kid;
# write to $fh, if desired
}
last unless( @$readready || @$writeready );
}
for my $kid ( @kids ) {
next unless $kid;
my ($r, $w, $p, $i) = @$kid;
close $_ for ($r, $w);
if( waitpid( $p, 0 ) == -1 ) {
warn "waitpid($p): $!\n";
next;
}
warn "kid $i exited with code ", $?>>8 if $?&0xFF00;
warn "kid $i died from signal ", $?&255 if $?&0x00FF;
print"kid $i exited ok\n" if !$?;
}
}
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Thu, 19 Jul 2001 03:31:11 +0200
From: "Carsten Menke" <bootsy52@gmx.net>
Subject: Re: GnuPG encrypting from STDIN in CGI
Message-Id: <20010719.033110.1875335928.2067@gmx.net>
>
> Perhaps the GnuPG module is what you need.
> http://search.cpan.org/search?mode=module&query=GnuPG
>
And this is what I could not use, because the provider doesn't allow to
install any modules nor does he have the gnupg.pm .
I found out more meanwhile the actual problem I got here is, how to open
a process (piping) for reading and writing? Because in the first instance
I need to write to the process in the way of open(PIPE, "| $command $options -")
and then write to this PIPE
print PIPE $input;
No I have to get the input using a PIPE opened to read. But if I reopen
PIPE, STDOUT is gone because there is no query. BTW, the code I used here
is not secure, and this is also concerning me.
Carsten
------------------------------
Date: Thu, 19 Jul 2001 06:59:26 +0200
From: Philip Newton <pne-news-20010719@newton.digitalspace.net>
Subject: Re: Including flock in code while developing in Windows for Unix??
Message-Id: <6opcltcn0rt9t4mhe39cuo72dtl29st9s9@4ax.com>
On Mon, 16 Jul 2001 21:18:15 -0400, David Coppit <newspost@coppit.org>
wrote:
> Bart Lateur wrote:
> > David Coppit wrote:
> >
> >>Happily Windows can do flock for 5.6.0 versions and better.
> >
> > AFAIK, NT only. It still barfs on Win9x.
>
> Okay. I thought fork simulation was part of the MS contribution to Perl.
Er, 'fork' ne 'flock'.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Thu, 19 Jul 2001 01:28:26 -0400
From: Joe Kline <jkline@one.net>
Subject: Re: Iterating Nested Hashes
Message-Id: <3B566FFA.A4FBDA1A@one.net>
Michael Carman wrote:
> Andrew Bell wrote:
> >
> > Say I have a hash like:
> >
> > $foo{$a}{$b}{$c}
> <SNIP>
> The typical idiom to iterate over your nested hash is this:
>
> foreach my $key1 (keys %foo) {
> foreach my $key2 (keys %{$foo{$key1}}) {
> foreach my $key3 (%{$foo{$key1}{$key2}}) {
> # do something with $foo{$key1}{$key2}{$key3}
> <SNIP>
> But if you want to keep yours, that's fine, just fix the error:
>
> while (my ($k1, $v1) = each %foo) {
> while (my ($k2, $v2) = each %$v1) {
> while (my ($k3, $v3) = each %$v2) {
> # do something...
I would say that the above is a better idiom. As you walk each level of the
hash you are directly referencing a specific level of the hash as opposed to
having to walk the references each time.
------------------------------
Date: 19 Jul 2001 01:39:49 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: map and split combination slow
Message-Id: <9j5dp5$kss$1@bob.news.rcn.net>
Randy Da.y <rpdaly@bigfoot.com> wrote:
> I'm processing a DB extraction file. This is a flat text file with
> fixed length fields. I'm using the following segment within a
> format_date function:
> if ($date =~ m/\s/) {
> map{ $len += $hlen{$_} } split //, $fmt2;
> return($datestr = " " x $len);
> }
> This is running extremely slow. When left in the function, 10K records
> are processed in approximately 3 minutes 20 seconds, without it, it is
> 25 seconds.
> Suggestions, comments?
Iterating over individual characters, as you're doing in your map, is
rather slow in Perl and is often a sign that you're "thinking in C."
Using map in a void context is frowned upon; use for() if you're just
applying some operation to each element of a list without creating a new
list.
It would help to see more of your code. I can only guess that $fmt2 is
some sort of format descriptor string where each character signifies a
particular data type. If that's the case, it's likely that for any given
file, there are only going to be a few unique variants of that string and
that you'd get a significant speedup if you remember the lengths of format
strings that you've already seen before rather than recalculating them
each time.
------------------------------
Date: Thu, 19 Jul 2001 02:11:01 GMT
From: Randy Daly <rpdaly@bigfoot.com>
Subject: Re: map and split combination slow
Message-Id: <v3gclt8gjfhqfttgdupv6of3lrhj889sk3@4ax.com>
Eric,
You're correct in your assumption about $fmt2. This function accepts 3
arguments, $date := Date to convert, $fmt1 := input format of $date,
$fmt2 := output format for $date. If $date is passed with a space
anywhere in the string, I assume it is a bad date and pass it back,
all spaces to the length of the requested output format. $hlen is a
hash with the lengths of the date parts. The date parts (and supported
format specifiers) are m = 2, d = 2, y = 2, Y = 4, / = 1. I hope that
helps. I like your suggestion about remembering. Can you explain?
Thanks.
On 19 Jul 2001 01:39:49 GMT, ebohlman@omsdev.com (Eric Bohlman) wrote:
>Randy Da.y <rpdaly@bigfoot.com> wrote:
>> I'm processing a DB extraction file. This is a flat text file with
>> fixed length fields. I'm using the following segment within a
>> format_date function:
>> if ($date =~ m/\s/) {
>> map{ $len += $hlen{$_} } split //, $fmt2;
>> return($datestr = " " x $len);
>> }
>> This is running extremely slow. When left in the function, 10K records
>> are processed in approximately 3 minutes 20 seconds, without it, it is
>> 25 seconds.
>
>> Suggestions, comments?
>
>Iterating over individual characters, as you're doing in your map, is
>rather slow in Perl and is often a sign that you're "thinking in C."
>
>Using map in a void context is frowned upon; use for() if you're just
>applying some operation to each element of a list without creating a new
>list.
>
>It would help to see more of your code. I can only guess that $fmt2 is
>some sort of format descriptor string where each character signifies a
>particular data type. If that's the case, it's likely that for any given
>file, there are only going to be a few unique variants of that string and
>that you'd get a significant speedup if you remember the lengths of format
>strings that you've already seen before rather than recalculating them
>each time.
------------------------------
Date: 19 Jul 2001 03:11:41 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: map and split combination slow
Message-Id: <9j5j5d$ei1$3@bob.news.rcn.net>
Randy Daly <rpdaly@bigfoot.com> wrote:
> You're correct in your assumption about $fmt2. This function accepts 3
> arguments, $date := Date to convert, $fmt1 := input format of $date,
> $fmt2 := output format for $date. If $date is passed with a space
> anywhere in the string, I assume it is a bad date and pass it back,
> all spaces to the length of the requested output format. $hlen is a
> hash with the lengths of the date parts. The date parts (and supported
> format specifiers) are m = 2, d = 2, y = 2, Y = 4, / = 1. I hope that
> helps. I like your suggestion about remembering. Can you explain?
Use a hash whose keys are date format strings and whose values are
appropriate-length strings of spaces. If you find a space in $date, check
to see if the hash has a value for $fmt2. If it does, return it; if not,
calculate the appropriate length string of spaces, store it in the hash
value for $fmt2, and return it.
The hash needs to persist across calls to your function, but should be
private to it; the best way to achieve that is to declare the hash in a
block wrapped around your function.
If you know in advance that there are only a handful of possible date
formats, precompute them by hand and populate the hash with literals.
------------------------------
Date: Thu, 19 Jul 2001 03:56:44 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: map and split combination slow
Message-Id: <3B565ACB.B9A2C4DF@acm.org>
"Randy Da.y" wrote:
>
> I'm processing a DB extraction file. This is a flat text file with
> fixed length fields. I'm using the following segment within a
> format_date function:
> if ($date =~ m/\s/) {
> map{ $len += $hlen{$_} } split //, $fmt2;
> return($datestr = " " x $len);
> }
> This is running extremely slow. When left in the function, 10K records
> are processed in approximately 3 minutes 20 seconds, without it, it is
> 25 seconds.
>
> Suggestions, comments?
This is about twice as fast:
if ( $date =~ m/\s/ ) {
$len += $hlen{substr $fmt2, $_, 1} for 0 .. length($fmt2) - 1;
return $datestr = " " x $len;
}
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 19 Jul 2001 04:12:18 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: map and split combination slow
Message-Id: <x7u209v9p9.fsf@home.sysarch.com>
>>>>> "JWK" == John W Krahn <krahnj@acm.org> writes:
JWK> "Randy Da.y" wrote:
>>
>> I'm processing a DB extraction file. This is a flat text file with
>> fixed length fields. I'm using the following segment within a
>> format_date function:
>> if ($date =~ m/\s/) {
>> map{ $len += $hlen{$_} } split //, $fmt2;
>> return($datestr = " " x $len);
>> }
>> This is running extremely slow. When left in the function, 10K records
>> are processed in approximately 3 minutes 20 seconds, without it, it is
>> 25 seconds.
>>
>> Suggestions, comments?
JWK> This is about twice as fast:
JWK> if ( $date =~ m/\s/ ) {
JWK> $len += $hlen{substr $fmt2, $_, 1} for 0 .. length($fmt2) - 1;
JWK> return $datestr = " " x $len;
JWK> }
why are you (and the OP) doing an assignment in the return statement?
and there are much simpler ways to do formatting. here is one:
this sub get a hash with various parts including a % style format
string. so it does a s/// with a func call in the replacement
sub _format_entry {
my( $entry ) = @_ ;
my $formatted = $entry->{'format'} ;
$formatted =~ s/%(.)/_format_field( $entry, $1 )/seg ;
return $formatted ;
}
this hash converts the % key to the key in the entry hash
my %letter_to_key = (
'T' => 'text',
't' => 'time',
'L' => 'label',
'l' => 'level',
'H' => 'hub_name',
'h' => 'host_name',
'P' => 'program_name',
) ;
this is longer then this snippet but this is the most common expansion
stuff.
sub _format_field {
my( $entry, $letter ) = @_ ;
if ( my $key = $letter_to_key{ $letter } ) {
return $entry->{$key} ;
}
<snip>
this is fast, simple and easy to add to. i added 2 new fields just by
stuffing the entry hash with the values and 2 new entries in the hash.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: Wed, 18 Jul 2001 23:35:18 -0400
From: Chris Micallef <cmicallef@playground.net>
Subject: Re: Obtaining remote users ip
Message-Id: <3B565576.C7533512@playground.net>
I'm not sure how this is relevant to the original question.
The reason I want to understand this is I am writing a simple counter that will
only increment on hits from unique ip's for that day/week/month/or year
(depending on settings).
Walter Hafner wrote:
> gorilla@elaine.furryape.com (Alan Barclay) writes:
>
> > In article <srj66csm32i.fsf@w3proj1.ze.tu-muenchen.de>,
> > Walter Hafner <hafner-usenet@ze.tu-muenchen.de> wrote:
> > >Hiho!
> > >
> > >Remember, that most Proxies rewrite the IP address and send the original
> >
> > s/most/some/;
> >
> > The original client might not even have an IP address, and even if it
> > does, it may be a private address, which has no meaning outside
> > of a private network.
>
> That's right. But for logging purposes i'd rather have a few private
> network addresses in my database than just the addresses of the AOL
> proxies. :-)
>
> And you can always filter out _proper_ private addresses by their
> netmask.
>
> Regards
>
> -Walter
------------------------------
Date: 19 Jul 2001 05:29:50 GMT
From: dkcombs@panix.com (David Combs)
Subject: Re: Parsing an html document for the title (don't flame, I have searched around)
Message-Id: <9j5r8e$4hj$1@news.panix.com>
In article <tkcc7t98ph3256@corp.supernews.com>,
Craig Berry <cberry@cinenet.net> wrote:
>dave (usted@cyberspace.org) wrote:
SNIP
>
>Prettier way to do it:
>
> print <<STUFF;
><h3>$title</h3>
><a href="$url">$url</a>
><br><br>
>STUFF
>
> But I'd 'use CGI qw(:all)' and then do this:
>
> print h3($title),
> a({ href => $url }, $url),
> br, br;
>
Totally different subject: what is that <br><br>?
Is it supposed to be a synonym for "<p>"?
The reason I ask is the browser I use, LYNX, does NOT think
that way. Two breaks are two breaks, period. Same as ONE
<br>. Generates NO blank line.
Now, I notice that netscape DOES pretend that the double-br
is a <p>.
If a page I'm looking at with lynx has the double-br (and
lots do!), I find that I have to get the original html
out into a file, and change the double-brs to p's. After
that, it looks ok, paragraphs separated by a blank line.
Since you used the double-br, maybe you can explain
to me what it's all about.
Thanks!
David
------------------------------
Date: Thu, 19 Jul 2001 03:49:07 GMT
From: Confused @ Times <confused@times.doh>
Subject: Re: Replacing a specific line
Message-Id: <MPG.15c006a89b01b6e8989681@news.telusplanet.net>
Thanks to all, specifically John - I got it working.
------------------------------
Date: 19 Jul 2001 09:00:34 +0200
From: Walter Hafner <hafner-usenet@ze.tu-muenchen.de>
Subject: Re: Request for Comments ... ConvertColorspace.pm
Message-Id: <srjvgkpz9m5.fsf@w3proj1.ze.tu-muenchen.de>
Melissa Niles <mniles@itm.com> writes:
> I would like comments on the following module. It is not completed as of
> yet.
>
> It's purpose is to allow the retrieval of colorspace values from a
> different set of colorspace values, ie: get CMYK values from a set of
> RGB values.
For all questions regarding color spaces / color science etc. please
have a look at the sci.engr.color newsgroup. They have very good FAQs
over there. I can especially recommend all the Poynton papers.
Color conversion is a non trivial task. I should know. I wrote a PhD
thesis about adaptive color classification. :-)
Have a look at my thesis bibliography (german):
http://www.tu-muenchen.de/~hafner/diss/node91.html
For color conversions I'd read Hun95, Jac93, Jai89, the OKS80 paper,
Poy96 and maybe Mac85 (all in english!).
The "bible" of color science is WS82 - about 1300 pages for about
100$. ;-)
(Ok, so CMYK / RGB conversion isn't very complicated, but as soon as you
add conversions based upon XYZ or the CIE color spaces you're in
trouble without guidance).
> As far as I can find, there's no other module like it, but I have seen
> others with a need for this sort of module.
Maybe that's because Perl isn't very much used in the color science
world. Since the whole topic is highly numeric, they normally use Maple,
Mathemetica and especially Matlab! You should have no trouble finding
Matlab modules for color conversion. I even wrote one myself, long, long
ago. If you port one of them to Perl always remember that floating point
arithmetic in Perl isn't nearly as accurate as it is in the math tools!
Regards
-Walter
PS: before you ask me for sources etc: I have left the color science
scene about 3 years ago and changed my employer twice. I don't have
access to my program sources anymore.
------------------------------
Date: Thu, 19 Jul 2001 03:04:34 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Scrollable lists in console
Message-Id: <3B564E3F.56EC6727@rochester.rr.com>
Santtu wrote:
...
> Does anyone know how to create scrollable lists in console window?
> The idea is that there can be atleast 250 lines where user must select one
> and then go on with other list.
>
> Where can I get the size of my console window. Number of lines???
...
> Santtu
What "console window" are you running? What is your OS? And: What is
your Perl question? Sounds like maybe you want to consider use Tk; .
--
Bob Walton
------------------------------
Date: Thu, 19 Jul 2001 03:31:27 +0000 (UTC)
From: see-sig@from.invalid (David Efflandt)
Subject: Re: Scrollable lists in console
Message-Id: <slrn9lcl4e.61l.see-sig@typhoon.xnet.com>
On Wed, 18 Jul 2001 11:53:02 GMT, Santtu <santtu.nyrhinen@nokia.com> wrote:
>
> Does anyone know how to create scrollable lists in console window?
> The idea is that there can be atleast 250 lines where user must select one
> and then go on with other list.
What OS? While not a Perl solution, I have used the Unix 'dialog' program
from Perl to pick (by number) from a long list of active Quake servers,
and then launch Quake with the selected server plugged into the
commandline.
> Where can I get the size of my console window. Number of lines???
The following method works for Linux and Solaris:
# Screen & menu size
if(($_ = `stty`) =~ /rows\s+=\s+(\d+);.*columns\s+=\s+(\d+);/) {
($rows,$cols) = ($1,$2);
} elsif (($_ = `stty size`) =~ /^(\d+)\s+(\d+)/) {
($rows,$cols) = ($1,$2);
} else {
$rows = $ENV{LINES} if $ENV{LINES};
$cols = $ENV{COLUMNS} if $ENV{COLUMNS};
}
$rows = 25 unless $rows;
$cols = 80 unless $cols;
--
David Efflandt (Reply-To is valid) 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, 19 Jul 2001 03:26:11 GMT
From: jay <seandarcy@hotmail.com>
Subject: where is the "standard library"
Message-Id: <3B56549B.8070702@hotmail.com>
I'm running perl 5.6.1 on rh7.1. In trying to install a ghostscript rpm,
I got the error message that it couldn't find getopts.pl.
But:
[root@localhost root]# locate getopts.pl
/usr/lib/perl5/5.6.1/getopts.pl
So I figured there's something wrong with the rpm, but....
[root@localhost root]# perl getopts.pl
Can't open perl script "getopts.pl": No such file or directory
I don't have PERLLIB or PERL5LIB defined. As I read the docs, without
these defined, perl supposed to look in the "standard library". If
/usr/lib/perl5/5.6.1 isn't the standard library, what is? where is it set?
thanks
jay
------------------------------
Date: Thu, 19 Jul 2001 04:02:01 GMT
From: Akira Yamanita <ayamanita.nospam@bigfoot.com>
Subject: Re: where is the "standard library"
Message-Id: <3B565BAC.1CBF7CE7@bigfoot.com>
jay wrote:
>
> I'm running perl 5.6.1 on rh7.1. In trying to install a ghostscript rpm,
> I got the error message that it couldn't find getopts.pl.
>
> But:
> [root@localhost root]# locate getopts.pl
> /usr/lib/perl5/5.6.1/getopts.pl
>
> So I figured there's something wrong with the rpm, but....
>
> [root@localhost root]# perl getopts.pl
> Can't open perl script "getopts.pl": No such file or directory
Of course not. getopts.pl is not in /root which is where you were
trying to access it. You didn't specify a path nor did you change
directories to /usr/lib/perl5/5.6.1
> I don't have PERLLIB or PERL5LIB defined. As I read the docs, without
> these defined, perl supposed to look in the "standard library". If
> /usr/lib/perl5/5.6.1 isn't the standard library, what is? where is it set?
perl -e 'print join("\n",@INC);'
------------------------------
Date: Thu, 19 Jul 2001 03:24:49 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Yet Another use/require Question
Message-Id: <slrn9lcko1.1rf.mgjv@verbruggen.comdyn.com.au>
On Wed, 18 Jul 2001 22:19:48 GMT,
David Marshall <marshall@chezmarshall.com> wrote:
> disclaimer: yes, i know that use blah (); is the same as begin { require
> blah;}.
Yes, it is, but just for clarity for readers who didn't notice:
use Module;
is equivalent to
BEGIN { require Module; import Module LIST; }
use Module ();
is equivalent to (as you say)
BEGIN { require Module }
That import is important, and you sem to know about it, judging from
your first question below.
> * Assuming that a module doesn't @ISA Exporter and I know I always want
> to load it (such at the top of another module), is there ever a good
> reason to prefer "require" to "use"?
First of all: It is a bit silly to exclude the two most important
reasons why one would use require over use, when asking this question,
of course.
The two most common reasons are probably (as you indicate, implicitly):
1) You might not always want to load a module.
2) You might want to avoid the import, although you can also do that
by specifying the empty list, as noted above.
In general, you'd use require when you want to avoid the compile time
actions of the BEGIN block. Some reasons might be:
You might want to delay the loading of the module until it is needed,
so that your program starts faster. Of course, you will pay that
penalty a bit later during run time anyway.
You might not know the name of a module until run time (which probably
could be fixed in other ways, but that's not the issue).
You might want to check whether a module is available before loading
it. You can do this at compile time as well, but at run time you have
more possibilities in dealing with it more gracefully, especially if
you want to inform the user, and maybe get some feedback.
> * Making the above question more general, if I know I always want to load
> a module, is there a good reason not to always load it with "use" and
> explicitly control what gets imported to my namespace?
I can't think of a way how use and require followed by import differ
in what gets imported into your name space.
use Module () <=> BEGIN{ require Module }
use Module <=> BEGIN{ require Module; import Module }
use Module LIST <=> BEGIN{ require Module; import Module LIST }
The only difference I can see is that one's a run time action, and the
other a compile time action.
> * For modules that I know I always want to load, is there any drawback to
> replacing every appearance of "require Furgle;" with "use Furgle ();" ?
None that I can think of, apart from what's already said, but I may be
missing something.
> I have observed in .pm files under my /usr/local/lib/perl5/5.6.1, there
> are 33 lines that match '^use Exporter' and 55 lines that match '^require
> Exporter'. Other than personal preference, is there any real
> significance to the choice between "use" and "require" in this instance?
Not really. The 'require Exporter' is a bit of a historical thing,
people copying from the manual page, I suppose.
> OK, now suppose I make some awesome decision about whether module A
> should load module B via "use" or "require." Is such a decision
> overridden by the decision of whoever loads module A? That is, if A
> loads B via "use," but A is loaded by "require," B doesn't get loaded
> until "require A;" is executed, correct? And if A loads B via "require,"
> but A is loaded with "use," it doesn't really matter how A loads B,
> because all that happens within a BEGIN block anyway. Correct?
I have trouble following what you are trying to say here. Probably my
fault. I've got a tooth ache, and I lose concentration after long
posts..
Martien
--
Martien Verbruggen |
Interactive Media Division | Freudian slip: when you say one thing
Commercial Dynamics Pty. Ltd. | but mean your mother.
NSW, Australia |
------------------------------
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 1332
***************************************