[18919] in Perl-Users-Digest
Perl-Users Digest, Issue: 1114 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 12 00:05:41 2001
Date: Mon, 11 Jun 2001 21:05:11 -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: <992318711-v10-i1114@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 11 Jun 2001 Volume: 10 Number: 1114
Today's topics:
Re: Ack! Newbie still suffering from C-brain! <bart.lateur@skynet.be>
Can an lvalue sub also be an rvalue? (pt)
Re: Can an lvalue sub also be an rvalue? <johnlin@chttl.com.tw>
Re: can you do while (<HANDLE>) inside opening a file t (Joe Smith)
Re: DBD::ODBC or Win32::ODBC? <bkennedy99@Home.com>
Re: Design pattern for a generic functions dispatcher <abe@ztreet.demon.nl>
ENV{HTTP_REFERER} in Netscape <dianne@dogmac.com>
Re: FAQ 7.16: What's the difference between dynamic a <johnlin@chttl.com.tw>
Re: File uploading - Where are the files? (David Efflandt)
Re: Getting the First Letter in string <joe+usenet@sunstarsys.com>
Re: How can I convert a date (MM/DD/YYYY) to UTC time? (Joe Smith)
Re: How to send an email and have the result ? (David Efflandt)
Re: integer.pm bug? <johnlin@chttl.com.tw>
Re: integer.pm bug? <dan@tuatha.sidhe.org>
Re: Limiting special characters <davsoming@lineone.net>
Re: Limiting special characters <davsoming@lineone.net>
Re: Limiting special characters <krahnj@acm.org>
New Newsgroup proposal: comp.lang.perl.regex ()
Re: New Newsgroup proposal: comp.lang.perl.regex (Tad McClellan)
Now for problem number two <jmorais@rochester.rr.com>
Re: Now for problem number two <der.prinz@gmx.net>
Re: Now for problem number two <jmorais@rochester.rr.com>
Re: Simplest code to test if web site is up? <usenet@willem.byte.nl>
Re: sort on hash <jhall@ifxonline.com>
Re: sort on hash (Craig Berry)
Re: Sorting versions of a file, Help needed <godzilla@stomp.stomp.tokyo>
Re: Sorting versions of a file, Help needed <godzilla@stomp.stomp.tokyo>
Re: supressing error messages in NT <bkennedy99@Home.com>
system() and exec() don't execute but don't die either <hayati@math.uiuc.edu>
Re: Vars, vars, vars... <ren@tivoli.com>
Re: weighted average? (E.Chang)
Re: why it dies? <davsoming@lineone.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 11 Jun 2001 22:11:26 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Ack! Newbie still suffering from C-brain!
Message-Id: <hggaits6hdck2djvgekj8r2g2qogjv0rqk@4ax.com>
Tad McClellan wrote:
>>I agree. Most of my foreach-es are spelled "for", especially if I use $_
>>as the default loop variable.
>
>
>I disagree. I don't like overloading, is slows down comprehension
>while I resolve which usage it is.
>
>I always use "foreach" for the "walk across a list" thingie.
>
>I always use "for" for the "three part C-like" thingie.
Comprehension, and the "three part C-like" thingie in one sentence?
Boing.
--
Bart.
------------------------------
Date: 11 Jun 2001 16:09:52 -0700
From: mnemotronic@yahoo.com (pt)
Subject: Can an lvalue sub also be an rvalue?
Message-Id: <da662010.0106111509.3f15fa10@posting.google.com>
Can a sub declared with the "lvalue" attribute also be used as a
regular (rvalue) sub?
e.g.
$thing_status = status($thing) ; # get thing's status
status($thing) = 0 ; # reset thing's status
The "Built-in attributes" docs sez (emphasis mine):
lvalue
Indicates that the referenced subroutine is a valid lvalue and
CAN(!!!) be assigned to. The subroutine must return a modifiable value
such as a scalar variable, as described in the perlsub manpage.
This implies that an lvalue sub does not require being used in an
lvalue context, or am I reading something into an admittedly
expermental feature? I'm not sure how the sub would detect it's
context ... wantarray can indicate null context, but that does not
imply lvalue context, or does it?
------------------------------
Date: Tue, 12 Jun 2001 09:15:56 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: Can an lvalue sub also be an rvalue?
Message-Id: <9g3qbg$s1r@netnews.hinet.net>
"pt" wrote
> Can a sub declared with the "lvalue" attribute also be used as a
> regular (rvalue) sub?
> $thing_status = status($thing) ; # get thing's status
> status($thing) = 0 ; # reset thing's status
Your code tells your the answer. Does it compile? Does it work?
John Lin
------------------------------
Date: Tue, 12 Jun 2001 01:05:50 +0000 (UTC)
From: inwap@best.com (Joe Smith)
Subject: Re: can you do while (<HANDLE>) inside opening a file twice?
Message-Id: <9g3pte$v6m$1@nntp1.ba.best.com>
In article <QNYU6.81822$%i7.61334578@news1.rdc1.sfba.home.com>,
Gala <Gala@nonono.com> wrote:
>Ok.. a long is a 32 bit number, therefor goes up to of 4,294,967,295 -
>about 4 gigs (unsigned), or, 2,147,483,647 - about 2 gigs (singed). Now
>lets be realistic here. Is there a computer out there that has a file
>thats 4 or 2 gigs big? No, really, I really doubt are files of that size
Yes, there are plenty of personal computers out there using in video
editing work with video mpeg files greater than 4 gigabytes. A text
file greater than 2 gig is unusual, but binary files of that size are
not uncommon.
>trobble with a file size bigger then a long can hold. Not to mention,
>most server providers usally dont give more then 100 megs, or sometimes
>less, depending on the provider and service, but theres no way in the
>7th circle of hell you are going to get anything even remotely close to
>2 gigs.
Perl is not a language that only runs on web servers. The amount of
disk space allocated to a $30/month account is irrelevent to proper
coding techniques.
-Joe
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.
------------------------------
Date: Tue, 12 Jun 2001 02:34:14 GMT
From: "Ben Kennedy" <bkennedy99@Home.com>
Subject: Re: DBD::ODBC or Win32::ODBC?
Message-Id: <GcfV6.10897$Zt6.4451127@news1.rdc2.pa.home.com>
"Richard Biffl" <REMOVETHISPHRASEusenet@blacklettersoftware.com> wrote in
message news:w%7V6.4092$Il5.514701@newsread1.prod.itd.earthlink.net...
> What are the pros and cons of these modules? I'm using ActivePerl on
Windows
> 2000, and Win98 may use the program too. I'll initially use the interface
to
> migrate data from a text file to a Paradox table, using nothing but INSERT
> statements, but maybe I'll do more with it later. I've seen a post here
> saying that DBD::ODBC is preferred, but ActiveState's website mentions
that
> Win32::ODBC is popular.
>
> Richard
Win32::ODBC gives you better metadata, lets you play with the ODBC API, and
supports scrolling curors. DBI on the other hand has a richer interface for
fetching data, though its nothing that couldn't be accomplished by a thin
layer over Win32::ODBC, which I imagine the DBD::ODBC driver does. I
personally think that the biggest advantage is portability, as DBI runs on
all operating systems and Win32::ODBC is obviously restricted to Windows -
this is what led me to convert a bunch of Win32::ODBC code to DBI based
code. Unless you absolutely need the scrolling cursors, I'd stick with
DBI - hope this helps!
--Ben Kennedy
------------------------------
Date: Tue, 12 Jun 2001 00:45:50 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: Design pattern for a generic functions dispatcher
Message-Id: <p3iait4s0fsivtr5c58pu3i90t77f5mdu2@4ax.com>
On 11 Jun 2001 03:16:54 -0700, abe@ztreet.demon.nl (Abe Timmerman)
wrote:
> #!/usr/bin/perl -w
> use strict;
>
> die <<__USAGE__ unless @ARGV;
> Usage: $0 action [params]
>
> Action can be one of:
> @{ [ sort keys %action_map ] }
> __USAGE__
>
> my %action_map = (
> ACTION1 => 'MyModule::SubModule::Myfunction',
> ACTION2 => 'MyOtherModule::MyOtherFunction',
> );
And those two should (evidently) be swapped (don't ever do partial
copy/paste actions!):
my %action_map = (
ACTION1 => 'MyModule::SubModule::Myfunction',
ACTION2 => 'MyOtherModule::MyOtherFunction',
);
die <<__USAGE__ unless @ARGV;
Usage: $0 action [params]
Action can be one of:
@{ [ sort keys %action_map ] }
__USAGE__
--
Good luck, Abe
Amsterdam Perl Mongers http://amsterdam.pm.org
perl -we '$_="Just another Perl hacker";print$1while/(.)/g'
------------------------------
Date: Tue, 12 Jun 2001 10:56:40 +1000
From: "Dianne van Dulken" <dianne@dogmac.com>
Subject: ENV{HTTP_REFERER} in Netscape
Message-Id: <dNdV6.3200$qJ4.139582@ozemail.com.au>
Hi,
I have already posted this to the perl and perl-cgi mailing lists, but
haven't been able to find a solution
I am calling a perl script from a HTML page in the following form:
<script language="javascript"
src="https://testserver.com.au/server/cgi-bin/script1.pl">
This checks the HTTP_REFERER of the calling page, and if it is one we like,
gives one set of javascript back, or else a different set.
The problem is that Netscape isn't giving me a HTTP_REFERER code at all..
Everyone I have talked to agrees that it SHOULD be giving it to me, but in
none of our tests it has done so.
Has anyone got a suggestion of what else I could use? The javascript
http_referrer still works in Netscape, but not the perl version. We need to
find the IP of the page calling the code, not the users IP or anything like
that.
Thanks a lot
Dianne
--
Dianne van Dulken
You have the right to remain silent.
Anything you say will be misquoted, then used against you.
------------------------------
Date: Tue, 12 Jun 2001 09:55:45 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: FAQ 7.16: What's the difference between dynamic and lexical (static) scoping? Between local() and my()?
Message-Id: <9g3sm9$3qo@netnews.hinet.net>
"Ren Maddox" wrote
> On Mon, 11 Jun 2001, goldbb2@earthlink.net wrote:
> > John Lin wrote:
> >> "PerlFAQ Server" wrote
> >> > "my($x)" creates a new variable that is only visible in the
> >> > current subroutine. This is done at compile-time, so it is called
> >> > lexical or static scoping.
> >>
> >> Really? At compile-time? Or actually at run-time?
> >
> > The scope of a lexical is defined at compile time, and will not
> > change at run time. Allocation and assignment of lexicals occur at
> > runtime.
>
> I believe that allocation also happens at compile time:
>
> my $x = 4;
> BEGIN { print \$x, ":$x\n" }
> print \$x, ":$x\n";
> __END__
> SCALAR(0x8104e0c):
> SCALAR(0x8104e0c):4
I don't know whether the following is a good example,
or it shows my misunderstanding:
sub foo { my $x; \$x }
print foo,"\n" for 1..3;
__END__
SCALAR(0x1be2450)
SCALAR(0x1bef17c)
SCALAR(0x1be2450)
Best regards.
John Lin
--
Hey, what can we tell by looking at the "0x1be2450"
and "0x8104e0c" string? Do they reveal Ren's computer
has more RAM than mine? Or something like that?
------------------------------
Date: Tue, 12 Jun 2001 01:15:59 +0000 (UTC)
From: see-sig@from.invalid (David Efflandt)
Subject: Re: File uploading - Where are the files?
Message-Id: <slrn9iaraf.m5c.see-sig@typhoon.xnet.com>
On 11 Jun 2001 10:41:44 -0700, Esteban <egiron@gmx.net> wrote:
> I already implemented the script and CGI.pm for the file upload
> system, and it works, it returns the count, but I can't seem to find
> the file on my local folders, how can I make the final file (not the
> temp) go to a directory of my choice? So what's the purpose of
> uploading a file if another user can't access it?
Returns the count of what? Did you check if the open() of the file you
saved it to was successfull or why not ($!). If you don't even end up
with a zero length file, then you may have a path or permission problem.
Note that the filename/filehandle is only readable once as a filehandle.
Also note that the filename may contain the path to the file on the
client's system, you need to parse the filename off the end of that if
using it for the destination filename.
Also note that there is another newsgroup for CGI questions.
--
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: 11 Jun 2001 23:32:35 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Getting the First Letter in string
Message-Id: <m3vgm2cqzw.fsf@mumonkan.sunstarsys.com>
cberry@cinenet.net (Craig Berry) writes:
> Philip Newton (pne-news-20010611@newton.digitalspace.net) wrote:
> : [1] any others I'm missing? chop reverse would also work if you used
> : an intermediate temporary variable.
>
> How about:
>
> $first = (split //, $str)[0];
TMTOWTDI-
$first = do {local $^A; formline '@' => $str; $^A}
$first = do {local $_ = reverse $str; chop};
$first = sprintf '%c' => vec $str, 0, 8;
$first = substr $str, 0, 1;
($first)= split //, $str, 2;
$first = unpack a => $str;
$first = pack a => $str;
($first)= $str =~ /(.)/s;
$first = $str & "\xff";
$first = chr ord $str;
--
Joe Schaefer "Sacred cows make the best hamburger."
--Mark Twain
------------------------------
Date: Tue, 12 Jun 2001 02:14:24 +0000 (UTC)
From: inwap@best.com (Joe Smith)
Subject: Re: How can I convert a date (MM/DD/YYYY) to UTC time?
Message-Id: <9g3tu0$vev$1@nntp1.ba.best.com>
In article <3B0ADA55.746DAFE9@gte.net>, Bill Nelson <isstb@flanet.com> wrote:
>> Perl is chock-full of time manipulation utils:
>>
>> localtime
>> gmtime
>> Time::Local
>
>Yes, but none that I can tell to take a date and convert it to UTC,
You are mistaken. Time::Local has two functions that convert from
(seconds,minutes,hours,day,month,year) to epoch time, which is what
you were looking for.
[Splitting a date string into (sec,min,...) is left as an exercise for
the reader. Or CPAN.]
-Joe
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.
------------------------------
Date: Tue, 12 Jun 2001 01:24:54 +0000 (UTC)
From: see-sig@from.invalid (David Efflandt)
Subject: Re: How to send an email and have the result ?
Message-Id: <slrn9iarr6.m5c.see-sig@typhoon.xnet.com>
On Mon, 11 Jun 2001 14:58:12 +0200, CutMaster <cutmaster@fearlesss.com> wrote:
> How to send an email, in Perl, but with having the result of this send :
> (ie : fail to send, domain unavailable, etc).
A halfway Perl method is to use IPC::Open3 with the verbose switch of
sendmail. An example CGI using this and the usual method is mailtest.txt
at http://cgi-help.virtualave.net/pub/
I don't have a working example up because I don't want spammers using
this test script, without any controls.
--
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: Tue, 12 Jun 2001 09:34:01 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: integer.pm bug?
Message-Id: <9g3rdd$13d@netnews.hinet.net>
"Anno Siegel" wrote
> According to Chris W. Unger:
> > Does anyone have any idea why the use of integer.pm would
> > cause the value of offset to be 0 after the following code
> > is executed? If I comment out the "use integer;" line, I get
> > the expected results (offset value is 3196874884).
> > use integer;
> > $offset = 6393749768 / 2;
> > print $offset;
>
> It's no bug.
>
> With "use integer" in effect, Perl translates the operands of an
> arithmetic operation (/) to native integers. The size of those
> is often 32 bits.
IMHO, in this case, maybe Perl should provide
use integer 'long'; # I want to use native 'long' type
use integer 'longlong'; # I want to use native 'longlong' type
to satisfy the need.
Best regards.
John Lin
------------------------------
Date: Tue, 12 Jun 2001 02:45:39 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: integer.pm bug?
Message-Id: <nnfV6.76075$v5.5949053@news1.rdc1.ct.home.com>
John Lin <johnlin@chttl.com.tw> wrote:
>> It's no bug.
>>
>> With "use integer" in effect, Perl translates the operands of an
>> arithmetic operation (/) to native integers. The size of those
>> is often 32 bits.
> IMHO, in this case, maybe Perl should provide
> use integer 'long'; # I want to use native 'long' type
> use integer 'longlong'; # I want to use native 'longlong' type
> to satisfy the need.
It does--you build perl with 64-bit integers if you want them.
Dan
------------------------------
Date: Mon, 11 Jun 2001 23:08:11 +0100
From: "David Soming" <davsoming@lineone.net>
Subject: Re: Limiting special characters
Message-Id: <tialoakv6qs400@corp.supernews.co.uk>
--
David Soming
'Just a head-banger- doing what I do best'
______________
"Craig Berry" <cberry@cinenet.net> wrote in message
news:tiabu1gks033d4@corp.supernews.com...
> David Soming (davsoming@lineone.net) wrote:
> : I have a list of special characters in an if statement which I want to
> : disallow in my form:
> :
> : if ($message =~ /(\$+|\?+|\|+|\(+|\)+|\[+|\]+|\{+|\}+|\^+|\*+|\.+|\<)/)
{
>
> Why match on all those one-or-more quantifiers? One is enough to trigger
> the condition, afer all.
>
> Also, it's easier by far to do this using a character class rather than
> alternation:
>
> if ($message =~ /([$?|()[\]{}^*.<])/) {
>
> tr/// counting would be more efficient if you didn't need to report which
> character had tripped the detector.
>
> : Have I got it pretty much covered- any others worth including?
>
> I usually prefer going at the problem from the other direction: Determine
> what the set of legal characters is, and test the string to make sure it
> contains only those characters. Otherwise you're left trying to enumerate
> all the oddball characters, including non-printables and the like, which
> is harder to do.
>
> : Also is it possible to limit the byte size and/or string length to
prevent
> : malicious attacks?
>
> Sure...just do something like
>
> die 'Go away HaX0R' if length $message > 1000;
>
I like that! :-)
------------------------------
Date: Tue, 12 Jun 2001 00:47:18 +0100
From: "David Soming" <davsoming@lineone.net>
Subject: Re: Limiting special characters
Message-Id: <tialobcka3sq01@corp.supernews.co.uk>
>
> Also, it's easier by far to do this using a character class rather than
> alternation:
>
> if ($message =~ /([$?|()[\]{}^*.<])/) {
>
Actually messing around with this code allows any and all characters
(also doesn't return output of the offending char ( )) to browser-
unless its implemented like this...
if ($message =~ /($+[?|()[\]{}^*.<])/) {
At least I learned somthing :-)
--
David Soming
'Just a head-banger- doing what I do best'
______________
------------------------------
Date: Tue, 12 Jun 2001 00:00:58 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Limiting special characters
Message-Id: <3B255BE3.6C9E9C8E@acm.org>
[Please don't top-post]
David Soming wrote:
>
> Thanks for the two links.
> I agree it is a much better (safer) approach to specify what characters are
> allowed as opposed to a long list of characters which are not. and as they
> point out you could potentially and erroneously miss one or two!
> However I'm new to perl (if it wasn't already obvious), and although I get
> the gist of what its supposed to do - don't know how to implement the
> example code from CERT into my program: Any quick solution available please
> apart from reading up perldoc for a fortnight or more?
>
> char *percent_x(...) ######No idea what this line is/does! {
> {...}
> static char ok_chars[] = "1234567890!@%-_=+:,./\
> abcdefghijklmnopqrstuvwxyz\
> ABCDEFGHIJKLMNOPQRSTUVWXYZ";
>
> {...}
>
> for (cp = expansion; *(cp += strspn(cp, ok_chars)); /* */ ) #####Nor
> this!
> *cp = '_';
>
> {...}
This is a C (or C++) program example. The perl equivalent would be:
$data =~ s#[^0-9a-zA-Z!@%_=+:,./-]#_#
John
--
use Perl;
program
fulfillment
------------------------------
Date: Mon, 11 Jun 2001 23:07:53 GMT
From: ksimpson@ttul.org ()
Subject: New Newsgroup proposal: comp.lang.perl.regex
Message-Id: <dbcV6.43986$cF.1879189@news1.crdva1.bc.home.com>
Many postings to clpm are regular expression related -- so many, in fact,
that I think we need a new newsgroup specifically for regular expression
discussions.
I'd like to propose that we form a new newsgroup, comp.lang.perl.regex,
whose sole purpose is to deal with regular expression related questions.
Any takers?
------------------------------
Date: Mon, 11 Jun 2001 21:29:59 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: New Newsgroup proposal: comp.lang.perl.regex
Message-Id: <slrn9ias4n.dav.tadmc@tadmc26.august.net>
ksimpson@ttul.org <ksimpson@ttul.org> wrote:
>Many postings to clpm are regular expression related -- so many, in fact,
>that I think we need a new newsgroup specifically for regular expression
>discussions.
>
>I'd like to propose that we form a new newsgroup,
Git on over to news.groups for how to go about creating a new newsgroup.
>comp.lang.perl.regex,
>whose sole purpose is to deal with regular expression related questions.
This has come up before around 1997 or so. Right up to the exact
same newsgroup name.
>Any takers?
(long URL wrapped for posting)
http://groups.google.com/groups?as_q=comp.lang.perl.regex&
as_ugroup=comp.lang.perl.misc
Looks like it came up in Oct 1999 and Feb 2001 too.
Creating a newsgroup is a lot of work. You better really really
want one before you volunteer to shepherd one through the creation
process.
Is that what you are doing? (volunteering)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 11 Jun 2001 22:55:50 GMT
From: "John Morais" <jmorais@rochester.rr.com>
Subject: Now for problem number two
Message-Id: <W%bV6.183518$f85.27409878@typhoon.nyroc.rr.com>
Since you where all so helpful on my first question.. I have a second
problem and I do not know where to Post it so here goes...
In Oracle there are fixed views sys.v_$<somename>. You can only query
against them if you are internal, sys, or system or have been granted select
access or sysdba authority. You can access them through SQL*PLUS or svrmgrl.
ie
C:\Perl\eg>sqlplus sys/ratdog@jhmnt2
SQL*Plus: Release 8.1.7.0.0 - Production on Mon Jun 11 18:32:35 2001
(c) Copyright 2000 Oracle Corporation. All rights reserved.
Connected to:
Oracle8i Enterprise Edition Release 8.1.7.0.0 - Production
With the Partitioning option
JServer Release 8.1.7.0.0 - Production
SQL> select * from sys.v_$instance;
INSTANCE_NUMBER INSTANCE_NAME
--------------- ----------------
HOST_NAME
----------------------------------------------------------------
VERSION STARTUP_T STATUS PAR THREAD# ARCHIVE LOG_SWITCH_
----------------- --------- ------- --- ---------- ------- -----------
LOGINS SHU DATABASE_STATUS INSTANCE_ROLE
---------- --- ----------------- ------------------
1 jhmnt2
HOME-SREVWEVPFU
8.1.7.0.0 11-JUN-01 OPEN NO 1 STOPPED
ALLOWED NO ACTIVE PRIMARY_INSTANCE
Now here is my perl (or Perl) :
#!perl -w
use DBI;
my $dbh = DBI->connect( "dbi:Oracle:$ARGV[0]","$ARGV[1]","$ARGV[2]")
or die "Can not connect to database : $DBI::errstr\n";
$sth = $dbh->prepare( " select * from sys.v_$instance " );
$sth->execute();
$sth->dump_results();
C:\Perl\eg>perl db_test1.pl jhmnt2 sys ratdog
Name "main::instance" used only once: possible typo at db_test1.pl line 7.
Use of uninitialized value in concatenation (.) or string at db_test1.pl
line 7.
DBD::Oracle::db prepare failed: ORA-00942: table or view does not exist (DBD
ERR
OR: OCIStmtExecute/Describe) at db_test1.pl line 7.
Can't call method "execute" on an undefined value at db_test1.pl line 9.
Now if I create a view from the sys.v_$instance and call it v_instance
SQL*Plus: Release 8.1.7.0.0 - Production on Mon Jun 11 18:32:35 2001
(c) Copyright 2000 Oracle Corporation. All rights reserved.
Connected to:
Oracle8i Enterprise Edition Release 8.1.7.0.0 - Production
With the Partitioning option
JServer Release 8.1.7.0.0 - Production
SQL> create or replace view v_instance as select * from sys.v_$instance;
View created.
SQL> create public synonym v_instance for v_instance;
Synonym created.
SQL> grant select on v_instance to public;
Grant succeeded.
so now I change my code :
#!perl -w
use DBI;
my $dbh = DBI->connect( "dbi:Oracle:$ARGV[0]","$ARGV[1]","$ARGV[2]")
or die "Can not connect to database : $DBI::errstr\n";
$sth = $dbh->prepare( " select * from v_instance " );
$sth->execute();
$sth->dump_results();
C:\Perl\eg>perl db_test1.pl jhmnt2 sys ratdog
'1', 'jhmnt2', 'HOME-SREVWEVPFU', '8.1.7.0.0', '11-JUN-01', 'OPEN', 'NO',
'1', '
STOPPED', undef, 'ALLOWED', 'NO', 'ACTIVE', 'PRIMARY_INSTANCE'
1 rows
This has me totally baffled... From the Oracle side if I am connecting as
SYS then that connection should have all the grants and privilege of the SYS
user, but it doesnt appear to have those privileges.
Am I missing something or is the actually database connection made through
perl not SYS but some thing else ?
------------------------------
Date: Tue, 12 Jun 2001 01:13:23 +0200
From: "Stefan Weiss" <der.prinz@gmx.net>
Subject: Re: Now for problem number two
Message-Id: <3b255055$1@e-post.inode.at>
John Morais <jmorais@rochester.rr.com> wrote:
> SQL> select * from sys.v_$instance;
So this view is *really* called 'sys.v_$instance', *with* the dollar
sign?
Then you'll have to mask the $ in your script, or Perl will try
to interpolate the value of the (nonexistant) variable $instance
there:
> $sth = $dbh->prepare( " select * from sys.v_$instance " );
This should be:
$sth = $dbh->prepare('select * from sys.v_$instance'); # or
$sth = $dbh->prepare("select * from sys.v_\$instance");
> Name "main::instance" used only once: possible typo at db_test1.pl line 7.
> Use of uninitialized value in concatenation (.) or string at db_test1.pl
> line 7.
These error messages should point you to the bug. It would never
have happened in the first place if you had used strict.
HTH,
stefan
------------------------------
Date: Mon, 11 Jun 2001 23:53:51 GMT
From: "John Morais" <jmorais@rochester.rr.com>
Subject: Re: Now for problem number two
Message-Id: <jScV6.183537$f85.27458005@typhoon.nyroc.rr.com>
Oh DUH same problem in csh ksh now I feel really STOOPID
"Stefan Weiss" <der.prinz@gmx.net> wrote in message
news:3b255055$1@e-post.inode.at...
> John Morais <jmorais@rochester.rr.com> wrote:
>
> > SQL> select * from sys.v_$instance;
>
> So this view is *really* called 'sys.v_$instance', *with* the dollar
> sign?
>
> Then you'll have to mask the $ in your script, or Perl will try
> to interpolate the value of the (nonexistant) variable $instance
> there:
>
> > $sth = $dbh->prepare( " select * from sys.v_$instance " );
>
> This should be:
>
> $sth = $dbh->prepare('select * from sys.v_$instance'); # or
> $sth = $dbh->prepare("select * from sys.v_\$instance");
>
> > Name "main::instance" used only once: possible typo at db_test1.pl line
7.
> > Use of uninitialized value in concatenation (.) or string at db_test1.pl
> > line 7.
>
> These error messages should point you to the bug. It would never
> have happened in the first place if you had used strict.
>
>
> HTH,
> stefan
>
>
>
------------------------------
Date: Tue, 12 Jun 2001 01:24:19 +0200
From: "Willem" <usenet@willem.byte.nl>
Subject: Re: Simplest code to test if web site is up?
Message-Id: <9g3jpu$pu1$1@dinkel.civ.utwente.nl>
"B Wooster" <b.wooster@usa.net> wrote in message
news:cb45ebcb.0106111035.34abf2a9@posting.google.com...
> I've been looking at libwww and it can certainly
> do what I need to - but is there some very simple
> Perl code that can check if the web server at a
> particular site is up?
>
> I need this:
>
> $site_is_up = &check_site("www.somesite.com");
Use IO::Socket (std module) and send "HEAD / HTTP/1.0\n\n" to the server. If
you get a response, it is working :-)
------------------------------
Date: Mon, 11 Jun 2001 22:27:09 GMT
From: "John Hall" <jhall@ifxonline.com>
Subject: Re: sort on hash
Message-Id: <1BbV6.41358$%a.2165914@news1.rdc1.sdca.home.com>
I found it. Seems sort is case sensitive. This is the solution:
@usrkeys = (sort { lc($a) cmp lc($b)} keys(%permdb) ) ;
And yes i'm a big dummy.
"John Hall" <jhall@ifxonline.com> wrote in message
news:FkaV6.41355$%a.2163841@news1.rdc1.sdca.home.com...
>
> I want my array sorted by alpha, but it isn't;
>
> @usrkeys = (sort { $a cmp $b} keys(%permdb) ) ;
>
> Am I a big dummy?
>
> http://moron.shutdown.com
>
>
>
>
------------------------------
Date: Tue, 12 Jun 2001 00:17:18 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: sort on hash
Message-Id: <tianset9tdrt44@corp.supernews.com>
John Hall (jhall@ifxonline.com) wrote:
: I found it. Seems sort is case sensitive. This is the solution:
:
: @usrkeys = (sort { lc($a) cmp lc($b)} keys(%permdb) ) ;
Depending on how big that hash can get, you may wish to use a Schwartzian
or GR transform rather than re-lc-ing on every comparsion during the
sort...after all, there may be quite a few of them. For small hashes, the
difference is unimportant.
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "God becomes as we are that we may be as he is."
| - William Blake
------------------------------
Date: Mon, 11 Jun 2001 20:51:10 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Sorting versions of a file, Help needed
Message-Id: <3B2591AE.C8CC7B53@stomp.stomp.tokyo>
Anno Siegel wrote:
> Philip Newton wrote:
> > Afshin Akbari wrote:
(snipped)
> What we do need is a comparison routine for versions. Postponing
> the details, let's assume that compare_versions( $v1, $v2) returns
> a value < 0 if $v1 is smaller than $v2, and >= 0 otherwise, in the
> intended sense of "smaller". Then we could build a hash that holds
> the highest version for each file in a single pass:
>
> my %high_version;
> while ( <DATA> ) {
(snipped remaining broken code)
You should test code before posting. My presumption
is you are unaware your code produces no output.
Godzilla!
------------------------------
Date: Mon, 11 Jun 2001 20:53:49 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Sorting versions of a file, Help needed
Message-Id: <3B25924D.B48A1429@stomp.stomp.tokyo>
Philip Newton wrote:
> Afshin Akbari wrote:
(snipped)
> My first impulse would be a Schwartzian Transform (Gee, Randal, couldn't
> your grandfather(?) have picked a different name?). I'll assume that
> your file only contains information on one filename and its versions
> my @versions;
> my $name;
> while(<DATA>) {
(snipped half-baked code)
You should test code before posting. Your code only
gets it half right.
Godzilla!
------------------------------
Date: Tue, 12 Jun 2001 02:56:45 GMT
From: "Ben Kennedy" <bkennedy99@Home.com>
Subject: Re: supressing error messages in NT
Message-Id: <NxfV6.10908$Zt6.4476092@news1.rdc2.pa.home.com>
"John Hoerr" <jhoerr@resnet.gatech.edu> wrote in message
news:9g37ru$55u$1@iocextnews.bls.com...
> i can't find any documentation on suppressing error messages ala $output =
> `cmd 2>/dev/null`; for a win32 environment. Any thoughts on a good way
to
> do this?
If you don't care about it, you can close STDERR in the parent - if you do
care, you can do something like
{
local *TMP;
open(TMP,">&STDERR");
close(STDERR);
`echo Standard error text - should be invisible 1>&2`;
open(STDERR,">&TMP");
`echo Standard error test - should be visible! 1>&2`;
}
I'm sure theres a much better way to do that - I guess another thing you
could do is redirect the text to STDIN, like `command 2>&0` - though that
may very well be bad. Anyway, hope some of this helps --
--Ben Kennedy
------------------------------
Date: Mon, 11 Jun 2001 17:45:01 -0500
From: Katia Hayati <hayati@math.uiuc.edu>
Subject: system() and exec() don't execute but don't die either
Message-Id: <Pine.GSO.4.33.0106111737050.3270-100000@u05.math.uiuc.edu>
Hello,
I have the following code:
system("cat foo.txt | mail hayati\@math.uiuc.edu") == 0 or die $?;
This doesn't die, but never sends the mail. The same command issued at a
prompt works just fine. Replacing system() with exec() or backticks (and
getting rid of the ' == 0') doesn't do any good. I have read the man
pages on system() and exec() but still didn't see what I am doing wrong.
Any help would be greatly appreciated.
Thank you,
Katia Hayati
------------------------------
Date: 11 Jun 2001 16:56:52 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Vars, vars, vars...
Message-Id: <m3n17en0ij.fsf@dhcp9-173.support.tivoli.com>
On Mon, 11 Jun 2001, tadmc@augustmail.com wrote:
[snip]
> One alternative that often goes unmentioned is the one that is
> mentioned by the diagnostic message itself :-)
>
> You can just use an explicit package name in your main:
>
> print $main::SSH;
>
> or, shorten it to:
>
> print $::SSH;
The reason I shy away from this method is that it allows you to get by
with a typo more easily. Usually, this isn't a problem as the "used
only once" warning will still protect you, but I guess I'm just more
comfortable with the explicit protection that lexical declarations
provide (when combined with strictures, of course).
> if $SSH is only used a few times, then I would go with an explicit
> name instead of a declaration.
[snip]
OK, I admit it. When I only have a few variables to share between
files I usually just resort to explicit package notation.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Tue, 12 Jun 2001 02:44:35 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: weighted average?
Message-Id: <Xns90BDE7D067A05echangnetstormnet@207.106.93.86>
Koen van der Drift <koen@wuchem.wustl.edu> wrote in
<Pine.GSO.4.05.10106111626470.10070-100000@wuchem.wustl.edu>:
> Hi,
>
> I'm pretty new to Perl, and I have looked at the FAQ at CPAN, but I
> couldn't find anything about calculating a weighted average. The
> input file looks something like this (where the '...' indicate one
> series of data):
>
> ...
> 500.0 5
> 500.3 20
> 500.6 85
> 500.9 80
> 501.2 15
> 501.5 5
> ...
>
> I assume I can just read in the 2 columns into 2 arrays until the
> next '...', and then do the calculation myself,
No need to store the values in an array. Just accumulate the totals as
you read the data. For example:
my $total, $count;
while (<DATA>) {
my ($tot, $cnt) = split/\t/;
$total += $cnt*$tot;
$count += $cnt;
}
print "Weighted average is ", $total/$count, ".\n";
__DATA__
1.5 2
3 3
2.5 2
--
EBC
------------------------------
Date: Mon, 11 Jun 2001 23:05:39 +0100
From: "David Soming" <davsoming@lineone.net>
Subject: Re: why it dies?
Message-Id: <tialo9s3m7a7ff@corp.supernews.co.uk>
Thanks guys,
That's what you get when you try and copy/cut/paste/butcher/throw it
around/tear it up/stab to death/ the free scripts.
I've simply commented it out for now and I understood immediately why it
terminated with no other option available but to die!
Cheers, sorry for the lamer post.
--
David Soming
'Just a head-banger- doing what I do best'
______________
"Dan Wilga" <dwilga-MUNGE@mtholyoke.edu> wrote in message
news:dwilga-MUNGE-0AB3EB.14530111062001@nap.mtholyoke.edu...
> In article <tia14ba25b0c8a@corp.supernews.co.uk>,
> "David Soming" <davsoming@lineone.net> wrote:
>
> > Hi,
> > Using my form it correctly displays feedback (acknowledgment in
browser)
> > and sends webmaster email OK but dies with the following footer message:
> >
> [...]
> > &check_data;
> > &fill_empty_fields;
> > &store_data;
> > &send_email;
> > &display_feedback;
> > die; #and die it does! -line 30
> > }
>
> If you want to end your script normally, use exit(), not die(). Die() is
for
> abnormal termination, which is why you are getting the error message.
>
> perldoc -f die
> perldoc -f exit
>
> --
> Dan Wilga dwilga-MUNGE@mtholyoke.edu
> ** Remove the -MUNGE in my address to reply **
------------------------------
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 1114
***************************************