[18701] in Perl-Users-Digest
Perl-Users Digest, Issue: 869 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 10 14:08:35 2001
Date: Thu, 10 May 2001 11:05:22 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <989517921-v10-i869@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 10 May 2001 Volume: 10 Number: 869
Today's topics:
Re: $a . $a++ or Perl for vulcans? <dan@tuatha.sidhe.org>
Re: $a . $a++ or Perl for vulcans? (Abigail)
Re: 1 billion seconds bug <mischief@velma.motion.net>
Re: 1 billion seconds bug <flavell@mail.cern.ch>
Announcement -- TESTING COMPUTER SOFTWARE (TCS2001) Con (Peter Zuckerman)
Re: Announcement -- TESTING COMPUTER SOFTWARE (TCS2001) (Anno Siegel)
Re: Base 6 sieve. (Abigail)
Can't get sleep to work. <jim@wiedman.com>
Re: Can't get sleep to work. (Brandon Metcalf)
Re: Can't get sleep to work. (Clinton A. Pierce)
Re: Can't get sleep to work. nobull@mail.com
Re: CGI=HASH(0x176ef80) Help Please! (Anno Siegel)
Re: CGI=HASH(0x176ef80) Help Please! <ren@tivoli.com>
Converting a tab-delimited file? <andrew@innismaggiore.com>
Re: Converting a tab-delimited file? (Rafael Garcia-Suarez)
Re: Converting a tab-delimited file? <bart.lateur@skynet.be>
Re: Converting a tab-delimited file? <amnuts@talker.com>
Re: Execute script at certain times? <goldbb2@earthlink.net>
forking and variable references <randy.bey@rivernorthsys.com>
format Question <lmoran@wtsg.com>
Re: format Question <pne-news-20010510@newton.digitalspace.net>
Re: format Question <lmoran@wtsg.com>
Re: Help with double hash of arrays <goldbb2@earthlink.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 10 May 2001 15:17:10 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: $a . $a++ or Perl for vulcans?
Message-Id: <WhyK6.53801$Ce4.4588507@news1.rdc1.ct.home.com>
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
> Perl's behaviour in this area, and the issue of what is 'defined' and
> what is 'undefined' is not decently documented. When someone like Dan
> Sugalski comes in, and tells us all that it is undefined, that most
> likely is true. But... Where is that documented?
Generally speaking, it's not documented.
Programming Perl is taken as canon, and the implementation is supposed
to follow that. In places it doesn't, it's generally considered a bug.
For things that Programming Perl doesn't cover, the documentation is
supposed to, assuming that things are both documented and that the
documentation isn't contradictory. Beyond that, it's best to consider
things as rather dodgy.
Yes, this particular state of affairs isn't that great. (Well, OK, it
sucks) It's one of the things I'd like to rectify for perl 6.
Dan
------------------------------
Date: Thu, 10 May 2001 16:51:33 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: $a . $a++ or Perl for vulcans?
Message-Id: <slrn9flhol.7ok.abigail@tsathoggua.rlyeh.net>
Joerg Behrens (jbehren@gwdg.de) wrote on MMDCCCVIII September MCMXCIII in
<URL:news:qg66fazcjc.fsf@umpp41.gwdg.de>:
-:
-: Having the possibility to encounter an equivalence of $a+0 != $a
-: in the context of integers (occupied by common human interpretation)
-: doesn't really make Perl an intuitive language, IMHO. Use of this
-: feature by mistake might be hard to discover without debugger.
Getting $a + 0 != $a is *trivial* in Perl.
In fact, Perl supports at least two methods to do so:
tie()ing and overloading.
Abigail
--
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
"\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
"\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'
------------------------------
Date: Thu, 10 May 2001 15:35:48 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: 1 billion seconds bug
Message-Id: <tfldakitmc0n58@corp.supernews.com>
Philip Newton <pne-news-20010510@newton.digitalspace.net> wrote:
> On Thu, 10 May 2001 07:06:21 GMT, tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
> wrote:
>> I just want to point out that as the resident .nz 'er that (assuming
>> there's noone from Fiji or the Cook Islands here) my Perl scripts will
>> break before all of y'all since I'm closest (numerically and lexically)
>> to the IDL.
> AFAIK time() will return the same value at the same time everywhere in
> the world, if your clock is correctly set. It's localtime() which
[snip]
You forget how arroga^Wshort-sigh^Wum, provincial some people are
in the way they think. I know of at least two Linux versions which
ask upon installation if you wish to set your clock to 'GMT' and
use a proper timezone.
Besides, even though time() might return the same thing, I doubt
many people choose to think of their daily automated tasks in
terms of UTC, so localtime() could be just as important.
BTW, just a note about interesting places that use Perl which
you wouldn't think about in this sort of programming bug
elimination... Over on the Perl Jobs mailing list the American
Registry for Internet Numbers (ARIN) is advertising for someone
with mainly Perl and some C experience, as use almost all Perl
internally. Hopefully the 32 additional class Cs my tram just
got assigned won't get lost in September. ;-)
Chris
--
People understand instinctively that the best way for computer programs to
communicate with each other is for each of the them to be strict in what they
emit, and liberal in what they accept. The odd thing is that people themselves
are not willing to be strict in how they speak, and liberal in how they listen.
-- Larry Wall, 2nd State of the Onion Address, August 1998
------------------------------
Date: Thu, 10 May 2001 17:51:10 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: 1 billion seconds bug
Message-Id: <Pine.LNX.4.30.0105101744200.27671-100000@lxplus003.cern.ch>
On Thu, 10 May 2001, Chris Stith wrote:
> You forget how arroga^Wshort-sigh^Wum, provincial some people are
> in the way they think. I know of at least two Linux versions which
> ask upon installation if you wish to set your clock to 'GMT' and
> use a proper timezone.
I'm not sure what you're using that to illustrate (aside from the fact
that a more politically correct designation would be UTC, and nowadays
Greenwich isn't really involved ;-)
AIUI, the point of there being a question is related to dual-bootable
systems in which the other OS thinks it wants the hardware clock set
to local time. Linux offers the option to co-exist with that, or to
apply the usual unix procedures.
cheers
------------------------------
Date: Thu, 10 May 2001 09:17:37 -0500
From: pazpax@clark.net (Peter Zuckerman)
Subject: Announcement -- TESTING COMPUTER SOFTWARE (TCS2001) Conference -- Keynote Speakers
Message-Id: <pazpax-1005010917370001@sdn-ar-014dcwashp328.dialsprint.net>
18th International Conference and Exposition on
TESTING COMPUTER SOFTWARE
Theme: Meeting the New Challenges of Testing
June 18-22, 2001
Washington, D.C. * Hyatt Regency (Bethesda) * USA
(Conference: June 20-22; Workshops/Tutorials: June 18-19)
In cooperation with:
Association for Computing Machinery (ACM) SIGSoft
American Society for Quality (ASQ) Software Division
IEEE Reliability Society
Software Technology Support Center (STSC)
* * * * * *
The general sessions of the Conference on Testing Computer Software will
address major issues of concern to the developers and users of software.
The theme of the Conference "Meeting the New Challenges of Testing"
focuses on providing practical and essential solutions to the software
development profession, and the users of computer software at all levels.
Tom Gilb's topic will be "Real Time Priority and Risk Management for World
Class Software Quality." He will discuss that world-class software quality
cannot be achieved using conventional thinking. Scarce human and time
resources must be managed in a dynamic way; with regard to multiple
stakeholder values and actual resource consumption. And multitudes of
potential threats to success must be identified and managed.
Warren S. Reid's will discuss "Is That Your Final Answer? Surviving Cross
Examination in the Courtroom." Lawsuits involving large-scale system
failures and dot.com failures are one of the fastest growing areas of
litigation in the legal profession today. Unexpectedly you may find
yourself in a courtroom with an unhappy vendor or customer. To stave off
being second-guessed, you will need to know how to perform, communicate,
and document your work in a way it will survive a courtroom test, and to
present your position with professional aplomb on the witness stand.
John Musa will cover "Efficient Testing with a Measure to Select Testing
Strategies." The problem of how to select the most efficient testing
strategies will be addressed. The market forces that are making it more
and more imperative to improve testing efficiency will be explored. The
requirements for selecting a measure to evaluate testing strategies and
tools will be summarized. A proposal for a measure is presented, along
with sufficient details of its application to show that most of the
potential problems have been addressed.
Edward Jones will present "Educators Join the Fray -- Tester Training for
Undergraduates" He will describe the efforts to expose undergraduate
students to the practice and principles of software testing. The goals of
this effort are three-fold: (1) give students hands-on experience in the
fundamentals of testing; (2) to transfer a quality-centric value system
(attitude towards testing/quality); (3) to transfer testing skills and
attitude into the undergraduate curriculum.
Simon Mills will explore "A World-Wide Web of Intrigue -- Deceptive
Testing." His talk covers the new issues related to e-commerce
applications, and the many old issues surfacing under a new guise. He will
present case study experiences to reflect "new challenges" as being
reflections of yesterdays problems.
.
The Conference will conclude with the wrap-up session: "Conference
Reflections - and a few surprises thrown in!" Marnie Hutcheson will
expertly summarize: What we did; Where we've been; Where we're going.
* Thirty-two Concurrent Sessions divided into four parallel tracks present
a wide variety of topics and issues in major areas of: Management,
Automation, Technology, Requirements, Practices, Web and Case Studies.
* Pre-Conference (June 18-19) Workshops (2 days) and Tutorials (1 day)
will present comprehensive technical sessions for software testing
practitioners. These sessions will provide detailed training on major
software testing technologies, tools and methodologies.
* Networking with participants interested in specialized topics will be
facilitated by Birds-of-a-Feather Sessions and Lunch Discussion Groups.
* The Conference Volume (including the presentations and proceedings of
the sessions) will be a valuable reference for testing projects.
* The Testing Tools vendors exhibit will present the latest in products
and services to support software and applications testing.
For a continuously updated program check out on the Web:
<http://www.uspdi.org/conference/program.html>
* * * * *
For complete program details and registration please contact the U.S.
Professional Development Institute (USPDI):
Regular Mail: USPDI, 612 Ethan Allen Avenue, Suite 100; Takoma Park,
MD 20912-5400, USA.
Phone: [+1] 301-270-1033
Fax: [+1] 301-270-1040
E-mail: admin@uspdi.org (Subject: TCS2001)
On-line:
Brochure request: <http://www.uspdi.org/conference/brochure.html>
Registration: <http://www.uspdi.org/conference/register.html>
Web download: <http://www.uspdi.org/conference/printbrochure.html>
* * * * *
***
------------------------------
Date: 10 May 2001 15:04:56 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Announcement -- TESTING COMPUTER SOFTWARE (TCS2001) Conference -- Keynote Speakers
Message-Id: <9deamo$ap1$1@mamenchi.zrz.TU-Berlin.DE>
[Newsgroups reduced to clpm]
According to Peter Zuckerman <pazpax@clark.net>:
>
> 18th International Conference and Exposition on
>
> TESTING COMPUTER SOFTWARE
> Theme: Meeting the New Challenges of Testing
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[major snip]
Where do people learn to think of a conference theme like that? The
maxim seems to be, pack buzzwords in the phrase until all traces
of meaning are crowded out. Must be the same school that teaches
newbies to choose a topic.
Anno
------------------------------
Date: Thu, 10 May 2001 16:46:03 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Base 6 sieve.
Message-Id: <slrn9flheb.7ok.abigail@tsathoggua.rlyeh.net>
Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMDCCCVII
September MCMXCIII in <URL:news:9d9b9t$jbu$1@mamenchi.zrz.TU-Berlin.DE>:
$$ According to Abigail <abigail@foad.org>:
$$ >
$$ > As Anno pointed out yesterday, a sieve based on a base 6 numbering
$$ > system uses less memory. Here's an implementation, which is hopefully
$$ > reasonable efficient.
$$
$$ [code reluctantly snipped]
$$
$$ That's very pretty.
Thanks you.
$$ While my original impulse was to go to higher bases (than the original
$$ 10) and use as many primes as possible, somewhere on a bus today it
$$ dawned on me too that a small base might be the ticket. Well, the
$$ remaining small base, 6.
$$
$$ Your scrub routine is highly optimized. I had expected having to
$$ do something complicated before the loop to get in sync. The idea
$$ of establishing a preliminary limit to get some complications out of
$$ the middle rounds is new to me and noteworthy. Also noteworthy is
$$ the tasteful use of a bare block to align the final lines with the
$$ corresponding ones inside the loop.
Well, there are only two things that need to be optimized: the memory
usuage, and the scrub routine, as most work will be performed in this
routine. The "extra" pieces before and after the core loop seem very
natural - if you don't do that, you will have to put conditions in your
loop, and it's easy to see those conditions only deal with boundary
conditions. From there it's just one step to take the boundary conditions
out of your loop ;-)
$$ You are one of the few programmers who don't only have a distinctive
$$ personal style, but a whole range of such, one for each occasion.
$$ This is clearly one not of the more jocular programs. I is also, if
$$ I'm not very wrong, written with the idea in mind that it could be
$$ the prototype for a seriously fast prime generator written in C or
$$ assembler.
There's little about a sieve you can do to make it language specific.
All significant optimizations (one byte of usage per 24 possible numbers,
and the core loop) are language independent - so it translates easily
to C or assembler. As long as your language gives you access to bits.
There is, however, a major inefficiency in the program that's screaming
to be optimized away. Can you guess what it is?
Abigail
--
perl -wle'print"Κυστ αξοτθες Πεςμ Θαγλες"^"\x80"x24'
------------------------------
Date: Thu, 10 May 2001 15:36:25 GMT
From: Jim Wiedman <jim@wiedman.com>
Subject: Can't get sleep to work.
Message-Id: <3AFAB500.202B54C2@wiedman.com>
I'm sure this is going to be a really stupid question, but I can't
figure it out.
I am trying to test a script that reviews a logfile so I'm trying to
simulate the creation
of the log file. I'm trying to write a simple script that will open an
old log file, and place
one line at a time in a new log file with a 1 second pause between
lines.
The script works just fine until I put the sleep function in. I get no
errors, but nothing
is written to the new file. Can someone please tell me what I'm
missing?
Thanks,
Jim
#!/usr/bin/perl
use strict;
my $i;
open FULL, "< /home/gse/log/full.log" or die "Unable to open full.log:
$!\n";
open(NEW, "> seqevh.log") or die("Unable to open seqevh.log: $!");
while(<FULL>) {
print NEW $_;
sleep 5;
}
close(NEW);
close(FULL);
------------------------------
Date: 10 May 2001 16:31:21 GMT
From: bmetcalf@baynetworks.com (Brandon Metcalf)
Subject: Re: Can't get sleep to work.
Message-Id: <9defop$5bh$1@bcarh8ab.ca.nortel.com>
jim@wiedman.com writes:
> The script works just fine until I put the sleep function in. I get no
> errors, but nothing
> is written to the new file. Can someone please tell me what I'm
> missing?
...
> #!/usr/bin/perl
>
> use strict;
> my $i;
>
> open FULL, "< /home/gse/log/full.log" or die "Unable to open full.log:
> $!\n";
>
> open(NEW, "> seqevh.log") or die("Unable to open seqevh.log: $!");
>
> while(<FULL>) {
> print NEW $_;
> sleep 5;
> }
>
> close(NEW);
> close(FULL);
You need to force a flush after every write. Take a look at the perlvar
man page.
$| = 1;
Brandon
------------------------------
Date: Thu, 10 May 2001 16:49:24 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: Can't get sleep to work.
Message-Id: <oEzK6.13211$V5.2482416@news1.rdc1.mi.home.com>
[Posted and mailed]
In article <3AFAB500.202B54C2@wiedman.com>,
Jim Wiedman <jim@wiedman.com> writes:
> The script works just fine until I put the sleep function in. I get no
> errors, but nothing
> is written to the new file. Can someone please tell me what I'm
> missing?
You're probably having your output buffered somewhhere. Try this:
> #!/usr/bin/perl
>
> use strict;
> my $i;
>
> open FULL, "< /home/gse/log/full.log" or die "Unable to open full.log:
> $!\n";
>
> open(NEW, "> seqevh.log") or die("Unable to open seqevh.log: $!");
$ofh=select(NEW); # Change default filehandles
$|=1; # Turn on auto-flushing for NEW
select($ofh); # Go back to the original default filehandle
# (not really needed in this program)
>
> while(<FULL>) {
> print NEW $_;
> sleep 5;
> }
>
> close(NEW);
> close(FULL);
Good luck!
--
Clinton A. Pierce Teach Yourself Perl in 24 Hours *and*
clintp@geeksalad.org Perl Developer's Dictionary -- May 2001
"If you rush a Miracle Man, for details, see http://geeksalad.org
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: 10 May 2001 17:48:51 +0100
From: nobull@mail.com
Subject: Re: Can't get sleep to work.
Message-Id: <u9lmo5jgjw.fsf@wcl-l.bham.ac.uk>
Jim Wiedman <jim@wiedman.com> writes using a special text wrapping
algorithm that generates alternate long and short lines. This causes
me to suffer from motion-sickness:
> Subject: Can't get sleep to work.
Have you tried counting sheep? (Initially I read that as "Can't get
to sleep at work").
[ re-wrapping performed ]
> I'm trying to write a simple script that will open an old log file,
> and place one line at a time in a new log file with a 1 second pause
> between lines.
>
> The script works just fine until I put the sleep function in. I get
> no errors, but nothing is written to the new file. Can someone
> please tell me what I'm missing?
What you are missing is output buffer flushing.
See FAQ: "How do I flush/unbuffer an output filehandle? Why must I
do this?"
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 10 May 2001 15:24:52 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: CGI=HASH(0x176ef80) Help Please!
Message-Id: <9debs4$ap1$2@mamenchi.zrz.TU-Berlin.DE>
According to Rudolf Polzer <eins@durchnull.de>:
> Malte Ubl <ubl@schaffhausen.de> wrote:
> >
> >
> > Octavo schrieb:
> > >
> > > Hallo!
> > > I have set up a flat file database cgi script (which is posted below).
> > > When I run the script from my browser the data that gets input and
> > > returned is
> > >
> > > First Name: CGI=HASH(0x176ef80)->param('fname')
> > > Quiz1 Score: CGI=HASH(0x176ef80)->param('quiz1')
> > > Quiz2 Score: CGI=HASH(0x176ef80)->param('quiz2')
> >
> > Method calls are not interpolated in a double quote string. You need to do
> > something like this instead:
> >
> > print 'bla',$query->param("fname"),"bla";
>
> Or, in here-documents, use
>
> @{[ $query-param ("fname") ]}
If the result is a scalar, ${ \ $query-param( 'fname')} works too.
This is occasionally advised, yes. Has anyone ever used the device
in serious code?
Anno
------------------------------
Date: 10 May 2001 11:48:32 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: CGI=HASH(0x176ef80) Help Please!
Message-Id: <m38zk5no9r.fsf@dhcp9-172.support.tivoli.com>
On 10 May 2001, anno4000@lublin.zrz.tu-berlin.de wrote:
> If the result is a scalar, ${ \ $query-param( 'fname')} works too.
>
> This is occasionally advised, yes. Has anyone ever used the device
> in serious code?
About five years ago I was using this exact construct in some
production code until I found out about $query->import_names
($query->import at the time, I believe). This method allows you to
import all of the parameters into a specific package.
$query->import_names(PARAM);
print "Name: $PARAM::first_name $PARAM::last_name\n";
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Thu, 10 May 2001 13:16:35 GMT
From: Andrew Collington <andrew@innismaggiore.com>
Subject: Converting a tab-delimited file?
Message-Id: <MPG.15645e0476caaf14989695@news-server.neo.rr.com>
Hi there,
Has anyone got a small script available that can read in a tab-delimited
file and convert it into a series of SQL insert statements? I need it
to be able to read fields in the tab delimited file that may span
several lines (newline characters are allowed in some of the fields.)
Any help is appreciated - even if not a script, then a push in the right
direction of reading the lines would be great :)
Thanks very much!
Andy
------------------------------
Date: 10 May 2001 13:43:26 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Converting a tab-delimited file?
Message-Id: <slrn9fl6q0.r59.rgarciasuarez@rafael.kazibao.net>
Andrew Collington wrote in comp.lang.perl.misc:
} Hi there,
}
} Has anyone got a small script available that can read in a tab-delimited
} file and convert it into a series of SQL insert statements? I need it
} to be able to read fields in the tab delimited file that may span
} several lines (newline characters are allowed in some of the fields.)
}
} Any help is appreciated - even if not a script, then a push in the right
} direction of reading the lines would be great :)
Apparently your DB doesn't come with some sort of import utility.
I don't know what exactly your input files looks like (newlines in
fields sound strange), so my advice will be short: look for the $/
variable in perlvar. Try to write a program that reads your files with
setting $/ to "\t". HTH.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Thu, 10 May 2001 14:44:04 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Converting a tab-delimited file?
Message-Id: <d4alft80s81kitf52gpat9l7h6oott7m0j@4ax.com>
Rafael Garcia-Suarez wrote:
>Andrew Collington wrote in comp.lang.perl.misc:
>} Has anyone got a small script available that can read in a tab-delimited
>} file and convert it into a series of SQL insert statements? I need it
>} to be able to read fields in the tab delimited file that may span
>} several lines (newline characters are allowed in some of the fields.)
>Apparently your DB doesn't come with some sort of import utility.
>I don't know what exactly your input files looks like (newlines in
>fields sound strange), so my advice will be short: look for the $/
>variable in perlvar. Try to write a program that reads your files with
>setting $/ to "\t". HTH.
Since he's talking about fields that DO contain newlines, some field
values must be delimited, i.e. with quotes around them. In other words,
this is a CSV, not just a tab delimited text file pur sang.
So, my advice is to look up the Text::CSV, or better yet, the
Text::CSV_XS module. That'll help in getting the records read in
properly.
As for converting to SQL... Just one advice: use placeholders. That way,
you need to "compile" the SQL statement only once (the official name is
"prepare"), and you can use it again for every record. Plus, It takes
care of all the nasty quoting probs.
--
Bart.
------------------------------
Date: Thu, 10 May 2001 15:03:11 GMT
From: Andrew Collington <amnuts@talker.com>
Subject: Re: Converting a tab-delimited file?
Message-Id: <MPG.156476c4e249f6bf989696@news-server.neo.rr.com>
In article <d4alft80s81kitf52gpat9l7h6oott7m0j@4ax.com>,
bart.lateur@skynet.be says...
> Rafael Garcia-Suarez wrote:
>
> >Andrew Collington wrote in comp.lang.perl.misc:
>
> >} Has anyone got a small script available that can read in a tab-delimited
> >} file and convert it into a series of SQL insert statements? I need it
> >} to be able to read fields in the tab delimited file that may span
> >} several lines (newline characters are allowed in some of the fields.)
>
> >Apparently your DB doesn't come with some sort of import utility.
> >I don't know what exactly your input files looks like (newlines in
> >fields sound strange), so my advice will be short: look for the $/
> >variable in perlvar. Try to write a program that reads your files with
> >setting $/ to "\t". HTH.
>
> Since he's talking about fields that DO contain newlines, some field
> values must be delimited, i.e. with quotes around them. In other words,
> this is a CSV, not just a tab delimited text file pur sang.
You're right - it does have delimiters around the longer strings, I'm
sorry. I'm just exporting from excel, you see, and I did just create a
text file in a CVS format. I'm sorry, I really wasn't clear when I
originally posted.
> So, my advice is to look up the Text::CSV, or better yet, the
> Text::CSV_XS module. That'll help in getting the records read in
> properly.
Great! I'll have a look into that right now.
> As for converting to SQL... Just one advice: use placeholders. That way,
> you need to "compile" the SQL statement only once (the official name is
> "prepare"), and you can use it again for every record. Plus, It takes
> care of all the nasty quoting probs.
Okay, I'll bear that in mind when I have to write the SQL statements.
Thanks so much for your advice - I really apprciate it!
Andy
------------------------------
Date: Thu, 10 May 2001 10:51:48 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Execute script at certain times?
Message-Id: <3AFAAB04.952643B2@earthlink.net>
carlos wrote:
> "Benjamin Goldberg" <goldbb2@earthlink.net> wrote in message
> news:3AF629AF.128DD0FB@earthlink.net...
> > Abigail wrote:
> > >
> > > Bernard El-Hagin (bernard.el-hagin@lido-tech.net) wrote on
> > > MMDCCXCIII September MCMXCIII in
> > > <URL:news:slrn9eacp6.bfu.bernard.el-hagin@gdndev25.lido-tech>:
> > > :} On Tue, 24 Apr 2001 00:52:34 -0700, Preston Price
> > > :} <pric3596@cs.uidaho.edu> wrote:
> > > :} >I was wondering if anyone knew of a way to have a program run
> > > :} >at a certain time everyday. I want something that will run at
> > > :} >midnight every night. Does anyone know of a way to do this?
> > > :} >Thanks in advance.
> > > :}
> > > :} If you can prove that this is a Perl question I'll give you
> > > :} the answer.
> > >
> > > _:_ while ((localtime) [2] || (localtime) [1] || (localtime) [0]);
> > > mid_night_run;
> > > goto _;
> >
> > A busy loop? Yuck.
> >
> > while(1) {
> > my @t = (localtime); sleep 86400 - $t[0]+$t[1]*60+$t[2]*3600;
> > &mid_night_run; }
>
> cr0n
Well, of course one could use cron, or whatever it's dos/win equivilant
is (I think it's a program called "at", but I'm not sure), but since
this is a perl group, not a general help group, one ought to post
responses about how to do it in perl :)
Of course, if your crond is implemented in perl, that's another story...
--
Shift to the left, shift to the right, mask in, mask out, BYTE, BYTE,
BYTE !!!
------------------------------
Date: Thu, 10 May 2001 12:02:39 -0500
From: Randy Bey <randy.bey@rivernorthsys.com>
Subject: forking and variable references
Message-Id: <i4ilft4pfb78c5ork1tq7ncjmetnn3s73t@4ax.com>
OK so I am truly a dork.
I want to fork a child process and have both parent and child share
the same variable (a hash in this case).
While it appears that a child inherits all variables AS THEY ARE WHEN
IT FORKS, after that all bets are off.
I have tried using $main::hash references, but I think both parent and
child think they are main.
I have tried package parent (and package child) to distinguish
themselves but each appears to have it's own idea of what $main::hash
contains.
Clearly this is because they are two separate processes running and
they do not share the same memory. I have proved this to myself by
using hard references for hash ( $hashref = \%hash) and using
%$hashref to dereference.
Am I smoking dope? Is there no way to share memory between these two
disparate processes?
------------------------------
Date: Thu, 10 May 2001 10:53:20 -0400
From: Lou Moran <lmoran@wtsg.com>
Subject: format Question
Message-Id: <pqalftcopgu5addk8tkd0rlnfgujp1pef6@4ax.com>
I have (with a lot of help from CLPM) written a script that translates
a 5 character username into 5 numbers (seen here):
#!/usr/bin/perl -w
use diagnostics;
use strict;
open (LIST, "sn.txt") || die "No file exists: $!" ;
my $names = join "", <LIST>;
my $pwd = join "", $names;
$pwd =~
y/A-Za-z/2223334445556667778889990022233344455566677788899900/;
open (NEWFILE, '> C:\code\pwd.txt');
print NEWFILE $pwd;
print NEWFILE $names;
close LIST;
format NEWFILE =
"Name", "Pwd",
------ ------
@<<<<< @<<<<<
$names, $pwd
.
but the output doesn't look like the format.
What am I missing?
(Looked in perldoc -q format, perldoc -f format & perldoc perlform but
am wiling to go back)
--
print "\x{263a}"
------------------------------
Date: Thu, 10 May 2001 18:01:55 +0200
From: Philip Newton <pne-news-20010510@newton.digitalspace.net>
Subject: Re: format Question
Message-Id: <qbelftc4vlvo6pnfcfb1t203huu17fb2t7@4ax.com>
On Thu, 10 May 2001 10:53:20 -0400, Lou Moran <lmoran@wtsg.com> wrote:
> open (LIST, "sn.txt") || die "No file exists: $!" ;
>
> my $names = join "", <LIST>;
If you want to read in the whole file at once, two suggested
approaches are:
read LIST, $names, -s LIST;
(which won't work on things such as pipes, whose length you can't
read) and
{ local $/; $names = <LIST>; }
which localizes $/ (thereby giving it a value of undef) and reads in
the file in one go.
> my $pwd = join "", $names;
This doesn't make any sense to me. Since there's only one string to
join, the delimiter is never applies, and it's empty anyway. Something
like this might be better:
(my $pwd = $names) =~
tr[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]
[2223334445556667778889990022233344455566677788899900];
, which lines up the characters nicely to boot.
> open (NEWFILE, '> C:\code\pwd.txt');
Oops, no error checking here?
> print NEWFILE $pwd;
> print NEWFILE $names;
>
> close LIST;
or here? ("Disk full", for example.)
Oh, wait, you're closing your input file here, not your output file.
Confusing; I would have done so when I was finished reading it in.
You should probably explicitly close your output file as well so that
you can check for errors.
> format NEWFILE =
> "Name", "Pwd",
> ------ ------
> @<<<<< @<<<<<
> $names, $pwd
> .
>
> but the output doesn't look like the format.
>
> What am I missing?
>
> (Looked in perldoc -q format, perldoc -f format & perldoc perlform but
> am wiling to go back)
Do so. From perldoc -f format:
format Declare a picture format for use by the `write' function.
But you didn't use 'write' at all; you used 'print'.
Also, your format will print a line like this:
"Name", "Pwd",
, complete with quotes and commas. If it's not the line after a
picture line, it's treated as a literal string to output.
Try something like this:
open (NEWFILE, '> C:\code\pwd.txt')
or die "Can't open pwd.txt: $!";
write NEWFILE;
close NEWFILE
or die "Can't close pwd.txt: $!";
format NEWFILE =
Name Pwd
------ ------
@<<<<< @<<<<<
$names, $pwd
.
Is your input file only six characters long?
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Thu, 10 May 2001 12:31:01 -0400
From: Lou Moran <lmoran@wtsg.com>
Subject: Re: format Question
Message-Id: <muflfto8od6dhf70usc7jvtbkfhpluhn18@4ax.com>
On Thu, 10 May 2001 18:01:55 +0200, Philip Newton
<pne-news-20010510@newton.digitalspace.net> wrote wonderful things
about sparkplugs:
SNIPPED and read, mostly understood (there was a bit of Cargo Culting
going on (obviously) on my part)
>
> format NEWFILE =
> Name Pwd
> ------ ------
> @<<<<< @<<<<<
> $names, $pwd
> .
>
>Is your input file only six characters long?
No, it's about 300 lines of 5 characters, like so:
aname
bname
cname
Do I need to know how man lines I'll be printing using @<<<<< ?
I had sort of envisioned it just sort of working as expected.
more reading (looks like CH 7 (PP3) and perldoc -f format are very
similar.
>
>Cheers,
>Philip
--
print "\x{263a}"
------------------------------
Date: Thu, 10 May 2001 10:43:02 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Help with double hash of arrays
Message-Id: <3AFAA8F6.8A1BFD@earthlink.net>
nobull@mail.com wrote:
[snip]
> > but just remember, TINOTW.
>
> TINOTW?
>
> How does this expand to "there are an infinite number of ways to fail
> to do it"?
There Is No One True Way
So you can succeed or fail in as many differeny ways as you can imagine.
--
Shift to the left, shift to the right, mask in, mask out, BYTE, BYTE,
BYTE !!!
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 869
**************************************