[17477] in Perl-Users-Digest
Perl-Users Digest, Issue: 4897 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 15 21:05:39 2000
Date: Wed, 15 Nov 2000 18:05:10 -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: <974340310-v9-i4897@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 15 Nov 2000 Volume: 9 Number: 4897
Today's topics:
Alternative to ?? (Was: Re: Looking for idiom ...) <tim@ipac.caltech.edu>
Batch inserting into Oracle with Perl davewang168@my-deja.com
Re: Document management question! (Michael Koehne)
Re: Finer points of lists, etc. (John J. Trammell)
Re: Finer points of lists, etc. <sumus@aut.dk>
Re: Finer points of lists, etc. <jeffross@bendcable.com>
Re: Finer points of lists, etc. <sumus@aut.dk>
Re: Finer points of lists, etc. <jeff@vpservices.com>
Re: Finer points of lists, etc. (Logan Shaw)
Re: Finer points of lists, etc. <jeffross@bendcable.com>
Re: giving , another name, like "and" for && <ren.maddox@tivoli.com>
Go from decimal to hexadecimal. fallenang3l@my-deja.com
Re: Go from decimal to hexadecimal. (Logan Shaw)
Re: HTTP::Request's header code v. the true http error <brondsem@my-deja.com>
Re: IP geography <elephant@squirrelgroup.com>
Re: Mail <mesarch@ee.net>
Re: Mail <mesarch@ee.net>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 16 Nov 2000 17:07:50 -0800
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Alternative to ?? (Was: Re: Looking for idiom ...)
Message-Id: <3A1484E6.9D0300FF@ipac.caltech.edu>
Ren Maddox wrote:
>
> I don't remember for sure (and didn't bother to check, shame on me)
> but was there discussion about the alternative of having defined be
> clever about what it returns? In particular, I would want it to
> pass through the tested value, but with a special boolean property of
> true if the value is not true. With this, you could simply write:
>
> $sh->{password} = defined shift @args || $ENV{DBI_PASS};
>
> Currently, as long as the value shifted off of @args is not undef (or
> there isn't a value to shift off), then this will set the password to
> 1. I'm suggesting that it should set the password to the value
> shifted, even if that value is "", "0" or 0.
>
> I think this would obviate the need for the ?? operator.
Wow. I was thinking about this same solution a few days ago, but instead of
altering defined, I decided to invent a new operator called !? that behaves just
as you describe, so that one could do '$x !?= $y' with it. I gave up my
blue-skying and returned to work because
1 - Having a scalar be true but contain 0 or "" would be confusing. A simple
print statement would no longer tell the tale about that variable.
2 - It would require altering the behavior of all booleans.
3 - This special boolean property would either have to be viral or have some
sort of special, fleeting existence in temporary work space. E.g. suppose you
did
my $y = 0;
my $x = !? $y;
Does $x now have the special boolean property of "0 but true", or does that
property disappear when crossing an "="? Suppose $x keeps the special property
(it's viral). Then what about
my $z = $x + 1;
if(! $z) { ... }
Does "..." get executed or not?
It's tough for me imagine producing DWIMery out of this.
If !? (or a modified defined) is *not* viral, then it would be, I think, a
unique kind of operator in Perl. I wonder how to document it so's not to
confuse.
I can see precedent for #1, because objects with overloaded operators can behave
in similarly mysterious ways. (I'd bet you could even implement alot of this
that way). That doesn't make it pretty though. #2 is "just an implementation
detail," but knowing nothing about internals, it seems like it could get messy.
If we choose the nonviral answer to #3, it could work but be confusing, and
maybe tough to implement. All in all I like it better than the proposed behavior
of ??, but still hope for something better.
The other solution I've seen bandied about was subroutines whose args were
evaluated lazily, so one could short-circuit with the equivalent of
sub first_defined { for (@_) { return if defined } return; }
$x = first_defined $ARGV[0], getopts($opts), "default.file";
... and not have to execute getopts unless $ARGV[0] wasn't defined.
--
-- Tim Conrow tim@ipac.caltech.edu |
------------------------------
Date: Wed, 15 Nov 2000 23:40:49 GMT
From: davewang168@my-deja.com
Subject: Batch inserting into Oracle with Perl
Message-Id: <8uv6u1$3ks$1@nnrp1.deja.com>
Hi,
I am building a simple web log parsing program that will insert the IP
addresses of my users into an Oracle 8i database.
I've tried the obvious: "insert into IPtable (IP) values ($IP)"
.. and it takes forever to go through a 10mb log file.
I've heard there's a faster way to do this using batch inserts. Has
anyone had experience doing something similar? If so, I'd greatly
appreciate any tips.
Thanks!
David
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 16 Nov 2000 01:11:49 +0100
From: not-for-mail@copyleft.de (Michael Koehne)
Subject: Re: Document management question!
Message-Id: <5o8vu8.618.ln@bakunin.copyleft.de>
Gary <gary@dkstat.com> wrote:
> I work for a company that runs the following environment:
> OS: Freebsd for Intel machines
> Database: Mysql
> Languages: Perl, C
nice !
> 1. take MS/word docs and save them to a database.
> 4. Be able to print the documents back out in MS/Word format.
not so nice, but I can think about a solution, that is a good half Perl.
*hm* my advise is : save the documents as RFT. They'll still be in
M$/Word format. Use AbiWord to cleanup the docs. Save the docs in
AbiWord to get an XML version of your docs. Use one of the many XML
tools published on CPAN (hint to XML::Digest ;-) to extract the
valuable information from the docs.
Now about MySQL. This is a nice beast, but MySQL is a !RELATIONAL!
database, so its good for tables. You need a full text retrival
system to do your queries. Use something like "glimpse" and parse
its result by Perl. Use MySQL where its good for. To store the
metainformation's for each document and the filename.
Bye Michael
--
mailto:kraehe@copyleft.de UNA:+.? 'CED+2+:::Linux:1.2:13'UNZ+1'
http://www.xml-edifact.org/ CETERUM CENSEO MSDOS ESSE DELENDAM
------------------------------
Date: 15 Nov 2000 23:23:26 GMT
From: trammell@nitz.hep.umn.edu (John J. Trammell)
Subject: Re: Finer points of lists, etc.
Message-Id: <slrn915cbk.lp2.trammell@nitz.hep.umn.edu>
On Wed, 15 Nov 2000 14:20:44 -0800, Jeff Ross <jeffross@bendcable.com> wrote:
>Sort of a newbie stuck on list and string nuances.
>
>@MyList = (30188, $A01, 3644, $A02, 4080, $B03, 2976, $B09, 2912)
>
>I want to take this list (above) and make the $# equal to the value on
>its left side.
Please clarify what you mean by "$#". $# is a deprecated special
variable, do you mean $#MyList? Perhaps you want to do something
to (e.g. print) each member of array @MyList?
You also might want to "perldoc -q 'list and an array'". :-)
--
John J. Trammell
johntrammell@yahoo.com
------------------------------
Date: 16 Nov 2000 00:33:58 +0100
From: Jakob Schmidt <sumus@aut.dk>
Subject: Re: Finer points of lists, etc.
Message-Id: <hf58lsih.fsf@macforce.sumus.dk>
Jeff Ross <jeffross@bendcable.com> writes:
> Sort of a newbie stuck on list and string nuances.
>
> @MyList = (30188, $A01, 3644, $A02, 4080, $B03, 2976, $B09, 2912)
>
> I want to take this list (above) and make the $# equal to the value on
> its left side. I then want to print the results to a text file. My
> results should look like this:
>
> $A01 = 30188
> $A02 = 3644
> $B03 = 2976
> $B09 = 2912
if I get you right you want to output the names of the variables without
hardcoding them all. There\s no easy way to do that.
The assignment task is not easy either if the list is all you\ve got, since
the list elements become copies of whatever was in the variables.
But to me it all looks like a symptom of a poor solution. What you\re likely to
actually want is a hash. Could you give us some more input?
--
Jakob Schmidt
http://aut.dk/orqwood
etc.
------------------------------
Date: Wed, 15 Nov 2000 15:41:04 -0800
From: Jeff Ross <jeffross@bendcable.com>
Subject: Re: Finer points of lists, etc.
Message-Id: <F8694E7FE41DC8AC.B6D7806713A0AB1A.96767961D9DC6E9B@lp.airnews.net>
>Please clarify what you mean by "$#". $# is a deprecated special
>variable, do you mean $#MyList? Perhaps you want to do something
>to (e.g. print) each member of array @MyList?
>
I;m sorry for the confusion. $# would have been the value in the
second slot of my string, in this case $A01.
-Jeff
------------------------------
Date: 16 Nov 2000 00:45:16 +0100
From: Jakob Schmidt <sumus@aut.dk>
Subject: Re: Finer points of lists, etc.
Message-Id: <g0kslrzn.fsf@macforce.sumus.dk>
Jeff Ross <jeffross@bendcable.com> writes:
> I;m sorry for the confusion. $# would have been the value in the
> second slot of my string, in this case $A01.
String? Don\t you mean array?
As I said that value would be a copy of the initial value held by $A01
which probably isn\t what you want.
What do you want?
--
Jakob Schmidt
http://aut.dk/orqwood
etc.
------------------------------
Date: Wed, 15 Nov 2000 15:51:34 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Finer points of lists, etc.
Message-Id: <3A132186.66C2752@vpservices.com>
Jeff Ross wrote:
>
> Sort of a newbie stuck on list and string nuances.
>
> @MyList = (30188, $A01, 3644, $A02, 4080, $B03, 2976, $B09, 2912)
>
> I want to take this list (above) and make the $# equal to the value on
> its left side. I then want to print the results to a text file. My
> results should look like this:
>
> $A01 = 30188
> $A02 = 3644
> $B03 = 2976
> $B09 = 2912
Basically what you want to do is associate a tag with a number. That
means that instead of using an array, you should use an associative
array, also called a hash. This prints out your desired outcome and
also instead of creating $A01 (which is bad), it creates $hash{A01}
which is better:
my %hash = reverse qw(30188 A01 3644 A02 4080 B03 2976 B09 2912 C01);
for my $key(sort keys %hash) {
print "$key = $hash{$key}\n";
}
> My actual list is much longer, up to 99 potential variables.
Doesn't matter. The snippet above will handle that, no problem.
--
Jeff
------------------------------
Date: 15 Nov 2000 18:01:20 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Finer points of lists, etc.
Message-Id: <8uv84g$697$1@doughboy.cs.utexas.edu>
In article <63E1572557153C26.389422993BBF3B6D.8AA3E7D00355A0D7@lp.airnews.net>,
Jeff Ross <jeffross@bendcable.com> wrote:
>Sort of a newbie stuck on list and string nuances.
>
>@MyList = (30188, $A01, 3644, $A02, 4080, $B03, 2976, $B09, 2912)
>
>I want to take this list (above) and make the $# equal to the value on
>its left side. I then want to print the results to a text file. My
>results should look like this:
>
>$A01 = 30188
>$A02 = 3644
>$B03 = 2976
>$B09 = 2912
You have $A01 and $A02 paired up with the numbers before them and $B03
and $B09 paried up with the numbers after them. Is that intentional?
Anyway, one way to do what I *think* you're asking is this:
@MyList = qw{ 30188 $A01 3644 $A02 4080 $B03 2976 $B09 2912 };
while ( ($thing2, $thing1) = splice (@MyList, 0, 2) )
{
print "$thing1= $thing2\n";
}
This treats the things you've given, which look like variables, as just
plain old strings that happent to begin with dollar signs. I'm not
sure if that's what you want or not.
- Logan
------------------------------
Date: Wed, 15 Nov 2000 16:08:13 -0800
From: Jeff Ross <jeffross@bendcable.com>
Subject: Re: Finer points of lists, etc.
Message-Id: <2BA16F35F86A3A2E.16BC7D8E18613252.565A9B05387E460E@lp.airnews.net>
On 16 Nov 2000 00:45:16 +0100, Jakob Schmidt <sumus@aut.dk> wrote:
>? Don\t you mean array?
I guess I do.
------------------------------
Date: 15 Nov 2000 12:38:30 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: giving , another name, like "and" for &&
Message-Id: <m3bsvhf5cp.fsf@dhcp11-177.support.tivoli.com>
sthoenna@efn.org (Yitzchak Scott-Thoennes) writes:
> In article <8tjmck$ejj$1@lublin.zrz.tu-berlin.de>,
> anno4000@lublin.zrz.TU-Berlin.DE (Anno Siegel) wrote:
> > The standard comma operator (well, the list-building comma operator)
> > inserts both its (scalar) operands into the list being built. "Then",
> > however, must see its left operand as a list in which *not* to include
> > the right operand(s). But if the left operand is a list, the empty
> > list is a possibility, so the case of an empty operand must be allowed.
>
> Why? I would expect a low-precedence replacement for ',' named 'then'
> to *not* discard the left operand in list context.
> E.g. @a = ('a' then 'b') would put two scalars in @a.
The parens give the behavior you expect, and even the comma gives the
behavior Anno describes when simply used with assignment, as
assignment is higher precedence than comma. The difference would be
with list operators, which have lower precedence than comma, but
higher than the proposed "then" operator. So:
push @array, join "", split /:/, $string1 then then "\n";
would group like:
push @array, (join "", (split /:/, $string1) then) then "\n";
and would parse as:
push @array, join("", split /:/, $string1), "\n";
Basically, Anno is recommending that "then" force an implied close to
the preceding list. But since lists within lists simply flatten,
this:
@a = ('a' then 'b')
becomes:
@a = (('a'), 'b')
which is just
@a = ('a', 'b')
while:
@a = sort qw/apple banana pear/ then sort qw/corn beans potatoes/;
keeps the fruits (sorted) before all of the vegetables (also sorted).
The same as:
@a = sort(qw/apple banana pear/), sort qw/corn beans potatoes/;
Of course, the truth of the matter is that all of these things can be
solved with parens. But the same was true when "and", "or" and the
others were added. To me, this seems like a natural thing to include
with those. And for those of us that prefer the parens to be reserved
for Lisp, it helps in lots of situations. My favorite is adding a
newline at the end of a print statement without the join getting in the
way:
print join ":", @array then "\n";
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Thu, 16 Nov 2000 00:31:13 GMT
From: fallenang3l@my-deja.com
Subject: Go from decimal to hexadecimal.
Message-Id: <8uv9sh$66h$1@nnrp1.deja.com>
I know how to do that using (s)printf, but it works only for one value.
For example:
$myval = 20;
printf "%x", $myval;
That works, but the problem is there may be a huge amount of decimal
number to convert into hexadecimal, and printf isn't cutting it. Can
this be achieved by either pack or unpack? If yes then how? Thank you.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 15 Nov 2000 18:54:28 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Go from decimal to hexadecimal.
Message-Id: <8uvb84$6in$1@doughboy.cs.utexas.edu>
In article <8uv9sh$66h$1@nnrp1.deja.com>, <fallenang3l@my-deja.com> wrote:
>I know how to do that using (s)printf, but it works only for one value.
>For example:
>
>$myval = 20;
>printf "%x", $myval;
>
>That works, but the problem is there may be a huge amount of decimal
>number to convert into hexadecimal, and printf isn't cutting it.
So put it in a loop. Or, put it in a call to map():
@x = ( 0 .. 100 );
@y = map (sprintf ("%x", $_), @x);
foreach (@y) { print "$_\n"; }
Hope that helps.
- Logan
------------------------------
Date: Thu, 16 Nov 2000 00:00:40 GMT
From: Dave Brondsema <brondsem@my-deja.com>
Subject: Re: HTTP::Request's header code v. the true http error code
Message-Id: <8uv835$4kv$1@nnrp1.deja.com>
In article <slrn9144se.gs3.mgjv@martien.heliotrope.home>,
mgjv@tradingpost.com.au wrote:
> On Wed, 15 Nov 2000 03:51:33 GMT,
> Dave Brondsema <brondsem@my-deja.com> wrote:
> > In article <8766lqos1z.fsf@limey.hpcc.uh.edu>,
> > Tony Curtis <tony_curtis32@yahoo.com> wrote:
> >>
> >> $ perldoc LWP::UserAgent
> >>
> >> see redirect_ok()
> >
> > I get this error:
> >
> > Can't call method "method" on an undefined value at
> > C:/perl/site/lib/LWP/UserAgent.pm line 371.
> >
> > I added:
> > print $ua->redirect_ok();
> > $ua is a new LWP::UserAgent
> >
> > So I looked at UserAgent.pm and found this:
>
> Did you also look at the documentation?
Yes, I just didn't know what to do with it.
>
> # man LWP::UserAgent
> [snip]
> $ua->redirect_ok
> This method is called by request() before it tries to
> do any redirects. It should return a true value if a
> redirect is allowed to be performed. Subclasses might
> want to override this.
>
> The default implementation will return FALSE for POST
> request and TRUE for all others.
> [snip]
>
> In other words, subclass LWP::UserAgent, and define your own
> redirect_ok().
>
> #!/usr/local/bin/perl -wl
> use strict;
>
> package MYUA;
> use LWP::UserAgent;
> @MYUA::ISA = qw(LWP::UserAgent);
>
> sub redirect_ok { 0 }
>
> package main;
> use HTTP::Request;
>
> my $ua = MYUA->new() or die;
> my $req = HTTP::Request->new(GET => 'http://www.lego.com/lzedgo.htm');
> my $resp = $ua->request($req);
> print $resp->code();
>
> __END__
I understand now. Thanks!
> Martien
> --
> Martien Verbruggen |
> Interactive Media Division | The gene pool could use a little
> Commercial Dynamics Pty. Ltd. | chlorine.
> NSW, Australia |
>
--
Dave Brondsema
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 16 Nov 2000 10:30:05 +1100
From: jason <elephant@squirrelgroup.com>
Subject: Re: IP geography
Message-Id: <MPG.147dc785da39d980989897@localhost>
Martien Verbruggen wrote ..
>On Tue, 14 Nov 2000 14:46:39 +1100,
> jason <elephant@squirrelgroup.com> wrote:
>> tcblue@my-deja.com wrote ..
>>>does any know if there is a perl module or script that can 'try' and
>>>detect the physical location of a given IP address or hostname? I
>>>found this site that gives a pretty good description of how to make an
>>>educated guess on it. I know there is no real solid way of doing this,
>>>but i'd like to start collecting geographical information of IP
>>>address. please let me know If you have any ideas or if there is
>>>already something out there that does this. Thanks,
>>
>> how closely do you want to be able to identify the IP ? .. and what's
>> this web site that you're talking about ?
<OT>
>> IP addresses can quite easily be classified by country of designation
>
>No, they cannot. There are a few IP addresses that have spatial meaning.
>The large bulk has none. Try to guess where IBM's IP addresses hang
>out, for example. Then guess again half a year later. Even a top level
>domain means not that much. Someone in Sydney, Australia and someone in
>Perth, Australia both have .au at the end of their hostname (unless they
>have a reverse DNS resolution to a .com, .nu, .to, or any other domain),
>but they're 3 time zones away from each other. There are other countries
>that span multiple time zones. Hell, someone in Honolulu could have an
>IP address that resolves to a .au TLD.
obviously I didn't make myself clear .. I certainly wasn't talking about
reverse resolution .. nor was I trying to imply that any useful
information about actual host location could be gleaned
I was asking about the details of this web site (in disbelief) and then
stating that all that can be (somewhat) reliably looked up is the
country of designation for a given IP address
as I'm sure you probably know .. you can very easily determine whether
an IP address was designated by ARIN or APNIC or RIPE .. and each of the
non US registries contain country information in the number record ..
making it "quite easy" to classify IP address by country of designation
</OT>
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Wed, 15 Nov 2000 19:31:08 -0500
From: "Mike Mesarch" <mesarch@ee.net>
Subject: Re: Mail
Message-Id: <8uv9v7$ku7$1@sshuraab-i-1.production.compuserve.com>
I probably spent an hour two looking. I just wasn't looking in the right
places.
-Mike
"Jeff Boes" <jboes@eomonitor.com> wrote in message
news:3a12ae51$0$35017$44a10c7e@news.net-link.net...
> Mike Mesarch wrote:
> >
> > Can someone provide me with some code to send a mail message in perl.
> > Typically I don't ask for something like this, but I have searched to no
> > avail on how to do this. In the doco it suggests using sendmail
> > Mail:Mailer. All i want to do is connect to a mail server
> > (smtp.something.com) and send a message. I haven't seen anything to do
> > this.
>
> Then you haven't really looked:
>
> perldoc -q 'send mail'
>
> --
> Jeff Boes <jboes@eoexchange.com> Tel: (616) 381-9889 x.18
> Sr. Software Engineer, EoExchange, Inc. http://www.eoexchange.com/
> Search, Monitor, Notify. http://www.eomonitor.com/
------------------------------
Date: Wed, 15 Nov 2000 19:31:42 -0500
From: "Mike Mesarch" <mesarch@ee.net>
Subject: Re: Mail
Message-Id: <8uva09$6bq$1@sshuraaa-i-1.production.compuserve.com>
Someone sent this to me. It works beautifully!
-Mike
$to=""; # Insert to
$from=""; # Insert from
$subject=""; # Insert subject
@body=(""); # Insert body
use Net::SMTP;
my $relay=""; #Insert smtp.something.com
my $smtp = Net::SMTP->new($relay);
die "Could not open connection: $!" if (! defined $smtp);
$smtp->mail($from);
$smtp->to($to);
$smtp->data();
$smtp->datasend("To: $to\n");
$smtp->datasend("From: $from\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("\n");
foreach(@body) {
$smtp->datasend("$_\n");
}
$smtp->dataend(); # Note the spelling, no "s"
$smtp->quit;
"Mike Mesarch" <mesarch@ee.net> wrote in message
news:8us8gt$29i$1@sshuraab-i-1.production.compuserve.com...
> Can someone provide me with some code to send a mail message in perl.
> Typically I don't ask for something like this, but I have searched to no
> avail on how to do this. In the doco it suggests using sendmail
> Mail:Mailer. All i want to do is connect to a mail server
> (smtp.something.com) and send a message. I haven't seen anything to do
> this.
> Thanks!
> Mike
>
>
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 4897
**************************************