[13049] in Perl-Users-Digest
Perl-Users Digest, Issue: 459 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 11 10:07:18 1999
Date: Wed, 11 Aug 1999 07:05:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 11 Aug 1999 Volume: 9 Number: 459
Today's topics:
Re: <== Help with date sorting==> (Mike Bristow)
Re: <== Help with date sorting==> (Matthew Bafford)
Re: <== Help with date sorting==> (Anno Siegel)
Re: array and file processing (Michel Dalle)
Bath.pm Meeting 11-08-1999, Codename "Eclipse" <leon@netcraft.com>
Re: Browser detection - write different html <flavell@mail.cern.ch>
Re: CHMOD function <sariq@texas.net>
Re: Getting perl to accept a flat table file <Paul.Foran@analog.com>
Re: Getting perl to accept a flat table file craig_davids@my-deja.com
Re: Getting perl to accept a flat table file (Michel Dalle)
hash in record <huesser@physik.unizh.ch>
Re: Help - Split Function Blowing My Mind Away!! <aqumsieh@matrox.com>
Re: Improving speed of a sub <dhill@sunbeach.net>
Re: IO::Socket dilemma <j@mesduncan.co.uk>
Mac perl2exe? <erich.seifert@dachau.baynet.de>
meaning of $mode (lstat) <huesser@physik.unizh.ch>
Menu Options dave4000@my-deja.com
Re: Menu Options <mike@crusaders.no>
Re: Mini-objects <Mark@Mark.Com>
New to Perl: File manipulation Question <knewman@mcs.com>
Re: Perl & Oracle in a webserver.... environment variab <rereidy@uswest.net>
Re: perl on linux <vitus@zinc.fe.msk.ru>
Re: perl on linux <mike@crusaders.no>
Re: Perl Question - NOT ! (Michel Dalle)
perldoc problem (TM Lehto)
Re: Re: Re: pipes and file handles (Malcolm Ray)
Re: Reading the Online Documentation? (Anno Siegel)
Regexp newbie <erich.seifert@dachau.baynet.de>
Re: Regexp newbie (Andreas Fehr)
Re: Regexp newbie (Andreas Fehr)
Scalar context? <jkuhnert@harbingercomm.com>
Re: suggestions for CRAP <mike@crusaders.no>
Re: Upload file from mac (Chris Nandor)
Re: using alarm under win32 (Bbirthisel)
Re: Why use Perl when we've got Python?! (Mitchell Morris)
win32 Net::SMTP <dcaddell@talk21.com>
Re: win32 Net::SMTP (Andreas Fehr)
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 11 Aug 1999 10:39:44 GMT
From: mike@fat.dotat.at (Mike Bristow)
Subject: Re: <== Help with date sorting==>
Message-Id: <slrn7r2kng.8uo.mike@lindt.fat.dotat.at>
On Tue, 10 Aug 1999 18:50:44 GMT, Matthew Bafford <*@dragons.duesouth.net> wrote:
>And so it happened, on Tue, 10 Aug 1999 15:33:39 -0300, Kevin Howe"
><khowe@performance-net.com> typed random characters into perl, and ended
>up with the following posted to comp.lang.perl.misc:
>: I am looking to sort a set of dates with the following format in
>: most_recent-least_recent order.
>:
>: August 10, 1999
>: September 20, 1999
>: December 13, 1999
>:
>: Can anyone give me an example of how I might go about it?
>
>Year first, month second, day last.
>
>#!/usr/bin/perl -w
>
>my %months = (
Don't reinvent the wheel without good reason.
Note that one of the good reasons to reinvent the wheel in this situation
is that Date::Manip is /slow/.
But if this isn't timecritical, why bother?
mike@work:~$ cat foo.pl
#!/usr/bin/perl -w
use strict;
use Date::Manip;
my @unsorted = ( 'August 10, 1999', 'September 20, 1999',
'December 13, 1999', 'April 1, 2000',
'November 3, 1900', 'November 3, 1000',
'November 23, 1900', 'January 21, 1994',
'May 30, 5432'
);
&Date_Init; # this line is magic
for my $d (
sort { my ($ad,$bd) = (ParseDate($a),ParseDate($b)); $ad cmp $bd }
@unsorted
) {
print $d,"\n";
}
mike@work:~$ perl -w foo.pl
November 3, 1000
November 3, 1900
November 23, 1900
January 21, 1994
August 10, 1999
September 20, 1999
December 13, 1999
April 1, 2000
May 30, 5432
mike@work:~$
--
Mike Bristow, Geek-At-Large. GK/RT0038
one tequila - two tequila - three tequila - FLOOR !!!
------------------------------
Date: Wed, 11 Aug 1999 12:39:28 GMT
From: *@dragons.duesouth.net (Matthew Bafford)
Subject: Re: <== Help with date sorting==>
Message-Id: <slrn7r2q92.ev3.*@dragons.duesouth.net>
On Wed, 11 Aug 1999 10:39:44 GMT, Mike Bristow) held some poor sysadmin
at gunpoint, and typed the following into comp.lang.perl.misc:
: On Tue, 10 Aug 1999 18:50:44 GMT, Matthew Bafford <*@dragons.duesouth.net> wrote:
: >my %months = (
:
: Don't reinvent the wheel without good reason.
Don't accuse without reading the original post.
: Note that one of the good reasons to reinvent the wheel in this situation
: is that Date::Manip is /slow/.
Which is why I wrote what I did.
: But if this isn't timecritical, why bother?
As the original post said, this IS time critical. In his second post he
elaborated, mailing me sample code (which I included in my post) using
Date::Manip.
His original question was 'is there any way to speed this up?'.
[snip Date::Manip code]
: Mike Bristow
--Matthew
------------------------------
Date: 11 Aug 1999 13:18:57 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: <== Help with date sorting==>
Message-Id: <7ort81$orh$1@lublin.zrz.tu-berlin.de>
Abigail <abigail@delanet.com> wrote in comp.lang.perl.misc:
> require Time'JulianDay; # All hail the Emperor!
The Julius in _Julian Day_ was probably no emperor at all. The
French scholar Joseph Justus Scaliger introduced the system of
counting days from a fixed date in the past. He chose 1 January
4713 BCE, and named it in honor of his father Julius Caesar.
While some books state that for a fact, the calendar faq (and who
would want to cast aspersions on a usenet faq) allows for the
possibility that it was named after the Julian calendar. So
hail away if you must.
Anno
------------------------------
Date: Wed, 11 Aug 1999 13:16:14 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Re: array and file processing
Message-Id: <7ort84$rlr$1@news.mch.sbs.de>
In article <7opehr$dps$1@nnrp1.deja.com>, Teacher Guy <habfan2@my-deja.com> wrote:
>Another Newbie...... needs help.
>
>Hello and thanks to everyone for help. My next dilemna involves
>processing arrays in Perl. I have a database with student names, test
>scores and courses. I need to load data into an array, sort the array
>on test scores field (without screwing up order of other fields) and
>choose only the top ten students. Next, I want to calculate average of
>these 10 students and print the results. Here's what I'm trying to do:
[code snip]
Interesting assignment...if a bit unclear :
What do you mean by "without screwing up order of other fields" ?
I see no order in your example, except maybe in the input data itself.
Do you want to sort by testscore, and then by order of appearance in
your input data, or is that not required ?
And can the same student appear several times, e.g. for several courses ?
And should the average be the average of the ten top scores, or the
average of all courses followed by the top 10 students ?
Otherwise, you could just use something like this (with a couple of
intermediate variables to make things a bit more understandable) :
#!/usr/local/bin/perl -w
while (<DATA>) {
chomp;
# we don't seem to need the other fields for this assignment
# ($student,$testscore,$course) = split(/\|/);
$testscore = (split(/\|/))[1];
push(@scores,$testscore);
}
# check whether we have enough data
if (@scores < 10) {
die "Insufficient data...\n";
}
# find the top 10 scores, assuming they're numerical
@topscores = (sort {$b <=> $a} @scores)[0..9];
print "The top 10 scores are : @topscores\n";
# calculate the average
$total = 0;
foreach $score (@topscores) {
$total .= $score;
}
$ave = $total / 10;
print "The average of these 10 scores is : $ave\n";
print "Is that really what you wanted to know ?\n";
exit;
__DATA__
stud1|10|course1
stud1|9|course2
stud1|8|course3
stud2|9|course1
stud2|8|course2
stud2|7|course3
stud3|8|course1
stud3|7|course2
stud3|6|course3
stud4|7|course1
stud4|6|course2
stud4|5|course3
But that is probably not what you're looking for, right ? :-)
What you actually need (according to my ESP module) is
to sort the students by their highest testscore, rather than
sorting the testscores by themselves.
So, depending on what else you'll need to do with these
data, you might use an array of arrays, a hash of hashes
(e.g. $hash{$student}{$course}), a hash of arrays
(e.g. $hash{$student} = ( [$course1, $score1], ...)), etc.
Have a look at perllol and perldsc for more information on
how to build such structures... There are some nice examples.
Michel.
------------------------------
Date: Wed, 11 Aug 1999 12:27:29 +0100
From: Leon Brocard <leon@netcraft.com>
To: "Bath.pm Mailing List" <bath-pm-list@hfb.pm.org>
Subject: Bath.pm Meeting 11-08-1999, Codename "Eclipse"
Message-Id: <37B15E21.EAC79354@netcraft.com>
The world hasn't ended!
During the eclipse everyone was humming "It's the end of
the world as we know it", and yet we're still here.
So, in true Bath.pm style, we'll meet today as usual.
Unusually, I may cook for everyone in my new flat.
We shall see.
Blurb:
We meet (very informally) at The Hobgoblin in Saint James's
Parade, Bath (UK), every Wednesday from 6pm. Come and join us!
So, back to the real world I suppose...
Leon
--
Leon Brocard................................http://bath.pm.org/
leon@netcraft.com........................http://www.astray.com/
... I'm sorry, Reality is not in service at this time.
------------------------------
Date: Wed, 11 Aug 1999 12:08:02 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Browser detection - write different html
Message-Id: <Pine.HPP.3.95a.990811120027.25962B-100000@hpplus03.cern.ch>
On Tue, 10 Aug 1999, Robert wrote:
> What we are looking for is a perl/cgi script or a java script that will
> accomplish the following...When a user comes to our page, the script will
> detect the browser app ver # and take an action base on that result. What we
> want is when a browser is 4.0 or better, we want the page to load a
> shockwave slideshow, if the browser is lower and can't handle shockwave we
> want the page to load a java applet slide show.
There's a surprisingly large number of WWW information providers (using
this term in its loosest possible sense) who have constructed that kind
of obstacle course for their readership, evidently either not caring
that it's fundamentally unsound engineering, unaware or unconcerned of
the consequences for cacheing, or based on the assumption that their
content is of no conceivable interest to discerning webnauts who have
made their own choice of operating system, browser and configuration
rather than making do with the unconfigured heap of [expletive deleted]
that came right out of the box.
If that describes your site, then you'll probably want to go right
ahead. Sigh.
------------------------------
Date: Wed, 11 Aug 1999 08:43:16 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: CHMOD function
Message-Id: <37B17DF4.6B896B55@texas.net>
stirling@banet.net wrote:
>
> >Your solution is *only* different from the original poster's in that
> >it's slower.
> >
> >It doesn't fix anything.
> ----And yet the funny thing is, it works.
You're missing the point. Let's start over.
The original poster stated that this did not work for him/her:
$OrignialLogFile = 'sample.txt';
You recommended:
$orig="sample.txt";
1) The only difference is single quotes vs. double.
2) If one works, both work. Yours is slower because Perl has to look
for things to interpolate.
As has been stated in replies to the original post, the problem lies
elsewhere.
- Tom
------------------------------
Date: Wed, 11 Aug 1999 13:44:45 +0100
From: Paul Foran <Paul.Foran@analog.com>
To: backwards.saerdna@srm.hc
Subject: Re: Getting perl to accept a flat table file
Message-Id: <37B1703D.3483F276@analog.com>
Andreas Fehr wrote:
> On Wed, 11 Aug 1999 09:21:20 +0100, Paul Foran <Paul.Foran@analog.com>
> wrote:
>
> >Can somebody tell me how to get perl to accept a comma delimited txt
> >file and parse it contents.
>
> Yes, write some Perl code and run it with the filename as parameter.
>
> Andreas
How can I do this exactly???
paul.
------------------------------
Date: Wed, 11 Aug 1999 13:06:30 GMT
From: craig_davids@my-deja.com
Subject: Re: Getting perl to accept a flat table file
Message-Id: <7orsgg$5kj$1@nnrp1.deja.com>
In article <37B13280.B43298B7@analog.com>,
Paul Foran <Paul.Foran@analog.com> wrote:
> Hi all,
>
> Can somebody tell me how to get perl to accept a comma delimited txt
> file and parse it contents.
>
> paul.
>
Open the file into the file handle (STUFF, in this case) and parse the
file using a split command.
ie:
open(STUFF, "dir/filename");
while(<STUFF>)
{
($var1, $var2, $var3) = split (/,/);
# do something with variables
}
close(STUFF)
good luck!
Craig
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Wed, 11 Aug 1999 13:37:46 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Re: Getting perl to accept a flat table file
Message-Id: <7orugg$se4$1@news.mch.sbs.de>
In article <37B13280.B43298B7@analog.com>, Paul Foran <Paul.Foran@analog.com> wrote:
>Hi all,
>
>Can somebody tell me how to get perl to accept a comma delimited txt
>file and parse it contents.
>
1) start with :
#!/usr/local/bin/perl -w
use strict;
Note : your Perl version may be located somewhere else.
2) read in your file with :
while (<>) {
# ...
# the line processing below is supposed to fit here
# ...
}
Note : you'll need to specify the filename as command line argument
3) remove any new-lines with :
chomp;
4) split each line into an array of fields with :
my @fields = split(/,/);
5) do something useful with these fields
As an alternative, look up the Text::CSV module at CPAN.
Michel.
------------------------------
Date: Wed, 11 Aug 1999 15:06:35 +0200
From: Peter Huesser <huesser@physik.unizh.ch>
Subject: hash in record
Message-Id: <37B1755B.BF489878@physik.unizh.ch>
This is a multi-part message in MIME format.
--------------678A1726D132A5B1EBA2205A
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hello
I have a problem with hashes within a record. The following code doesn't
do
what is expected:
#!/usr/bin/perl
%some_table = (
'gaga' => 1,
'baba'=> 2,
);
print $some_table{'gaga'},"\n";
$rec = (
total => 10,
LOOKUP => { %some_table } ,
);
print $rec->{LOOKUP}{'gaga'},"\n";
I believe this code is similar to the one in "Programming Perl" (page
273, second edition), but the last
print statement does not print anything. Can anybody give me a hint ?
Thank's in advance for any help
Pedro
--------------678A1726D132A5B1EBA2205A
Content-Type: text/x-vcard; charset=us-ascii;
name="huesser.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Peter Huesser
Content-Disposition: attachment;
filename="huesser.vcf"
begin:vcard
n:Peter;Huesser
x-mozilla-html:FALSE
org:Physikinstitut der Universitaet Zuerich
version:2.1
email;internet:huesser@physik.unizh.ch
x-mozilla-cpt:;0
fn:Huesser Peter
end:vcard
--------------678A1726D132A5B1EBA2205A--
------------------------------
Date: Wed, 11 Aug 1999 09:00:10 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Help - Split Function Blowing My Mind Away!!
Message-Id: <x3y7ln2bhgl.fsf@tigre.matrox.com>
lr@hpl.hp.com (Larry Rosler) writes:
> OK, surprises. Gotchas. That's harder. Let's start with the one at
> hand:
>
> 1. The first argument to join() is a string, but to split() is a regex
> (no matter that it might look like a string).
>
> 2. "e:\foo\bar" is unlikely to be a good filename, but 'e:/foo/bar' is.
>
> I'll keep thinking. Anyone???
How about:
Autovivification
$/ is a string. Not a regexp.
for() loops localize $_, while() loops don't.
metacharacters in scalars used in pattern matching
/$match/ (should be /\Q$match\E/)
?
Ala
------------------------------
Date: Wed, 11 Aug 1999 07:59:34 -0400
From: Duncan Hill <dhill@sunbeach.net>
Subject: Re: Improving speed of a sub
Message-Id: <Pine.LNX.4.10.9908110754120.20692-100000@bajan.pct.edu>
On 11 Aug 1999, Sam Holden wrote:
> On Tue, 10 Aug 1999 22:33:56 -0400, Duncan Hill <dhill@sunbeach.net> wrote:
> >if one person hits it, but if several hundred people hit the same part
> >at once, memory is gonna hurt.
> But surely a copyright notice is reasonably small anyway maybe a few hundred K.
In the case of a single CGI script calling a single file that is a
couple of K, yes. The snippet of code came from a CGI that handled 2
different files. One was the copyright, the other was the form that
required the copyright to be read. Now, lets assume that there are 40
such scripts running on the server, and some of the forms are (for
some reason) 40K+. It adds up after a while.
Yes, RAM is cheap.. and so are some managers. I'll grant you that the
server for this code in this case is a Real Slow 6000 with 256 MB
RAM.. so RAM usage is not a problem.. heck, system load is 1.00 or
less.. always. Well, until one of the faculty writes a Perl script
that has an infinite loop.
--
Duncan Hill Sapere aude
One net to rule them all, One net to find them,
One net to bring them all, and using Unix bind them.
------------------------------
Date: Wed, 11 Aug 1999 11:07:53 +0100
From: "James A. Duncan" <j@mesduncan.co.uk>
Subject: Re: IO::Socket dilemma
Message-Id: <37b14afe.0@news.proweb.co.uk>
IO::Select can handle this for you with the can_read and can_write methods
Regards,
James.
--
James A. Duncan
Systems Administrator @ WebFusion Internet Solutions
Brundle wrote in message <7oqmqu$ce4$1@nnrp1.deja.com>...
>This is not a problem with IO::Socket, but a fundemental lack of
>knowledge on my part.
>
>Say I initiate a TCP connection to a server, and we are speaking a
>protocol that goes back and forth of the same connection:
>
>local: 'hi'
>remote: 'how are you'
>local: 'fine thanks'
>
>This works fine with 'print $socket 'hi' and $response=<$socket>.
>
>But say the server doesnt always respond - sometimes I say something
>and they dont say anything back. Then I am blocked when I read on
><$socket>.
>
>How do I test $socket to see if there is data on the pipe before trying
>to read it?
>
>Any help much appreciated
>
>
>Sent via Deja.com http://www.deja.com/
>Share what you know. Learn what you don't.
------------------------------
Date: Wed, 11 Aug 1999 14:34:31 +0200
From: Erich Seifert <erich.seifert@dachau.baynet.de>
Subject: Mac perl2exe?
Message-Id: <37B16DD7.97529BA7@dachau.baynet.de>
I wonder if there's something like perl2exe for Apple Macintosh?
Thanx, Eric
--
* Anyone sending unwanted advertising e-mail to this address will be
charged $25 for network traffic and computing time. By extracting my
address from this message or its header, you agree to these terms.
* Hiermit widerspreche ich der Nutzung oder Uebermittlung meiner Daten
fuer Werbezwecke oder fuer die Markt- oder Meinungsforschung gemaess
Paragraph 28 Absatz 3 des Bundesdatenschutzgesetzes.
------------------------------
Date: Wed, 11 Aug 1999 15:11:26 +0200
From: Peter Huesser <huesser@physik.unizh.ch>
Subject: meaning of $mode (lstat)
Message-Id: <37B1767E.46679572@physik.unizh.ch>
This is a multi-part message in MIME format.
--------------CD96ECC13D67E82A805ABEA6
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Can anybody explain me the meaninig of the mode field in the lstat
returnvalue? For example a file with mode
-rwxr-xr-x gives the number 33261.
Thank's for any help
Pedro
--------------CD96ECC13D67E82A805ABEA6
Content-Type: text/x-vcard; charset=us-ascii;
name="huesser.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Peter Huesser
Content-Disposition: attachment;
filename="huesser.vcf"
begin:vcard
n:Peter;Huesser
x-mozilla-html:FALSE
org:Physikinstitut der Universitaet Zuerich
version:2.1
email;internet:huesser@physik.unizh.ch
x-mozilla-cpt:;0
fn:Huesser Peter
end:vcard
--------------CD96ECC13D67E82A805ABEA6--
------------------------------
Date: Wed, 11 Aug 1999 10:46:02 GMT
From: dave4000@my-deja.com
Subject: Menu Options
Message-Id: <7ork99$6u$1@nnrp1.deja.com>
I have the following large option menu (or problem!)
1.a
2.b
3.c
...
...
n.n
Enter Option:
To call any of the routines from the menu I have an equally
large if else (or elsif) statement, ie
if ($option == 1){
do subroutine1();
}else
if ($option == 2){
do subroutine2();
}
etc...etc
is there an easy way of calling these routines, as at the moment
the if else statements are more than 30 !!!!
Thanks
Dave
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Wed, 11 Aug 1999 13:30:39 +0200
From: "Trond Michelsen" <mike@crusaders.no>
Subject: Re: Menu Options
Message-Id: <eads3.159$wU.1131@news1.online.no>
<dave4000@my-deja.com> wrote in message news:7ork99$6u$1@nnrp1.deja.com...
> To call any of the routines from the menu I have an equally
> large if else (or elsif) statement, ie
> if ($option == 1){
> do subroutine1();
> }else
> if ($option == 2){
> do subroutine2();
> }
> etc...etc
>
> is there an easy way of calling these routines, as at the moment
> the if else statements are more than 30 !!!!
Yes. By using a hash of function references, you can do this very easily.
Pretty much copied from page 697 in the "Perl Cookbook":
-------------8<------------
%subs = (1 => \&subroutine1,
2 => \&subroutine2,
3 => \&subroutine3,
etc...
);
if ($subs{$option}) {$subs{$option}->()}
else {&default_subroutine}
-------------8<------------
Anyway - you should paste actual code in your posting
> }else
> if ($option == 2){
as this won't compile.
You probably use something like this:
} elsif ($option == 2) {
or even
} else {
if (option == 2) {
together with a bunch of closing brackets at the end.
--
Trond Michelsen
------------------------------
Date: Wed, 11 Aug 1999 11:49:40 +0100
From: Mark <Mark@Mark.Com>
Subject: Re: Mini-objects
Message-Id: <37B15544.1CD4663E@Mark.Com>
Sean McAfee wrote:
> Today I was looking for a way to simplify the making of Oracle queries
> using the DBI module. Each query call looked pretty much the same:
>
> my $sth = prepare $dbh "select ... from ...";
> execute $sth;
> while ($row = fetch $sth) { ... }
>
> ...not too bad, really, but I thought it would be better to factor out the
> common "prepare $dbh" and "execute" code and simply pass a SQL query to a
> function which would return a cursor-like object. But this didn't seem
> to be a big enough job to warrant a full-blown module, and I don't really
> like to put multiple unrelated packages in the same source file because I
> then have to always be aware of which package is in effect when I add new
> code. So after a bit of experimentation, I came up with the following
> approach:
<snipped>
The problem with packaging DBI methods is error checking. This is made more
difficult by putting the prepare/execute/fetch in a single function. In many
cases, you want to do specific things on failures of prepare or execute. For
example , using mod_perl (apache), you may need to remake the database
connection if an execute fails. Also, don't forget 'finish'
I agree that the construct:
if ($sth = $dbh->prepare...)
{
if ($rc = $sth->execute)
{
while ($res = $sth->fetch)
{
......
}
}
else # execute failed
{}
}
else # prepare failed
{}
is very long winded but if you need to do different things on different fails.
- Mark
------------------------------
Date: Wed, 11 Aug 1999 08:43:32 -0500
From: Kevin Newman <knewman@mcs.com>
Subject: New to Perl: File manipulation Question
Message-Id: <37B17E04.572475CD@mcs.com>
Hi All,
I'm very new to PERL and have a few questions on how to create :
1) an edited temprary file of an original file that is being read in
2) edit and save the original file in place
What I'm trying to do is open a file then extract a string. After this
string has been stored to a variable, I want to remove the additional
white space from the end of each line and use this edited text to send
to a printer a number of times determined by the string value. Sounds
simple enough? I am able to create the temporary file but I get the
error message:
Use of uninitialized value at "filename" line nn, <> chunk nn.
Where "filename" = the perl filename and nn = a number.
What does this mean? How do I correct it? Below is an example of what
I've done so far. Thanks in advance for your help
Kevin Newman
knewman@mcs.com
#!/usr/bin/perl -w
use Getopt::Std;
# Define the command line printer options
getopts("d:");
@ARGV == 1 or die "usage: label_printer -d<printer> \n";
if($opt_d or die){
print "Printer Destination: $opt_d \n";
}
$command_line = join ($",@ARGV);
print "Line Print Command $command_line \n";
$line_print = "lp";
# Assign the command line printer options list
$print_options = "-d$opt_d";
print "Print Options: $print_options \n";
# Initialize found_copies to 0
$found_copies = 0;
#Just a temp file. I would really like the
# filename to be the original filename.tmp
$new = "dummy2";
# Look for the Keyword ^FX COPIES = nnn ^FS (Case is not important)
# if one occurance of the copies line is found the if statement will
# not be entered again, but the file will continue to be cleaned of
spaces
open (NEW, "> $new") or die "can't open $new: $!";
select (NEW);
while ($line = <> ) {
if ($line =~ m/^(\^FX\s*COPIES\s*\=\s*([0-9]+)\s*\^FS)/i &&
$found_copies == 0)
{
#DEBUG CODE
print "inside of the if statement";
$nmbr_of_labels = $2;
$found_copies++;
#DEBUG CODE
print "FOUND COPIES = $found_copies \n";
}
$line =~ s/ *$/END/;
print NEW $_ or die "can't write $new: $!";
print $line;
}
close(NEW) or die "can't close $new: $!";
# Now print the labels
# for ($i = 0; $i < $nmbr_of_labels; $i++) {
# @args = ($line_print, $print_options, $command_line);
# print "@args \n";
# system(@args) == 0 or die "system @args failed: $?"
#}
#
------------------------------
Date: Wed, 11 Aug 1999 06:02:50 -0600
From: Ron Reidy <rereidy@uswest.net>
Subject: Re: Perl & Oracle in a webserver.... environment variable problems
Message-Id: <37B1666A.430AC1DC@uswest.net>
lianthe@my-deja.com wrote:
> I'm using Perl5 and Oracle (through DBD/DBI) to modify some cgi programs
> to write to a database. In Netscape Suitespot webserver on Solaris, the
> scripts do not work. I've tracked it down to the missing environment
> variables ORACLE_HOME and LD_LIBRARY_PATH. I tried setting
> $ENV{LD_LIBRARY_PATH} and $ENV{ORACLE_HOME}, but that only helps in a
> subshell, not in the current shell. I was able to "kludge" my test
> script by writing a wrapper around it that set these variables, but that
> won't really work for my real project (and it's a performance hit as
> well).
>
> I've tried many things:
> * the webmaster account (that the script runs as) has the right vars set
> * the default .profile has the right vars in
> * the vars are set and exported in the server's start script
> * I don't see anywhere in the webserver setup to set the vars
>
> Any other things I can try? There's got to be a way to do this?
>
> Thanks,
> Kevin
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
Set the environment vars in your cgi program.
$ENV{ORACLE_HOME} = '/usr/local/oracle/product/8.1.5';
$ENV{LD_LIBRARY_PATH} = $ENV{ORACLE_HOME} . '/lib';
$ENV{ORACLE_SID} = 'WEB_APP';
--
Ron Reidy
Oracle DBA
Reidy Consulting, L.L.C.
------------------------------
Date: 11 Aug 1999 14:28:58 +0400
From: Victor Wagner <vitus@zinc.fe.msk.ru>
Subject: Re: perl on linux
Message-Id: <37b1506a.0@news.rtsnet.ru>
Nir Leshem <nirl@zoran.co.il> wrote:
> hi all...
> does anybody know why my linux shell doesnt recognize the 'shebang' notation (#!/usr/..../perl
May be your script uses DOS end-of-line convention?
Try to load it in vim and then type
:set notx
:wq
> im surly using the correct path, and chmod my script to +x
> and also encountered no problems running my script via the shell (i.e. perl foo.pl)
> help....
> nir.
> --------------------------------------------------------------------
> Nir Leshem
> VLSI group E-mail nirl@zoran.co.il
> ZORAN Microelectronics LTD Tel : 972-4-8545911
> Advanced Technology Center Fax : 972-4-8551550
> P.O.B. 2495, Haifa 31204, Israel www : http://www.zoran.com
> --------------------------------------------------------------------
--
--------------------------------------------------
Victor Wagner vitus@ice.ru
Programmer Office:7-(095)-964-0380
Institute for Commerce Home: 7-(095)-135-46-61
Engineering http://www.ice.ru/~vitus
------------------------------
Date: Wed, 11 Aug 1999 15:06:02 +0200
From: "Trond Michelsen" <mike@crusaders.no>
Subject: Re: perl on linux
Message-Id: <Gzes3.227$wU.1511@news1.online.no>
Victor Wagner <vitus@zinc.fe.msk.ru> wrote in message
news:37b1506a.0@news.rtsnet.ru...
> > does anybody know why my linux shell doesnt recognize the 'shebang'
notation (#!/usr/..../perl
> May be your script uses DOS end-of-line convention?
> Try to load it in vim and then type
> :set notx
> :wq
or you can do it with perl...
perl -e 'while(<>){s/\cM//g;print}' < oldscript.pl > fixedscript.pl
--
Trond Michelsen
------------------------------
Date: Wed, 11 Aug 1999 13:58:30 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Re: Perl Question - NOT !
Message-Id: <7orvna$t02$1@news.mch.sbs.de>
In article <7oqcg1$572$1@nnrp1.deja.com>, jsmith19991@my-deja.com wrote:
>I'm having a problem with a perl script. The problem
>we are having is with the E-mailing of information to a
>client. To make it simple, the scriptsends an Email to
>someone after they enter their address (Mary Smith in
>the following example). The script includes the following
>lines for sending the mail:
[ploink?]
This question has already been answered elsewhere.
You need to give a fully-qualified e-mail address to
sendmail, like jsmith19991@my-deja.com, rather than
just 'John'.
Michel.
Sent to Deja.com http://www.deja.com/
Learn that you can't share what you don't know.
------------------------------
Date: Wed, 11 Aug 1999 13:41:09 GMT
From: hiwi1krg@iitb.fhg.de (TM Lehto)
Subject: perldoc problem
Message-Id: <37b17a91.93284756@iitb>
Hi,
Whenever I have a Perl problem I always use perldoc extensively before
posting here in this NG (usually I find answers from there too,
although this problem isn't covered by FAQ).
Problem is that perldoc leaves a .perldoc directory in /tmp/ and when
I run perldoc again, I get message like this:
mkdir /tmp/.perldoc: File exists at /usr/bin/perldoc line 352.
I'm getting tired of removing that directory manually every time I
want to use perldoc command.
Any ideas how to fix it?
Perl version is Perl 5.005, patch 2 and it's running on SuSE Linux 6.1
kernel 2.2.5
Thanks,
Tomi
------------------------------
Date: 11 Aug 1999 13:49:01 GMT
From: M.Ray@ulcc.ac.uk (Malcolm Ray)
Subject: Re: Re: Re: pipes and file handles
Message-Id: <slrn7r2vqd.1ko.M.Ray@carlova.ulcc.ac.uk>
On Wed, 11 Aug 1999 08:49:16 GMT, slmlambert@my-deja.com
<slmlambert@my-deja.com> wrote:
[snip code not working on NT due to lack of fork]
>Yeah - I initially tried it at work under NT much to my pain. No luck
>and some really bizzarre error msgs. I think that it has a problem
>with the '|-'.
>
>> Incidentally, I've been remiss in not commenting on portability.
>> I suspect that this would *not* work under Windows (of any flavour)
>> at present, due to its inability to fork processes.
>
>I took it home last night and tried it under Linux and there were no
>problems. Why are there no suprises there?
>
>I think that it might be time to change tack. If NT has an issue with
>the pipes then it may be easier to ftp manually via socket connection.
>Thoughts?
Possibilities:
1. Use a tied filehandle. This is a way (see 'perldoc perltie') of
making I/O on a filehandle automagically call functions you supply.
This is moderately hairy, and I suspect it wouldn't work in this case,
because a quick peek at Net::FTP reveals that it uses file descriptors
(and a tied filehandle doesn't have an underlying file descriptor).
2. Use a pipe within the same process. See 'perldoc -f pipe' for a
function which creates a pair of filehandles at either end of a pipe.
Pipes are generally used between processes, but there's no reason why
you couldn't use one within your single process. Beware of buffering
problems, though.
3. Use a temporary file. Generate a temporary filename, open the
file for writing, write the scalar to it, close it, use Net::FTP to
send it, then delete it.
4. Wait for Activestate and Microsoft to implement fork!
--
Malcolm Ray University of London Computer Centre
------------------------------
Date: 11 Aug 1999 11:22:52 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Reading the Online Documentation?
Message-Id: <7ormec$omq$1@lublin.zrz.tu-berlin.de>
Larry Rosler <lr@hpl.hp.com> wrote in comp.lang.perl.misc:
>In article <37B03E31.2C79F52C@texas.net> on Tue, 10 Aug 1999 09:58:57 -
>0500, Tom Briles <sariq@texas.net> says...
>> I can attest to at least one thing that Larry *doesn't* know. So there!
>
>Oh, yeah? Tell me what that might be. (And then I'll know it.
>Hehehe.)
Now, that's great! Let me tell you you don't know why I always get
"Premature end of headers..." from my CGI. Will you now just tell
me...
Oh, I got it, it's in line 17.
Anno
------------------------------
Date: Wed, 11 Aug 1999 14:22:33 +0200
From: Erich Seifert <erich.seifert@dachau.baynet.de>
Subject: Regexp newbie
Message-Id: <37B16B08.2C61206B@dachau.baynet.de>
Hi,
My problem: I'm not very familiar with regular expressions, but I want
to replace each of the leading spaces in a string with another string.
Who can help me?
Eric
--
* Anyone sending unwanted advertising e-mail to this address will be
charged $25 for network traffic and computing time. By extracting my
address from this message or its header, you agree to these terms.
* Hiermit widerspreche ich der Nutzung oder Uebermittlung meiner Daten
fuer Werbezwecke oder fuer die Markt- oder Meinungsforschung gemaess
Paragraph 28 Absatz 3 des Bundesdatenschutzgesetzes.
------------------------------
Date: Wed, 11 Aug 1999 12:46:51 GMT
From: backwards.saerdna@srm.hc (Andreas Fehr)
Subject: Re: Regexp newbie
Message-Id: <37b16f5f.26086710@news.uniplus.ch>
On Wed, 11 Aug 1999 14:22:33 +0200, Erich Seifert
<erich.seifert@dachau.baynet.de> wrote:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sorry, you have to charge my news reader...
>My problem: I'm not very familiar with regular expressions, but I want
>to replace each of the leading spaces in a string with another string.
>Who can help me?
The documentation! Try: perldoc -q space
Should be to demanding...
>* Anyone sending unwanted advertising e-mail to this address will be
>charged $25 for network traffic and computing time. By extracting my
>address from this message or its header, you agree to these terms.
Don't agree anything, but:
Anyone sending messages to this newsgroup without reading the
documentation will be charged $25 for network traffic and computing
time. And that is cheap!
Andreas
------------------------------
Date: Wed, 11 Aug 1999 13:54:50 GMT
From: backwards.saerdna@srm.hc (Andreas Fehr)
Subject: Re: Regexp newbie
Message-Id: <37b17f46.3083213@news.uniplus.ch>
On Wed, 11 Aug 1999 12:46:51 GMT, backwards.saerdna@srm.hc (Andreas
Fehr) wrote:
>Should be to demanding...
^ ^
n't o
My English strikes back...
Andreas
------------------------------
Date: Wed, 11 Aug 1999 09:35:19 -0700
From: "G. Kuhnert" <jkuhnert@harbingercomm.com>
Subject: Scalar context?
Message-Id: <37b17b81.0@news.kivex.com>
I know this is a stupid question....but, can someone tell me what's wrong
with this statement? I've researched the FAQ's etc....but must be missing
something.
------------------------------------------------------------------
if ($input{'password'} eq $user{'password'}) {
do this..
} else {
do this..
}
------------------------------------------------------------------
Where both values should equal "cat"? I don't know why it won't work. I've
tried every combination that I can think of to get it, but it just refuses
to believe that 'cat' is 'cat'.
file is on www.calnet.com/login.html
Thank you,
George
Here is the complete code if it helps:
#! /usr/local/bin/perl
use FileHandle;
&ReadParse(*input);
$dir=$input{'username'};
$it=$dir.".dat";
open(THISFILE, "jkuhnert.dat");
# initial user data file reading
while($line=<THISFILE>) {
chomp($line);
($key, $value)=split('=', $line);
$user{$key}=$value;
}
close(THISFILE);
$password=$input{'password'};
$pass=$user{'password'};
if ($password eq $pass) {
print"Content-type: text/html\n\n";
print <<EOF;
<HTML>
<HEAD>
<TITLE>Login Debug</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF"><center><br><h2>User Login</h2><hr><br><br>
Login was successfull!!!!
</center>
</BODY>
</HTML>
EOF
;
} else {
print"Content-type: text/html\n\n";
print <<EOF;
<HTML>
<HEAD>
<TITLE>Login Debug</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF"><center><br><h2>User Login</h2><hr><br><br>
Login was not successfull!!<br><br>
The line is $value $it<br><br>File: $file
<br><br><br>Password $hmm<br><br>Input Password: $hmm<br>
Real Password: $real<Br><br>$real$hmm
</center>
</BODY>
</HTML>
EOF
;
}
------------------------------
Date: Wed, 11 Aug 1999 14:56:08 +0200
From: "Trond Michelsen" <mike@crusaders.no>
Subject: Re: suggestions for CRAP
Message-Id: <oqes3.213$wU.1187@news1.online.no>
Jeff Pinyan <jeffp@crusoe.net> wrote in message
news:Pine.GSO.4.10.9908101833130.19643-100000@crusoe.crusoe.net...
> THE AUTHOR SPEAKS! :)
> On Aug 10, Uri Guttman blah blah blah:
> > possibly. let's see where this goes.
> If you ask me, and perhaps you should, I would be thrilled to have a
> section of CRAP's web site (soon to be at http://www.mattright.com/) to be
> a CGI Repository. The CRAP project is beginning to pick up speed -- I'm
> waiting for a couple articles to be written -- and this site should become
> a well-tapped resource.
I dont mean to step on any toes here, but wouldn't it be a good idea to
sweep through CPAN first and identify poor/sloppy modules first?
I mean. I trust CPAN almost blindly. If I find some module that promises to
do something that I'm looking for, I'll download and install it, and I more
or less never consider implementing the functionality myself. However I have
absolutely no idea about the efficiency or security of the module.
Then there are also a couple of modules that does the same job (eg.
Net::NNTP / News::NNTPClient) so it could be nice to have a comparison
between similar modules and a "recommended modules"-list. (Well - I guess
that if the module makes it into the standard distribution it will classify
as "recommended", but nevertheless..)
Friedl's regex-book identifies a few modules that uses $' $& and $` in
regexes and thereby slowes down all regexes in your program. An
electron-based form of this list would also be nice.
--
Trond Michelsen
------------------------------
Date: Wed, 11 Aug 1999 12:33:50 GMT
From: pudge@pobox.com (Chris Nandor)
Subject: Re: Upload file from mac
Message-Id: <pudge-1108990833530001@192.168.0.7>
In article <37af50ab@news.datacomm.ch>, "LongDan" <longdan@datacomm.ch> wrote:
>I am trying to upload a file trough perl. it works pperfect from pc, but on
>the mac i am getting problems. i think because when i transmit a file from
>mac, i get the data and ressource fork in the same file.
What kind of "upload"? FTP? TFTP? NFS? SMB? Sneakernet?
--
Chris Nandor mailto:pudge@pobox.com http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10 1FF77F13 8180B6B6'])
------------------------------
Date: 11 Aug 1999 14:02:05 GMT
From: bbirthisel@aol.com (Bbirthisel)
Subject: Re: using alarm under win32
Message-Id: <19990811100205.00585.00000604@ng-bg1.aol.com>
Hi Brian:
>I can't get alarm() to work under win32.
No. You won't. $MS architectural limitation (unless you are
a ring 0 driver).
>how I intended to use it. This works under unix:
>
>print "Enter a number:";
>eval{
> local $SIG{ALRM} = sub { die };
> alarm 5;
> $no = <STDIN>;
> print "You typed $no\n";
> alarm 0;
> 1;
>} or print "Too Late!\n";
You can do what you want with Term::Readkey. That part
does work on Win32.
-bill
Making computers work in Manufacturing for over 25 years (inquiries welcome)
------------------------------
Date: 11 Aug 1999 13:04:20 GMT
From: mgm@unpkhswm04.bscc.bls.com (Mitchell Morris)
Subject: Re: Why use Perl when we've got Python?!
Message-Id: <slrn7r2t6k.ik0.mgm@unpkhswm04.bscc.bls.com>
In article <37B0E525.B8ED0EAC@erols.com>, Matthew O. Persico wrote:
>
>
>Mitchell Morris wrote:
>>
>[snip]
>
>> All that said, I really wish that nested structures in Perl were as simple to
>> read and write as Python's. I can write $hash{$key}->[0] as well as the next
>> guy, but damnit I don't really want to be managing the references myself.
>>
>
>Then don't. If you omit the ->, it still works.
>
>Try it.
>
>--
>Matthew O. Persico
>
>You'll have to pry my Emacs from my cold dead oversized
> control-pressing left pinky finger. -- Randal L. Schwartz
Hmmph. Perhaps I contrived an insufficiently contrived example. Let me steal
one from TomC's supa-lovely "perldoc perldsc":
#! /usr/local/bin/perl -w
use strict;
my $listref = [
[ "fred", "barney", "pebbles", "bambam", "dino", ],
[ "homer", "bart", "marge", "maggie", ],
[ "george", "jane", "elroy", "judy", ],
];
print $listref->[2][2];
This one requires the arrow. I had (I suppose) formed the habit long ago of
always including the arrow since that seems easier than memorizing when it's
actually required versus when it's optional.
Oh well ... learn something new every day.
--
Mitchell Morris
You people all use ADSL to be cool, right? I'm still using ATM, because I
don't like TrueType.
-- Kibo
------------------------------
Date: Wed, 11 Aug 1999 10:43:49 +0100
From: "Declan" <dcaddell@talk21.com>
Subject: win32 Net::SMTP
Message-Id: <37b145c6.0@nnrp1.news.uk.psi.net>
This is a multi-part message in MIME format.
------=_NextPart_000_0014_01BEE3E6.656A4880
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
All,
I am currently using perl win32 Net::SMTP to send a mail message. Has =
anyone an example of sending a text message and an attachment.=20
Many Thanks,
D.=20
------=_NextPart_000_0014_01BEE3E6.656A4880
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>
<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type>
<META content=3D'"MSHTML 4.72.3110.7"' name=3DGENERATOR>
</HEAD>
<BODY>
<DIV>All,</DIV>
<DIV> </DIV>
<DIV>I am currently using perl win32 Net::SMTP to send a mail =
message. Has=20
anyone an example of sending a text message <STRONG>and</STRONG> an =
attachment.=20
</DIV>
<DIV> </DIV>
<DIV>Many Thanks,<BR>D. </DIV></BODY></HTML>
------=_NextPart_000_0014_01BEE3E6.656A4880--
------------------------------
Date: Wed, 11 Aug 1999 10:38:37 GMT
From: backwards.saerdna@srm.hc (Andreas Fehr)
Subject: Re: win32 Net::SMTP
Message-Id: <37b15267.18671187@news.uniplus.ch>
On Wed, 11 Aug 1999 10:43:49 +0100, "Declan" <dcaddell@talk21.com>
wrote:
>This is a multi-part message in MIME format.
use this ^^^^ ...
...but _not_ here!!!
Andreas
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 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.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. Due to their sizes, neither the Meta-FAQ nor
the FAQ are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq" from
almanac@ruby.oce.orst.edu.
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 459
*************************************