[17592] in Perl-Users-Digest
Perl-Users Digest, Issue: 5012 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 1 18:10:31 2000
Date: Fri, 1 Dec 2000 15:10:13 -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: <975712213-v9-i5012@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 1 Dec 2000 Volume: 9 Number: 5012
Today's topics:
Perl and Microsoft Access Problem <thf@cisunix.unh.edu>
RE:Automation <hillr@ugsolutions.com>
Re: Reading file into array. <johngros@Spam.bigpond.net.au>
Re: Reading file into array. (Tad McClellan)
Re: sorting a file... (David Wall)
SSLeay, LWP and HTTPS (Jan Stocker)
Re: SSLeay, LWP and HTTPS nobull@mail.com
strings with a minus <johngros@Spam.bigpond.net.au>
Re: txt files getting denied. (David Wall)
Re: unzip from script HELP nobull@mail.com
Re: What if $SIG{__DIE__} is occupied by other module? <schwern@pobox.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 1 Dec 2000 14:29:38 -0500
From: "Timothy Frye" <thf@cisunix.unh.edu>
Subject: Perl and Microsoft Access Problem
Message-Id: <908ubl$np1$1@tabloid.unh.edu>
Hello Everyone,
I'm writing an application in Perl to interface with an Access Database. In
one portion of my program, I connect to the database and perform a simple
select statement and return the results as the default values in an online
form. I had this working properly.
I then made a change to the program and it failed. I removed what I changed
and it still failed. I even separated just the database interaction part
out and ran just that part of the program to no avail. The problem is this;
after SELECTing the appropriate values,
fetchrow_array returns only the last value that was selected. Here is the
code:
##############Begin Code###################
use strict;
use CGI qw(:standard);
use DBI;
my (
$APP, $dbh, $sth, $rc, $statement, $id, $id2, $call, $handle, $trouble,
$start, $end, $notes, $time, $dept, $caller,
);
$APP = CGI->new();
$id = $APP->param("id");
$dbh = DBI->connect('DBI:ODBC:TroubleCalls', '{ RaiseError => 1}') || die
"Couldn't connect to database: " . DBI->errstr;
print "Connecting to troublecalls!!<br>\n";
$statement = "SELECT * FROM TroubleCalls WHERE TroubleID = $id";
$sth = $dbh->prepare($statement) || die "Couldn't prepare statement: " .
$dbh->errstr;
$rc = $sth->execute() || die "Couldn't execute statement: " . $sth->errstr;
($call, $handle, $trouble, $start, $end, $notes, $time, $dept,
$caller)=$sth->fetchrow_array()||die"Couldn't fetch row info:".$sth->errstr;
$sth->finish() || die "Couldn't finish the fetch operation: ". $sth->errstr;
print header, start_html;
print "\$call = $call<br>\n";
print "\$handle = $handle<br>\n";
print "\$trouble = $trouble<br>\n";
print "\$start = $start<br>\n";
print "\$end = $end<br>\n";
print "\$notes = $notes<br>\n";
print "\$time = $time<br>\n";
print "\$dept = $dept<br>\n";
print "\$caller = $caller<br>\n";
print end_html;
###################End Code############################
The problem is that when this executes, I get this as the printout:
$call = Tim
$handle =
$trouble =
$start =
$end =
$notes =
$time =
$dept =
$caller =
and that first value of Tim should show up as the value for $caller. If I
ask for only one value, I get the value that I asked for. Anymore than that
and I get the last value selected showing up as the first value printed out
and nothing else (as above).
Anybody got any clues?
-Timothy Frye
Systems Administrator
Dimond Library
University of New Hampshire
------------------------------
Date: Fri, 01 Dec 2000 13:05:51 -0800
From: Ron Hill <hillr@ugsolutions.com>
Subject: RE:Automation
Message-Id: <3A2812AF.D722889@ugsolutions.com>
I am new to PERL and I have searched through the FAQs and other info
sources before posting. ; How do you
feed commands to a process that you open with PERL? ; I am ; trying
to automate several processes to speed up a total process. ; What I
need to do is open a program (windows based) and then feed commands into
it to get theprocess complete and then come back to PERL and go to the
next step. ; Some of the programs are like notepad (commands like print,
save, open). ; Thanks for any help.
Rodney Knight
U.S. Geological Survey
Tennessee
Hello,
Please try not to post using HTML people here do not like that.
You might want to look at the system function
perldoc -f system
------------------------------
Date: Fri, 01 Dec 2000 21:13:07 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Re: Reading file into array.
Message-Id: <DvUV5.863$xW4.6961@news-server.bigpond.net.au>
Well I am trying to learn you might just find me 'trying'. ;-)
I will try to use strict but on some of my scripts I run on my server I
can't get them to run because I can't initialize a subs variables it calls
a module for mail.
I can go back to using it with my scripts I run from the commandline, this
was one and I am sorry I did not use it.
I have a batch file I use that calls perl -w script.pl. I assumed I don't
need -w in the #! line. The or die I ommitted because I know the files are
being opened.
I guess it should be there for the occasion when they won't open for
whatever reason. Once again I will stop being lazy.
I did intend to find a line with [ in it, it is the start of the data I
wanted.
Thanks for pointing out all my mistakes.
<nobull@mail.com> wrote in message news:u97l5kgfr5.fsf@wcl-l.bham.ac.uk...
> > Subject: Reading file into array.
>
> What does this have to do with anything?
>
> > This is the best I could come up with but $_ should be $_[$somevalue]
where
> > can I get the value perl would be using as it creates @_?
>
> You seem to be confused. @_ and $_ are separate variables. $_[0] is
> the first element of the array @_.
>
> Also you are not using strict, enabling warnings and checking the
> return value from open(). Comming to this newsgroup for help and not
> doing these things is considered very rude because it means you think
> we should help you when you cannot be bothered to help yourself. Many
> of your mistakes would have been detected had you bothered.
>
> > while (@_ = <BOGUS> ){
>
> That's gibberish! You have a loop that reads the whole file into the
> array on _each_ interation of the loop. Reading the whole file is
> something that will only succede at most once so you could replace the
> "while" with "if".
>
> I suspect you meant to say
>
> while ( $line = <BOGUS> ){
>
> I'll change that and carry on
>
> > #!e:/millenium programs/perl/bin/perl
> > $path = "C:/Program Files/G6FTP/";
> > $file = $path."Users.ini";
> > open BOGUS,"$file";
> > $array = 0;
>
> Using "array" as a variable name is not something you should do in
> real code. Using it as name for a scalar is like naming your cat "My
> Dog". You never use this variable again.
>
> > if ($line =~ /\[/){
>
> Do you really want to look for [ anywhere in the string.
>
> > $flag = "set";
>
> When using a variable to act as a boolean flag it is sensible to adopt
> the conventions of the language that you are using. In Perl you
> should use '' and 1 for true and false.
>
> $flag = 1;
>
> > $counter = 0;
>
> Counters are something you rearely need in Perl. For now we'll leave it.
>
> > }elsif (/^\n/){
>
> It is more convetuional to test for the empty line with the pattern
> /^$/. This has the advantage that it'll work on Windows too. Decide
> if you want to use the default "current line" buffer (aka $_) or a
> named variable $line. Stick with your decision.
>
> } elsif ( $line =~ /^$/ ){
>
> > $flag ="not set";
>
> $flag = 0;
>
> > print $data[$array[$counter]];
> > print $data[$array[2]];
> > $temp = $data[$array[2]];
>
> I assume here you intend @data to be a 2D array with subscripts $array
> and $counter.
>
> > print $data[$array][$counter];
> > print $data[$array][2];
> > $temp = $data[$array][2];
>
> > $temp =~ s/Login=//;
> > if ({time-$temp}/86400<31){
> > $array++;
> > }
> > }elsif ($flag eq "set"){
>
> If you use ordinary boolean convention for $flag that's just:
>
> } elsif { $flag ) {
>
> > $data[$array[$counter]] = $line;
>
> $data[$array][$counter] = $line;
>
> > $counter++;
> > }
> >
> > }
>
> OK, lets summarise. Note, I'm only fixing the mistakes that pertain
> to lack of understang of Perl. I've ignored mistakes that petain to
> not being able to program.
>
> #!e:/millenium programs/perl/bin/perl -w
> use strict;
> my $path = "C:/Program Files/G6FTP/";
> my $file = $path."Users.ini";
> open BOGUS,"$file" or die $!;
>
> my $array = 0;
> my (@data,$flag,$counter)
>
> while ( my $line = <BOGUS> ){
> if ($line =~ /\[/){
> $flag = 1;
> $counter = 0;
> } elsif ( $line =~ /^$/){
> $flag = 0;
> print $data[$array][$counter];
> print $data[$array][2];
> my $temp = $data[$array][2]];
> $temp =~ s/Login=//;
> if ({time-$temp}/86400<31){
> $array++;
> }
> } elsif ($flag ) {
> $data[$array][$counter] = $line;
> $counter++;
> }
> }
>
> --
> \\ ( )
> . _\\__[oo
> .__/ \\ /\@
> . l___\\
> # ll l\\
> ###LL LL\\
------------------------------
Date: Fri, 1 Dec 2000 16:24:32 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Reading file into array.
Message-Id: <slrn92g5og.af8.tadmc@magna.metronet.com>
nobull@mail.com <nobull@mail.com> wrote:
>"John Boy Walton" <johngros@Spam.bigpond.net.au> writes as thought
>this is the middle of a thread, but it isn't this is the start of a
>new thread.
>
>> $flag = "set";
>
>When using a variable to act as a boolean flag it is sensible to adopt
>the conventions of the language that you are using. In Perl you
>should use '' and 1 for true and false.
s/true and false/false and true/;
or
s/'' and 1/1 and ''/;
( or even "NOT respectively".
or, if you are our troll, "NOT respectfully".
)
>$flag = 1;
>> $flag ="not set";
>
>$flag = 0;
Errr, so which is it?
Empty string or zero for false? ( I vote for zero )
heh, heh.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 1 Dec 2000 17:36:12 -0500
From: darkon@one.net (David Wall)
Subject: Re: sorting a file...
Message-Id: <8FFDBB6D9darkononenet@206.112.192.118>
texasreddog@my-deja.com wrote in <908bds$5rt$1@nnrp1.deja.com>:
>Can someone help me, by putting in some code for this to make this work?
>If anyone knows of a better sort solution than this, let me know.
I'm not sure why you want to reassign ID numbers, but if you take nobull's
advice to use a 2D array, it's pretty easy. Check out the following demo
program and see if it's the kind of thing you want to do:
#!/usr/bin/perl -w
use strict;
print "Original:\n";
my @records;
my $min_id = 9999999999;
while(<DATA>){
print;
next if /^#/; # ignore comments
my @fields = split /\|/;
push @records, \@fields;
$min_id = $min_id < $fields[0] ? $min_id : $fields[0];
}
print "\nSmallest ID is $min_id\n";
@records = sort { $a->[1] <=> $b->[1] } @records;
print "\n\nNew:\n";
print "#id|datestamp|label|description\n";
foreach my $rec (@records) {
$rec->[0] = $min_id++;
print join '|', @$rec;
}
__DATA__
#id|datestamp|label|description
29|20001206|Holiday Party|Location ???
30|20001225|Christmas Day|Office Closed
31|20001226|Christmas Holiday|Office Closed
33|20001227|Out Of Office|Joe Blow - Vacation
34|20001228|Out Of Office|Joe Blow - Vacation
35|20010101|New Years Day|Office Closed
36|20001207|Annual Stockholders Meeting |10:00am
37|20001201|Jane Doe - doctor's appt|11:00 doctor's appt.
--
David Wall
darkon@one.net
------------------------------
Date: 1 Dec 2000 19:33:47 GMT
From: jstocker@s61.informatik.uni-bremen.de (Jan Stocker)
Subject: SSLeay, LWP and HTTPS
Message-Id: <slrn92fv8r.fuo.jstocker@s61.informatik.uni-bremen.de>
Hi,
i've tried to make a HTTPS connection via LWP->UserAgent->request().
It runs for HTTP quite right, for HTTPS the file README.SSL reads you've
to intsall SSLeay and IO::Socket::SLL. If you try then a HTTPS request
it ends in a connection error.
My apache-log shows that OpenSSL dont accepts the ca send to it.
Which certificate is been used, where is it installed, where else can be
the bug?
Jan
--
"What duck?"
-- (Terry Pratchett, Soul Music)
------------------------------
Date: 01 Dec 2000 20:07:08 +0000
From: nobull@mail.com
Subject: Re: SSLeay, LWP and HTTPS
Message-Id: <u9wvdjgb2r.fsf@wcl-l.bham.ac.uk>
jstocker@s61.informatik.uni-bremen.de (Jan Stocker) writes:
> Hi,
>
> i've tried to make a HTTPS connection via LWP->UserAgent->request().
> It runs for HTTP quite right, for HTTPS the file README.SSL reads you've
> to intsall SSLeay and IO::Socket::SLL. If you try then a HTTPS request
> it ends in a connection error.
>
> My apache-log shows that OpenSSL dont accepts the ca send to it.
If all you want to use SSL for is encryption then simply switch off
the checking:
use IO::Socket::SSL;
IO::Socket::SSL::context_init({SSL_verify_mode => 0});
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 01 Dec 2000 22:32:07 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: strings with a minus
Message-Id: <HFVV5.906$xW4.7234@news-server.bigpond.net.au>
I have a string with a minus sign in it when I copy the scalar into an array
element I am getting an 'isn't numeric subtraction error'.
How do I escape the minus so the value can be passed?
Or is it just a warning and if run without the -w would go through?
------------------------------
Date: 1 Dec 2000 16:02:03 -0500
From: darkon@one.net (David Wall)
Subject: Re: txt files getting denied.
Message-Id: <8FFDA4386darkononenet@206.112.192.118>
rgarciasuarez@free.fr (Rafael Garcia-Suarez) wrote in
<slrn92fiue.i7r.rgarciasuarez@rafael.kazibao.net>:
>David Wall wrote in comp.lang.perl.misc:
>>
>> You do have to close a file before you unlink it, at least
>> under Windows NT. Linux doesn't seem to care.
>
>It's perfectly legal under Linux (and other unix flavors as well) to
>unlink a file that is open. Unlinking modifies the filesystem to delete
>the reference from the directory containing the file to the file inode.
>Note that this does not imply the deletion of the file itself: several
>directory entries may refer to the same inode. This trick is sometimes
>used by a program to get a private temporary file on disk: the unlinked
>open file remains accessible only by this program, through the use of
>its filehandle. Once the filehandle is closed, the file is deleted from
>the disk.
Thanks. I figured there was a good reason for allowing it, but since I was
ignorant of those reasons I prudently remained silent. That's possibly
something I should do more often around here, but if I don't display my
unknowing ignorance I can't get it corrected. ("Knowing" ignorance I can
do something about, e.g.; I /know/ I'm pretty ignorant about OO stuff, so
I'm reading Conway's book.)
--
David Wall
darkon@one.net
------------------------------
Date: 01 Dec 2000 20:14:12 +0000
From: nobull@mail.com
Subject: Re: unzip from script HELP
Message-Id: <u9u28ngaqz.fsf@wcl-l.bham.ac.uk>
any_v@my-deja.com writes:
> I have some zip files that I want to unzip on a Linux platform using a
> perl script and then read the unziped files.
> If I run from the prompt "unzip myfile.zip -dtmp", my zip file is
> unziped in tmp directory. I've tried to run the same command from
> script,e.g 'system("unzip","myfile.zip","-dtmp");' and when I want to
> open this files they don't exist. If I run the script again I receive
> messages that this files are already unziped and if I want to replace
> them or rename them. If I open the tmp directory from prompt it is
> empty.
> Any ideea what is wrong???
At a guess you are looking in one directory called 'tmp' and your
script is unziping into another directory called 'tmp'.
There's possibly a chdir() in your script somewhere.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 01 Dec 2000 21:48:37 GMT
From: Michael G Schwern <schwern@pobox.com>
Subject: Re: What if $SIG{__DIE__} is occupied by other module?
Message-Id: <9096bi$u7t$1@nnrp1.deja.com>
In article <975349354.16281@itz.pp.sci.fi>,
Ilmari Karonen <usenet11288@itz.pp.sci.fi> wrote:
> In article <u9wvdppat2.fsf@wcl-l.bham.ac.uk>, nobull@mail.com wrote:
> >
> >So do not set $SIG{__DIE__}, use eval {} and all will be well.
>
> And if you're running under mod_perl? HTML::Mason?
AFAIK none of those things effect using eval BLOCK to trap errors. $SIG
{__DIE__}, OTOH, is rife with problems when used in a persistant
environment.
> >Alteratively follow the advice given in "perldoc -f die":
> >
> > Note that the $SIG{__DIE__} hook is currently called even inside
> > eval()ed blocks/strings! If one wants the hook to do nothing in
such
> > situations, put
> >
> > die @_ if $^S;
> >
> > as the first line of the handler (see perlvar/$^S).
>
> You know, that doesn't really fix the problem
<snicker-snatch>
You're right, it doesn't. Use eval.
--
--
Michael G Schwern
schwern@pobox.com
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
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 5012
**************************************