[11629] in Perl-Users-Digest
Perl-Users Digest, Issue: 5229 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 25 19:07:22 1999
Date: Thu, 25 Mar 99 16:00:23 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 25 Mar 1999 Volume: 8 Number: 5229
Today's topics:
Re: "seeding" the time function <cassell@mail.cor.epa.gov>
Re: [AJM] CGI.pm Cookie question (Murphy)
Re: accessing class specific variables in inherited cla <gisle@aas.no>
Re: array question gwebb@reedtech.com
Re: Calculating the current time in London or GMT+x <cassell@mail.cor.epa.gov>
calendar files <rzeuner@buyitnow.com>
Copying and renaming files with invalid filenames <nick_hall@usa.net>
DNS Module for Perl <rose@gsc.nrcan.gc.ca>
Re: don't understand ||= operator <juex@my-dejanews.com>
Re: FFT/FT in perl? (brian d foy)
Re: How do you extract the desc. out of a meta tag? <gellyfish@gellyfish.com>
Re: HTTP:Request. POST method adding HTTP/1.0 to header <gisle@aas.no>
Re: Looking For a Module? <gellyfish@gellyfish.com>
Re: LWP Question <gisle@aas.no>
Re: need help getting started! <cassell@mail.cor.epa.gov>
Re: Need tips on improving performance. <ebohlman@netcom.com>
Re: Parsing text file (Tad McClellan)
Re: Perl Conference 3.0 in Monterey, California, Aug. 2 (brian d foy)
perl for win32 <brian.vivian@virgin.net>
Problem writing a file... file permissions ok on comput <wflanagan@msn.com>
Q: redefined subroutines <jacklam@math.uio.no>
Re: Quicksort won't work <cassell@mail.cor.epa.gov>
Reading results of external commands <mriggsby@sybex.com>
Running a perl script as a daemon.... <tim@diggy.com>
Re: Standard Deviation <ebohlman@netcom.com>
Re: String Limit in IE? <cassell@mail.cor.epa.gov>
String Manipulation -cgi/perl jatgal@my-dejanews.com
Re: String Manipulation -cgi/perl <jglascoe@giss.nasa.gov>
Re: String manipulation jatgirl@yahoo.com
Re: threaded perl <sugalskd@netserve.ous.edu>
Re: Too Late for -T error <cassell@mail.cor.epa.gov>
Re: Urgent: Document contains no data (Tad McClellan)
Re: WHY: open (HPIPE, "| notexistfile") or die "..."; D (Tad McClellan)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 25 Mar 1999 15:11:07 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: "seeding" the time function
Message-Id: <36FAC28B.CFFF277@mail.cor.epa.gov>
Dave Heaney wrote:
> Is there a function in Perl that can take a month, day, year, time set
> of arguments, and return the number of seconds from the epoch to that
> time? Or am I off to write my own? If it's not actually part of Perl,
> but someone else has it out there, it would be great if I could take a
> look at it. My version's not very efficient, and it's off by 5 hrs...
Wow, 5 hours?? Err, umm, sorry. I'm sure when you were reading the
FAQ you just missed it. And when you were reading about localtime().
Get Time::Local from CPAN. It has a function timelocal() that does
exactly what you want. And it's accurate down to leap seconds..
which isn't Perl's fault.
David
--
David L. Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 26 Mar 1999 03:24:21 GMT
From: jt45@tir.com (Murphy)
Subject: Re: [AJM] CGI.pm Cookie question
Message-Id: <36fe2fd8.3518085@news.supernews.com>
On Thu, 25 Mar 1999 03:34:51 GMT, jt45@tir.com (Murphy) wrote this
little gem:
>>> $cookie1=cookie(-name=>'name',-value=>$fname);
>>> $cookie2=cookie(-name=>'nic',-value=>$nic);
>>> print header(-cookie=>[$cookie1,$cookie2]);
>
>Ok, thanks. But this doesn't explain why my script won't send the
>cookie info to the browser. If I use traditional methods of sending
>cookies through Perl or through JavaScript, there's no problem. But
>as soon as I try to use the above mentionned (original) code, it
>doesn't do squat.
My goofiness is showing.
The cookies are being recorded by the browser, but because I did not
include an expiration date, they were not put in the database.
Putting in an expiration date fixed that.
Thanks again.
Murphy
-----------
jt45@tir.net
"Trying is the first step towards failure" - Homer J. Simpson
"Programming isn't about Java or Visual Basic. It's about real Languages" - CDI Commercial
------------------------------
Date: 25 Mar 1999 22:07:07 +0100
From: Gisle Aas <gisle@aas.no>
Subject: Re: accessing class specific variables in inherited classes
Message-Id: <m3g16tjn2c.fsf@eik.g.aas.no>
Tom Christiansen <tchrist@mox.perl.com> writes:
> :use lib(".");
>
> That does nothing. Dot is already in your path.
It makes a difference since dot is not first in path.
--
Gisle Aas
------------------------------
Date: Thu, 25 Mar 1999 22:41:48 GMT
From: gwebb@reedtech.com
Subject: Re: array question
Message-Id: <7dee39$acf$1@nnrp1.dejanews.com>
In article <MPG.1162f5ba39bacaf59897ba@nntp.hpl.hp.com>,
lr@hpl.hp.com (Larry Rosler) wrote:
> > $file_extension =~ s/[^.]\.//g;
>
> $file_extension =~ s/[^.]*\.//g;
>
> But to deal with 'foo.bar.txt' properly, you want:
>
> $file_extension =~ s/.*\.//g;
Thanks for catching my missing '*'. However with the star added
$file_extension =~ s/[^.]*\.//g;
will properly deal with 'foo.bar.txt'. Also note that the 'g' flag is
unnecessary in your case since '.*' will slurp up the whole string, then
backtrack to the first '.' character it finds.
Garth
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Thu, 25 Mar 1999 15:26:40 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: Calculating the current time in London or GMT+x
Message-Id: <36FAC630.3A48F9B7@mail.cor.epa.gov>
Neil Johnson wrote:
> The element [8] of the the array returned by local time will indicate if daylight
> saving is in action where the server is situated. However this will not help with
> the time in London.
Umm, you accidentally typed a space in 'localtime()'. However, it is reasonable
to
get GMT just by using the gmtime() function.
> Californian daylight saving , I believe is very similar to British and European
> daylight saving. The only difference is that in Britain and Europe the clocks go
> forward a week earlier than California (28th March). The clocks go back on the
> same date.
I'll take your word on that one. Dunno. But (gmtime)[9] should give you
the $isdst for GMT at that moment. Remember that gmtime and localtime get their
info straight out of a struct tm so 'year' needs to have 1900 added to it.
David
--
David L. Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Thu, 25 Mar 1999 16:37:56 -0700
From: ray zeuner <rzeuner@buyitnow.com>
Subject: calendar files
Message-Id: <36FAC8D4.49573826@buyitnow.com>
Hello,
Doesn anyone know of any calendar.pl files that work under unix. Such as
retrieving the current months data into some type of array.
thanks
ray
------------------------------
Date: Thu, 25 Mar 1999 23:34:24 GMT
From: Nick Hall <nick_hall@usa.net>
Subject: Copying and renaming files with invalid filenames
Message-Id: <7deh60$d00$1@nnrp1.dejanews.com>
Hi,
I just got a CD-R from a company that used a Mac to create all the datasets
(and burn the CD). It is filled with a whole bunch of files with invalid
filenames that don't even come close to ISO9660 (or Joliet, or whatever).
There are directories that look like:
SECTION 25/26
99' Priced Sec. 03
and files that look like:
03-7974/7975
If I try to read in these files with a "cat" command under linux or "cd" to
these directories, I get an error about the path not being found. I even
tried it under windows in a fleeting hope, but to no avail. I need to be able
to read these files. I was wondering if someone would help me out. Ideally, I
need a program that can go through the CD and copy the entire thing to the
hard drive and if it finds any bad filenames, it will change the invalid
character to something else (probably a "-" or something like that). The
problem I've been having is that whatever command (e.g. "cp") I try to copy
the files, it reports that it can't find the file. Can someone help me
please? I appreciate any help.
Nick
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Thu, 25 Mar 1999 16:45:42 -0700
From: "David Rose" <rose@gsc.nrcan.gc.ca>
Subject: DNS Module for Perl
Message-Id: <7dehpa$if21@nrn2.NRCan.gc.ca>
I need to reconcile Internet addresses for out domain and would like to know
if Perl can handle the job. I've checked at CPAN and there is a DNS module,
however, its several years old and mentions that it is buggy.
My preferred platform for Perl is Win95, however, I can also run it on a
number of Unix systems.
Many Thanks
- Dave Rose
--
================================================
David Rose, Gological Survey of Canada, Calgary
Phone: (403) 292-7129 Fax: (403) 292-5377
E-Mail: rose@gsc.nrcan.gc.ca
------------------------------
Date: Thu, 25 Mar 1999 14:15:13 -0800
From: "J|rgen Exner" <juex@my-dejanews.com>
Subject: Re: don't understand ||= operator
Message-Id: <7decap$8ai@news.dns.microsoft.com>
Jane Dudley <jdudley@inna.net> wrote in message
news:Pine.BSF.3.96.990325130952.11408A-100000@butterfly.inna.net...
> Hello, all.
>
> I am trying to understand a script fragment I found, that has an ||=
> expression. I looked at
> http://www.effectiveperl.com/recipes/searching.html and
> http://www.codebits.com/p5be/ch04.cfm, which have brief explanations, but
> I'm afraid I don't understand them. I think I don't understand the
> difference between |, which is "bitwise" and || which is "logical."
> (Hey, I'm a mechanical engineer. Either there IS water flowing in that
> pipe OR there isn't. There ain't no logical or bitwise flow about it).
Well, using bitwise OR you got a set of two times 8 pipes (could be 16 or 32
pipes but for the sake of argument let's stay with 8) for water input and
one set of 8 pipes as output.
Whenever at least one of the corresponding pair of input pipes has water,
then the corresponding output pipe has water, too.
This means:
WWNNWNNN
NWWWNNWN
===========
WWWWWNWN
N = No Water
W = Water
For logical OR you got only one output pipe. Whenever at least one of the
input pipes has water, then the single output pipe has water, too. This is
what you usually want when writing e.g. conditions and comparing results.
The bitwise OR is a programmers hack for people, who are too familiar with
C.
jue
--
J|rgen Exner
------------------------------
Date: Thu, 25 Mar 1999 17:31:42 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: FFT/FT in perl?
Message-Id: <comdog-ya02408000R2503991731420001@news.panix.com>
In article <7ddt69$qcs$1@nnrp1.dejanews.com>, mnanao@sbl.salk.edu posted:
> Does anyone have any routines for calculating FFTs or FTs
> in perl? I'm sure there is a way to embed a C/C++ FFT into
> perl, but I'm looking for actual perl code, if possible. TIA,
perhaps you just want to hook up a C library through XS or SWIG?
otherwise it could be a SFT ;)
--
brian d foy
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
------------------------------
Date: 25 Mar 1999 22:07:29 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: How do you extract the desc. out of a meta tag?
Message-Id: <7dec31$qj$1@jns.dircon.co.uk>
On Thu, 25 Mar 1999 12:01:14 -0800 Rollo Lawson wrote:
> I have been writing a simple search program in Perl to search my website. I
> have looked around to see where I can find out how they extract the meta tag
> description value to no avail. Can someone show me the simple syntax on how
> to do this. Iam just trying to add a simple description to the search
> results my script generates.
>
You probably want to use the HTML::HeadParser module or similar - there is
an example 'dir2html' at <http://www.btinternet.com/~gellyfish/resources/>.
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 25 Mar 1999 21:58:09 +0100
From: Gisle Aas <gisle@aas.no>
Subject: Re: HTTP:Request. POST method adding HTTP/1.0 to headerr
Message-Id: <m3lngljnha.fsf@eik.g.aas.no>
Peter Leo Feng <plf58@leland.Stanford.EDU> writes:
> $url="www.perl.com/cgi-bin/email-grabber/grabber";
> $request= new HTTP::Request("POST",$url);
You need "http://" prepended to your URL. If you want to use "URIs"
like that they you should look at the URI::Heuristic module. It
should allow you to get away with "perl/cgi-bin/..." too.
> $url="www.perl.com/cgi-bin/email-grabber/grabber";
> $request= new HTTP::Request("POST",$url);
> $request->header('Accept'=>'text/html');
> $request->header('Content-type'=>'text/html');
> $request->header('Content-length'=> 2);
> $content=<<Cont;
> NAME="emailaddr" VALUE="plf58\@sbh.com"
> Cont
> $request->content($content);
To me this content does not look like text/html or of length 2.
--
Gisle Aas
------------------------------
Date: 25 Mar 1999 21:55:25 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Looking For a Module?
Message-Id: <7debcd$os$1@jns.dircon.co.uk>
In comp.lang.perl.misc Steven Arnott <Steven.Arnott@soton.sc.philips.com> wrote:
> Hi,
> I'm looking for a module that would give my program to ability to read
> and write simple option files. Anyone know of such a module?
There are a number of Modules available from CPAN that can do this - I
have favoured IniConf in the past but your view might differ as to what
kind of format file you want.
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 25 Mar 1999 22:01:24 +0100
From: Gisle Aas <gisle@aas.no>
Subject: Re: LWP Question
Message-Id: <m3iubpjnbv.fsf@eik.g.aas.no>
Donny Widjaja <donny@impulsesoftware.com> writes:
> I am trying to make a connection with another server to process a credit
> card transaction. I pass all the information by using LWP::UserAgent
> module. The method I use is $agent->request($request_info,
> \&parseReturn);
> Inside the parseReturn procedure, I process the return value from the
> request and need to return two variables back to the main program, but I
> don't know how can I return those value.
Set global (or lexical) variables available to both the callback and
the rest of the main program. You might find it easier not to use the
callback form of the $agent->request method.
--
Gisle Aas
------------------------------
Date: Thu, 25 Mar 1999 15:39:23 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: need help getting started!
Message-Id: <36FAC92B.DEC70EB2@mail.cor.epa.gov>
sheela tiwary wrote:
> Hi,
> I have a simple perl script that works fine when I run it in the UNIX
> environment. However it won't run on the web-page, the web page just
> displays the contents of the file instead of the results.
>
> I would appreciate any suggestions on how to fix this problem.
Sheela, this is really a question for the newsgroup
comp.infosystems.www.authoring.cgi , but let me go ahead and
give you a little advice. Check out this ruthlessly-named doc:
http://www.perl.com/faq/idiots-guide.html
and please don't be offended by the name. I think you'll see
that your answer is in there.
David
--
David L. Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Thu, 25 Mar 1999 23:15:05 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Need tips on improving performance.
Message-Id: <ebohlmanF96B95.ILs@netcom.com>
Gift Registry <webmaster@giftregistry.hypermart.net> wrote:
: I currently have a large script, about 100k, which runs a site. I
: suspect that I can improve performance substantially by splitting this
: script up into smaller, logically related pieces. Is this true?
It's impossible to say without knowing exactly where your performance
hits are coming from. If most of the time is being spent forking off a
Perl process and compiling the script, with relatively little time spent
actually *running* the script, then that might help (though not as much
as using something like mod_perl or FastCGI). If, OTOH, most of the time
is spent in the actual execution of the script, then you'll get minimal
improvement.
If you're accessing database servers, you're probably taking a *big* hit
if you have to open a connection to the database server each time the
script is invoked. There are extensions to the technologies mentioned
above that will allow you to maintain persistent database connections;
I'm not very familiar with the details, but a DejaNews search of
comp.infosystems.www.authoring.cgi should turn something up. If that's
your problem, fixing it should *really* speed things up.
: If I break up large scripts into a series of smaller scripts which are
: conditionally pulled in during runtime with a conditional REQUIRE, will
: performance likely improve?
One can only guess. Why not try some profiling and see where you're
spending most of your time?
------------------------------
Date: Thu, 25 Mar 1999 12:34:34 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Parsing text file
Message-Id: <a3sdd7.3n.ln@magna.metronet.com>
Alan Scott (balanscott@earthlink.net) wrote:
: I need to read a test file into an array so I can then write it out as a
: different file. How would I do this????
What part are you stuck on?
How to open a file?
How to read a file?
How to put things into an array?
How to print the output?
...
Show us the code you have so far and we will help you fix it.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 25 Mar 1999 17:34:13 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Perl Conference 3.0 in Monterey, California, Aug. 21-24
Message-Id: <comdog-ya02408000R2503991734130001@news.panix.com>
In article <36f94bc7$0$217@nntp1.ba.best.com>, John Callender <jbc@shell2.la.best.com> posted:
> John Robson <as646@FreeNet.Carleton.CA> wrote:
>
> > Have you attended past Perl Conferences and what do you think of it? How
> > much does it cost and do you think it's worth your money and time? What
> > kind of folks do you find there? Did you learn much?
>
> I attended the first two, and really enjoyed them. I think I did get a
> lot of useful information out of them as well.
the biggest benefit of conferences is meeting people ;)
--
brian d foy
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
------------------------------
Date: Thu, 25 Mar 1999 23:32:32 -0000
From: "BRIAN VIVIAN" <brian.vivian@virgin.net>
Subject: perl for win32
Message-Id: <7deh5s$22v$1@nclient3-gui.server.virgin.net>
hi I have recently installed Gurusary Sarathy Perl version 5.004_02.
when I try to run scripts which require cgi-lib.pl I get this error
message:-
Can't locate cgi-lib.pl in @INC (@INC contains: C:\USR\LOCAL\lib\site
C:\USR\LOCAL\lib c:\perl\lib c:\perl\lib\site c:\perl\lib\site .) at
c:\perldev\shopscript\bike.pl line 3.
Process completed with exit code 2
Has anyone got any ideas of what the solution is? I guess it is something to
do with the location of cgi-lib.pl (assuming that it is actually located
somewhere).
Thank you for your time
------------------------------
Date: Thu, 25 Mar 1999 18:55:03 -0500
From: "William Flanagan" <wflanagan@msn.com>
Subject: Problem writing a file... file permissions ok on computer
Message-Id: <7deicp$211$1@remarQ.com>
All-
I'm trying to write a perl script that takes a structured text file, and
converts it to a comma delimited file. The problem that I am having is that
I can't get it to write the file. I've tried everything. I'm writing on a
Windows machine, so file permissions aren't the problem. The structured
file is of the form
FIELDNAME: FIELDVALUE
FIELDNAME2: FIELDVALUE2
FIELDNAME3: FIELDVALUE3
R2FIELDNAME: FIELDVALUE
R2FIELDNAME2: FIELDVALUE2
etc.
People of the corporate world may recognize this as a structured text output
from an export in Lotus Notes. Anyway, there are three null lines between
the "records" in the fields. So, I've taken to writing it in two phases.
1) I read the file, getting the fieldnames, so that if new fields are added
the next time that I run this, I'll have them automatically. Then, I go
through again and add records to the structure that I created before, and
when I encounter three null lines, I write a record.
Easy, right? Well, it's not going so well. I've tried every permutation,
and I can't get this thing to write to the disk. I can write to STDOUT, and
redirect it to a file, but I can't write directly to the file. I open the
file as write. Help!
Here's the code, pasted below.
Comments to wflanagan@msn.com. Thanks,
William
#!c:\progra~1\perl\bin\perl
# This is my first attempt at writing a program that will convert my Notes
database to a comma delimited
# file. This takes any structured text file and converts it to comma
delimited.
#-------
# Step Number 1: Get command line values:
#-------
if ($#ARGV !=1) {
die "Structured Text to Comma Delimiter, 1999 William Flanagan\n Usage:
$0 inputfile outputfile\n";
}
($infile,$outfile) = @ARGV;
if (! -r $infile) {
die "Can't read input $infile\n";
}
if (! -f $infile) {
die "Input $infile is not a plain text, please use a structured plain
text file\n";
}
#-------
# Step Number 2: Validate files
#-------
open(INPUT,"<$infile") ||
die "Can't open $infile successfully, ensure $infile is plain text $!";
if ( -e $outfile) {
print STDERR "Output file $outfile exists!\n";
until ($ans eq 'r' || $ans eq 'a' || $ans eq 'e' ) {
print STDERR "replace, append, or exit? ";
$ans = getc(STDIN);
}
if ($ans eq 'e') {exit}
}
if ($ans eq 'a') {$mode='>>'}
else {$mode='>'}
open(OUTPUT,"$mode$outfile") ||
die "Can't create $outfile file, ensure that it does not exist $!";
$ccount = 0;
#------
# Step Number 3: Read input, preprocess, and add to first line arguments for
output
#------
while ($line = <INPUT>) {
($fieldname, $fieldvalue) = split(":", $line);
if ($fieldname eq '') {
next;}
chomp($fieldvalue);
chomp($fieldname);
$foundfield='n';
for ( $a=0; $a <= $ccount; $a++) {
if ($columnlist[$a][1] eq $fieldname) {
$foundfield='Y';
last; }
}
if ($foundfield eq 'n') {
$columnlist[$ccount] = ["$ccount", "$fieldname"];
print STDOUT "Adding $fieldname to record list.\n";
$ccount++;
}
}
print STDOUT "\n\nTotal ccount is $ccount.\n";
#------
# Step Number 4: Gather outputfile information
#------
close INPUT;
open(INPUT,"<$infile") ||
die "Can't open $infile successfully, ensure $infile was not deleted or
moved $!";
$j=0;
while ($line = <INPUT>) {
($fieldname, $fieldvalue) = split(":", $line);
chomp($fieldvalue);
chomp($fieldname);
$foundfield='n';
if ($fieldname eq '') {
$eorcount++;
print STDOUT "\nEnd of Record count number $eorcount.\n\n";
if ($eorcount eq 3) {
for ($k=0;$k<=$#recorddata;$k++) {
print STDOUT "Inside 3 loop.\n";
print OUTFILE "$recorddata[$k]", ", ";
print STDOUT "$recorddata[$k]", ", ";
}
print OUTFILE "\n";
print STDOUT "\n";
@recorddata = ();
$eorcount = 0;
next;
}
}
for ( $a=0; $a <= $ccount-1; $a++) {
print STDOUT "Comparing $fieldname to $columnlist[$a][1].\n";
if ($columnlist[$a][1] eq $fieldname) {
@recorddata[$a] = $fieldvalue;
print STDOUT "Found $fieldname in record, adding @recorddata[$a]
to record.\n";
$foundfield='Y';
$eorcount = 0;
last;
}
}
if ($foundfield eq 'n') {
$eorcount++;
}
print STDOUT "Moving onto record $j\n\n";
$j++;
}
#-------
# 4: Done!
#-------
close INPUT,OUTPUT;
exit;
------------------------------
Date: Thu, 25 Mar 1999 23:04:25 +0100
From: Peter John Acklam <jacklam@math.uio.no>
Subject: Q: redefined subroutines
Message-Id: <36FAB2E8.BBEC0347@math.uio.no>
I've stripped away everything that does not seem to cause the problem,
and I am left with a Perl file only containing
#!/local/bin/perl5 -w
use strict;
use File::Spec;
use Dirhandle;
but when I run, or just syntax-check it, I get
Subroutine new redefined at E:\PERL\lib/Dirhandle.pm line 32.
Subroutine DESTROY redefined at E:\PERL\lib/Dirhandle.pm line 43.
Subroutine open redefined at E:\PERL\lib/Dirhandle.pm line 48.
Subroutine close redefined at E:\PERL\lib/Dirhandle.pm line 54.
Subroutine read redefined at E:\PERL\lib/Dirhandle.pm line 60.
Subroutine rewind redefined at E:\PERL\lib/Dirhandle.pm line 66.
How do I avoid these error messages? Not using -w is hardly a good
solution, I think.
I am using Perl version 5.005_02 built for MSWin32-x86-object, with
File::Spec version 0.6. Dirhandle contains no version information.
Peter
--
Peter J. Acklam - jacklam@math.uio.no - http://www.math.uio.no/~jacklam
------------------------------
Date: Thu, 25 Mar 1999 14:59:40 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: Quicksort won't work
Message-Id: <36FABFDC.95120E67@mail.cor.epa.gov>
Darren Smurthwaite wrote:
>
> I have just started using PERL and am trying to convert some old C++
> routines. Can anyone tell me what is wrong with the following code?
> It is trying to read a file then quicksort the array but it doesn't
> sort anything. Is it something to do with the way the variables work?
>
> Cheers
> da5
Darren, please don't take this the wrong way, but you're trying
too hard to write C code in Perl. It takes a little bit to pick up
the feel of the language, although reading Randal Schwartz's
"Learning Perl" is a good way to pick up Perl if you already know a
programming language or three.
> #-----
I'll assume this is just a divider, not the first line of the
program. :-)
> #!/usr/local/bin/perl
#!/usr/local/bin/perl -w
use strict;
These will help you catch a lot of errors. Trust me.
Now let me give you some advice. Perl does a lot of things for
you that C doesn't. Don't write your own quicksort routine,
unless it's just for practice. Perl has a very nice, very
flexible sort() function which nicely conceals the, umm,
features of C's qsort from the user. And there's a nice entry
in the FAQ about sorting, which will help you.
> sub swap #swaps elements in array
> {
> local($i,$j)=@_;
> $temp=@list[i];
> @list[i]=@list[j];
> @list[j]=$temp;
> }
A very important feature of Perl is the $-@-% distinction.
If you are working with one variable [a scalar or one value
of an array or hash], use a '$'. If you are using an array
or a hash or a slice of an array [i.e. more than one index
in the square brackets], use an '@'. All your above lines
which have @list[.] should have $list[.] . The -w flag would
have caught this for you. BTW, you don't have to do this in
Perl like you have to in C. In Perl you can switch them in
parallel. Like this:
@list[$i,$j] = @list[$j,$i];
See? A slice using more than one index gets the '@' at the
front. And so you wouldn't even need this subroutine...
> sub quicksort
> {
> local($l,$r)=@_;
'my' is a much better choice here than 'local'.
'perldoc -f my' and 'perldoc -f local' will tell you some
details, and 'perldoc perlsub' will show you more info.
> if($r-$l>0)
> {
> if(@list[$r]<@list[$r-1])
> {
> swap($r-1,$r); #swap the numbers
> }
> }
> if($r>$l)
> {
> print "quicksort(l,r)=".$l.",".$r."\n";
> $pv=@list[$r];
> $i2=$l-1;
> $j2=$r;
> while($i2<$j2)
> {
> while(@list[++$i2]<$pv){};
> while(@list[--$j2]>$pv){};
> if($i2<$j2)
> {
> swap($i2,$j2);
> }
> }
> swap($i2,$r);
> quicksort($l,$i2-1);
> quicksort($i2+1,$r);
> }
> }
>
> #-END OF SUBS---------------------------
>
> $infile='data.txt'; # Name the file
> open(INFILE,"<$infile"); # Open the file
You really ought to check whether your open worked.
open INFILE "$infile" or die "Dang open failed again: $!\n";
> @list=<INFILE>; # Read it into an array
> close(INFILE); # Close the file
and check the return on this too...
> $aend=$#list;
> quicksort(0,$aend);
> print $aend."\n\n";
@sorted = sort @list; #th-th-th-that's all folks!
> foreach $line (@list)
> {
> print"$line";
> }
> #-----END-----
HTH,
David
--
David L. Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Thu, 25 Mar 1999 14:51:19 -0800
From: Matt Riggsby <mriggsby@sybex.com>
Subject: Reading results of external commands
Message-Id: <36FABDE7.866A9BFF@sybex.com>
I'd like to run a shell command (say, through the system command) and
read the results of that command into a variable. For example, I'd like
to be able to have perl run a line like:
command('ipconfig');
...and get back my IP address, subnet mask, and default gateway, or at
least get back data in a variable or array that I can parse to extract
the desired data. Ultimately, I want to use this with some command-line
utilities to do some reverse DNS fun and games that will be a little
more far-reaching than what I can get out of gethostbyaddr.
Suggestions? I'm using perl 5 on an NT box, if that matters.
------------------------------
Date: Fri, 26 Mar 1999 08:41:19 +1000
From: "Diggy Tim" <tim@diggy.com>
Subject: Running a perl script as a daemon....
Message-Id: <7dedl5$ti0$1@reader1.reader.news.ozemail.net>
Something has stumped me for a long time, It always seemed to be a simple
thing to do for me.. But so far I have been unable to do it.
How do I go about running a perl script from the command line and have it
sit in the background and not die when I log out.
OS is Solaris 2.5 - 2.7.
Cheers,
Tim
--
--
Tim Gunn
tim@diggy.com
_ _ _ _ _ _ _ _ _ _ _
Diggy Internet Services
Lv 2, 132 Albert Street
Brisbane Qld 4000
Ph +61 7 3236 5855
Fax +61 7 3236 5733
http://www.diggy.com.au
------------------------------
Date: Thu, 25 Mar 1999 22:42:06 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Standard Deviation
Message-Id: <ebohlmanF969q6.Gx3@netcom.com>
Andrew Johnson <andrew-johnson@home.com> wrote:
: sub simple_stats {
: my @data = @_;
: my $size = @data;
: return unless $size;
: my ($sum_x, $sum_x2) = (0, 0);
: for (@data) {
: $sum_x += $_;
: $sum_x2 += $_ ** 2;
: }
: my $mean = $sum_x / $size;
: my $var = ($sum_x2 - ($sum_x ** 2 / $size)) / ($size - 1);
: my $stdev = sqrt($var);
: return ($mean, $var, $stdev);
: }
This common textbook formula for computing variances is not particularly
stable in the face of roundoff error. There are better "one-pass"
algorithms, though I can't remember the details off the top of my head.
A DejaNews search of sci.stat.math and sci.stat.consult should turn up
the details.
------------------------------
Date: Thu, 25 Mar 1999 15:34:21 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: String Limit in IE?
Message-Id: <36FAC7FD.DCAC48FA@mail.cor.epa.gov>
Justin M. Silver wrote:
>
> I have a perl script that passes user input from web page to webpage and
> eventually writes a file based on this information. The problem is with a
> <textarea> input. All of the information goes through fine in Netscape, but
> in IE, the variable is cut in half, with the data at the end replaced with
> a "%". This only happens with large amounts of data (IE seems to cut it off
> at about 1800 characters). I dont think this is the scripts fault, as it is
> rather simple, and it work in NS. Does anyone else have any ideas, or know
> if IE has a limit on the length of strings it will pass?
I don't mean to sound abrupt, but this is definitely not a question for this
newsgroup. And you already worked that out. If it is a bug, it's a bug
in Internet Exploder. You will probably get the best results asking in one
of the web-authoring ng's or in the microsoft.public.* newsgroups or checking
the Microsoft Knowledge Base.
Try comp.infosystems.www.authoring.cgi or one of the 65 or so
microsoft.public.inetexplorer groups, and someone there should be able to
provide an authoritative answer.
HTH,
David
--
David L. Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Thu, 25 Mar 1999 21:46:06 GMT
From: jatgal@my-dejanews.com
To: jatgirl@yahoo.com
Subject: String Manipulation -cgi/perl
Message-Id: <7deaqr$7cl$1@nnrp1.dejanews.com>
I have a string in following format $user,$user@domain.com
$user2,$user2@domain.com ...so on .. What I need to do is as following
UserName Email $user $user@domain.com $user2 $user2@domain.com so on
... String is obtained from a cgi -form .. I figured the part to split the
$user and $user@domain.com however I'm having trouble to account the spaces
between from a user to user as a new element in array. Any one has any idea
how this can be achieved. Any CPAN modules that will do the job? Please help
me out with this. I would greatly appreciate your effort :)
Thanks
Jatgal
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Thu, 25 Mar 1999 17:59:02 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: jatgirl@yahoo.com
Subject: Re: String Manipulation -cgi/perl
Message-Id: <36FABFB6.1ACDA860@giss.nasa.gov>
[courtesy copy of post sent to cited author]
jatgal@my-dejanews.com wrote:
>
> I have a string in following format $user,$user@domain.com
> $user2,$user2@domain.com ...so on .. What I need to do is as following
just OTTOMH,
my $string =
'fred,fred@foo.bar.com bif,bif@whiz.bang ary,ary@ary.lang.org';
my @foo = map { [ split /,/ ] } split /\s+/, $string;
use Data::Dumper;
print Dumper \@foo;
Jay Glascoe
--
which is worse: ignorance or apathy?
who knows. who cares.
------------------------------
Date: Thu, 25 Mar 1999 22:41:52 GMT
From: jatgirl@yahoo.com
Subject: Re: String manipulation
Message-Id: <7dee3e$acg$1@nnrp1.dejanews.com>
Thanks Bob! it worked out perfectly well :)
In article <7dcb2a$37v$1@birch.prod.itd.earthlink.net>,
sowmaster@juicepigs.com (Bob Trieger) wrote:
> In article <7dc1pe$774$1@nnrp1.dejanews.com>, jatgal@my-dejanews.com wrote:
> >Hi guys
> > I'm trying to manipulate following string
> >user1, user1@domain.com use2,user2@domain.com user3,user3@domain.com ..so
on..
> >
> >what I need to do is break the string as following
> > Name Email
> > user1 user1@domain.com
> > user2 user2@domain.com
> > so on ...
> >
> >I got the part where I can split the Name and Email, however I'm having
> >trouble in manipulating space as a sign of next element in an array.. any
> >idea how that can be done? or am I doing it wrong?
>
> Split your input line into an array at the spaces.
> Then split each element of the array into key and value of a hash at the
> commas.
>
> This is how I'd do it, but I'm sure you will get varying examples:
>
> #!/usr/bin/perl -w
> use strict;
> my $var = q(user1, user1@domain.com use2,user2@domain.com
> user3,user3@domain.com);
> my @array = split /\s+/, $var;
> my %hash = map { split /,/ } @array;
> print map { "$_\t$hash{$_}\n" } keys %hash;
>
> Good luck
>
> Bob Trieger
> sowmaster@juicepigs.com
>
>
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 25 Mar 1999 22:08:46 GMT
From: Dan Sugalski <sugalskd@netserve.ous.edu>
Subject: Re: threaded perl
Message-Id: <7dec5e$gs8$1@news.NERO.NET>
Michael Douglass <mikedoug@texas.net> wrote:
: Any new word on threads under perl? I've tried perls under 5.005_02
: on my Solaris 2.6 box and I can core dump it with just a test script
: that starts up X threads and has them each spit out numbers while they
: sleep random amounts of time.
5.005_03 should be a lot more stable for threads. Due out Real Soon Now,
or you can check out the trial releases on CPAN in authors/id/GBARR
Dan
------------------------------
Date: Thu, 25 Mar 1999 15:06:13 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: Too Late for -T error
Message-Id: <36FAC165.D5F80CA6@mail.cor.epa.gov>
Cal Bond wrote:
> Hi-
> I downloaded a cgi script designed to grade multiple choice forms. When
> I got everything sorted out and put on the page, I got a Internal Server
> Error (500)- 'premature end of script headers'. I downloaded perl and
> ran the script from the command line with the 'perl -d' function and got
> an error 'Too late for -T option at (name).cgi line 1'. I latered line
> one, the path to perl, for my server. It's
> #!/usr/bin/perl -T
> I've tried it without the -T extension but then get screens full of
> error output. I even tried just running the script with the original
> perl path (#!/usr/local/bin/perl) from the command line just to see hwat
> would happen and still get the same '-T option' error.
> You can probably tell I'm not much of a programmer and apologize if this
> is a really dumb question or I've left something major out, but I've
> been through all the faqs and I'm still stuck. Can anyone help me out?
> Thanks
> Callan Bond
If you read through the perldiag info [for example, type 'perldoc perldiag']
you'll find this error, with a complete description of the problem.
Too late for "-T" option
(X) The #! line (or local equivalent) in a Perl script
contains the -T option, but Perl was not invoked with -T in
its command line. This is an error because, by the time Perl
discovers a -T in a script, it's too late to properly taint
everything from the environment. So Perl gives up.
If the Perl script is being executed as a command using the
#! mechanism (or its local equivalent), this error can
usually be fixed by editing the #! line so that the -T
option is a part of Perl's first argument: e.g. change `perl
-n -T' to `perl -T -n'.
If the Perl script is being executed as `perl scriptname',
then the -T option must appear on the command line: `perl -T
scriptname'.
What more is there for me to say?
David
--
David L. Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Thu, 25 Mar 1999 12:28:23 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Urgent: Document contains no data
Message-Id: <nnrdd7.3n.ln@magna.metronet.com>
Shade L. Jenifer (sjenifer@geo.census.gov) wrote:
: I have a problem that needs immediate attention and
: our resources here (ie books) are scarce.
But books are about a fourth level resource, for several reasons:
1) you may not have it with you.
2) you cannot do word searches in it, you are at the
mercy of whoever did the indexing.
3) they are likely to be out of date.
4) they cost money.
The resources that should be tried before books have none of
those problems (assuming you have a file system and a 'net
connection):
Perl FAQs
other standard Perl docs
word search on www.dejanews.com
Of course that only applies to Perl books, as Perl
is what is discussed here in the Perl newsgroup.
For non-book CGI resources, you might try the CGI newsgroup:
comp.infosystems.www.authoring.cgi
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 25 Mar 1999 12:32:34 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: WHY: open (HPIPE, "| notexistfile") or die "..."; DOES NOT DIE ???
Message-Id: <ivrdd7.3n.ln@magna.metronet.com>
Patrice M.I. Parmentier (ppa@itmasters.com) wrote:
: I want to open a pipe for writing to the stdin of a program:
: open (HPIPE, "| xxxx") or die "...";
: !!! The open never fails, even when xxxx does not exist !!!
: WHY???
Yours is a Frequently Asked Question.
You are not supposed to ask those yet again, you are instead
supposed to look them up and read them, saving your time and
the time of the thousands of folks who will see your repeat
of a question that has been answered many times, and honoring
the people who spent time away from their other pursuits in
order to package up a definitive answer for you.
If you don't understand what is said there, _then_ post
asking for clarification.
Perl FAQ, part 8:
"Why doesn't open() return an error when a pipe open fails?"
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". 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". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 5229
**************************************