[23471] in Perl-Users-Digest
Perl-Users Digest, Issue: 5685 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 20 18:06:04 2003
Date: Mon, 20 Oct 2003 15:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 20 Oct 2003 Volume: 10 Number: 5685
Today's topics:
<$fh> question <neil.shadrach@corryn.com>
Re: <$fh> question <abigail@abigail.nl>
ANNOUNCE: Archive::Zip 1.07 <ned@bike-nomad.com>
Re: Any thought on "Perl Database" based on "Tie:File"? <usenet@dwall.fastmail.fm>
Re: C vs Perl <palaste@cc.helsinki.fi>
Re: C vs Perl <Chris@Sonnack.com>
Re: Displaying variables-list <jurgenex@hotmail.com>
Re: Displaying variables-list <grazz@pobox.com>
Re: Finding all used fileno's ? <darnold@presicient.com>
Re: Help me with is code <no@no.no>
Re: Help me with is code (Tad McClellan)
interprocess queue (was Re: win32 interprocess communic <hekmanATgeo-slopeDOTcom@no.spam>
Mason pipeline style <perl@my-header.org>
Re: Mason pipeline style <bobx@linuxmail.org>
Re: my first perl script! <HelgiBriem_1@hotmail.com>
Odd Perl bitwise-AND & MySQL problem? (dohnut)
Re: Perl & Apache: modifying index.html while it's used (brendan)
Re: Perl on AS400 <jwillmore@remove.adelphia.net>
Re: Perl security guru needed for a quick, 2 hr, job. <syscjm@gwu.edu>
Quick Perl question (MDS)
Re: Quick Perl question <abigail@abigail.nl>
Re: Quick Perl question <some@one.com>
Re: Quick Perl question <abigail@abigail.nl>
Re: really hard regex ;( (Thomas)
Re: Rookie: Constructing a large SQL INSERT statement <tore@aursand.no>
Re: Rookie: Constructing a large SQL INSERT statement nobull@mail.com
some help (Hernan)
Re: TCP close_wait problem (Grant)
using perl on the command line, like sed or awk (gorda)
Re: using perl on the command line, like sed or awk <grazz@pobox.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 20 Oct 2003 15:04:05 +0000 (UTC)
From: Neil Shadrach <neil.shadrach@corryn.com>
Subject: <$fh> question
Message-Id: <bn0th1$hgg$1@visp.bt.co.uk>
If I have a few lines like this which work fine:
my $fh=$p->{'fh'};
while (<$fh>)
{ # loop contents
}
How do I avoid resorting to temporary variable $fh?
I've had a look at the perlop pages but all is still not clear to me :(
------------------------------
Date: 20 Oct 2003 15:16:01 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: <$fh> question
Message-Id: <slrnbp7v1h.ope.abigail@alexandra.abigail.nl>
Neil Shadrach (neil.shadrach@corryn.com) wrote on MMMDCCII September
MCMXCIII in <URL:news:bn0th1$hgg$1@visp.bt.co.uk>:
!!
!! If I have a few lines like this which work fine:
!!
!! my $fh=$p->{'fh'};
!! while (<$fh>)
!! { # loop contents
!! }
!!
!! How do I avoid resorting to temporary variable $fh?
!! I've had a look at the perlop pages but all is still not clear to me :(
Parsing of the content of <> is tricky. One way of solving it is
by not using <>, which is just a shorthand for calling readline:
while (defined ($_ = readline $p -> {fh})) {
# Your loop here
}
Abigail
--
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"
------------------------------
Date: Mon, 20 Oct 2003 14:09:58 GMT
From: Ned Konz <ned@bike-nomad.com>
Subject: ANNOUNCE: Archive::Zip 1.07
Message-Id: <Hn29n6.24Fo@zorch.sf-bay.org>
Archive::Zip v1.07 has been released.
Changes since 1.06 include:
- Added file attribute code by Maurice Aubrey
- Added FAQ about RedHat 9 build errors
- Added check for empty filenames
Changes since 1.05 include the following:
- Fixed seek use with IO::Scalar and IO::String
- Fixed use of binmode with pseudo-file handles
- Removed qr{} form for older Perl versions
- Changed rel2abs logic in _asLocalName() if there is a volume
- Fixed errors with making directories in extractMember() when none
provided
- Return AZ_OK in extractMemberWithoutPaths() if member is a directory
- Fixed problem in extractTree with blank directory becoming "." prefix
- Added examples/writeScalar2.pl to show how to use IO::String as
destination of Zip write
- Edited docs and FAQ to recommend against using absolute path names in
zip files.
>From the README:
The Archive::Zip module allows a Perl program to create, manipulate,
read, and write Zip archive files.
Zip archives can be created, or you can read from existing zip files
or strings (using IO::Scalar). Once created, they can be written to
files, streams, or strings.
Members can be added, removed, extracted, replaced, rearranged, and
enumerated. They can also be renamed or have their dates, comments, or
other attributes queried or modified. Their data can be compressed or
uncompressed as needed. Members can be created from members in existing
Zip files, or from existing directories, files, or strings.
Directory trees can be added or extracted simply using special tree
routines.
This module uses the Compress::Zlib library to read and write the
compressed streams inside the files. Note that versions of Compress::Zlib
prior to 1.06 truncate data and should not be used.
Compress::Zlib prior to 1.08 caused crashes on some Windows systems.
Examples and helper libraries are given to show how:
* zip files can be read and written to strings
* zip files can be written in chunks to arbitrary functions
CHANGES SINCE v1.00:
1.05 Wed Sep 11 12:31:20 PDT 2002
- fixed untaint from 1.04
1.04 Wed Sep 11 07:22:04 PDT 2002
- added untaint of lastModFileDateTime
1.03 Mon Sep 2 20:42:43 PDT 2002
- Removed dependency on IO::Scalar
- Set required version of File::Spec to 0.8
- Removed tests of examples that needed IO::Scalar
- Added binmode() call to read/writeScalar examples
- Fixed addTree() for 5.005 compatibility (still untested with 5.004)
- Fixed mkdir() calls for 5.005
- Clarified documentation of tree operations
1.02 Fri Aug 23 17:07:22 PDT 2002
- Many changes for cross-platform use (use File::Spec everywhere)
- Separated POD from Perl
- Moved Archive::Zip::Tree contents into Archive::Zip
A::Z::Tree is now deprecated and will warn with -w
- Reorganized docs
- Added FAQ
- Added chunkSize() call to report current chunk size
and added C::Z BufSize patch from Yeasah Pell.
- Added fileName() to report last read zip file name
- Added capability to prepend data, like for SFX files
- Added examples/selfex.pl for self-extracting archives creation
- Added examples/zipcheck.pl for validity testing
- Made extractToFileNamed() set access/modification times
- Added t/testTree.t to test A::Z::Tree
- Fix/speed up memberNamed()
- Added Archive::Zip::MemberRead by Sreeji K. Das
- Added tempFile(), tempName()
- Added overwrite() and overwriteAs() to allow read/modify/write of zip
- added examples/updateZip.pl to show how to read/modify/write
1.01 Tue Apr 30 10:34:44 PDT 2002
- Changed mkpath call for directories to work with BSD/OS
- Changed tests to work with BSD/OS
COPYRIGHT:
Copyright (c) 2000-2003 Ned Konz. All rights reserved. This program is free
software; you can redistribute it and/or modify it under the same terms
as Perl itself.
AVAILABILITY:
>From CPAN, in directory
http://www.cpan.org/modules/by-authors/id/N/NE/NEDKONZ/
or
ftp://ftp.cpan.org/pub/CPAN/modules/by-authors/id/N/NE/NEDKONZ/
as Archive-Zip-1.07.tar.gz
------------------------------
Date: Mon, 20 Oct 2003 16:38:08 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Any thought on "Perl Database" based on "Tie:File"?
Message-Id: <Xns941A80897274Adkwwashere@216.168.3.30>
Tassilo v. Parseval <tassilo.parseval@rwth-aachen.de> wrote:
> I didn't look too closely, but I bet there's also a backend that
> keeps the data in your computer's RAM but lets you use the DBI
> module to access it with proper SQL statements.
DBD::RAM
:-)
Jeff Zucker wrote it, but I think he's more interested in his AnyData
modules nowadays.
> If such a backend
> was well written (preferably in C and not Perl), it could result
> in very fast database access. But it's, quite naturally, not
> suitable for large data sets. It might however be what you need
> since a real database is indeed overkill when you only have very
> data to deal with.
DBD::RAM is pure Perl....
--
David Wall
------------------------------
Date: 20 Oct 2003 17:30:58 GMT
From: Joona I Palaste <palaste@cc.helsinki.fi>
Subject: Re: C vs Perl
Message-Id: <bn164i$qho$1@oravannahka.helsinki.fi>
len v <ccya86@yahoo.com> scribbled the following
on comp.lang.c:
> A recent (Oct 3) Fox Trox comic (Bill Amend ) got me thinking causing me to
> edit the origional comic. Bill then had to write a patch, as most C
> programers must do.( http://homepage.mac.com/billamend/images/patch.gif )
> To see the comparison, go to ---> http://perl.hacker.freeservers.com/
Yes, and I could implement a language called FoxTrot that would have the
following program:
Do it
translate into code that wrote "I will not throw paper airplanes in
class" 500 times into stdout. But I wouldn't guarantee FoxTrot would be
useful for anything else.
IOW, one-off cases like these are useless for comparing elegance of
languages.
--
/-- Joona Palaste (palaste@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"It sure is cool having money and chicks."
- Beavis and Butt-head
------------------------------
Date: Mon, 20 Oct 2003 16:24:19 -0500
From: Programmer Dude <Chris@Sonnack.com>
Subject: Re: C vs Perl
Message-Id: <3F945283.44AE0E41@Sonnack.com>
len v wrote:
> A recent (Oct 3) Fox Trox comic (Bill Amend ) got me thinking
> causing me to edit the origional comic.
"Origional" ??
--
|_ CJSonnack <Chris@Sonnack.com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL |
|_____________________________________________|_______________________|
------------------------------
Date: Mon, 20 Oct 2003 13:05:15 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Displaying variables-list
Message-Id: <f4Rkb.9285$Y1.613@nwrddc03.gnilink.net>
Peter Pippinger wrote:
> I´m very new to perl. I have a list in %info.
No, you don't.
You have a hash %info. A hash is a mapping from a domain (usually called
keys) into a codomain (usually called values) and is something quite
different then a list.
> It has allways two
> parts: NAME and VALUE.
> For example:
> name1,value1,name2,value2,name3,value3... and so on.
>
>
> If i do the following...
> **
> foreach $test (%info){
You are using a hash in list context. Usually this indicates you are using
the wrong data structure and in general it is a bad idea unless you know
exactly what you are doing.
> print "$test \n";
> }
> **
> ...all the content of %info will be shown. But i need to have the
> content devided into the two variables. So that i can do something
> like that:
>
> LOOPBEGINNING
> print "$name $value";
> LOOPEND
>
> How can i do that?
Maybe all you are looking for is the keys() function (untested):
foreach $test (keys(%info)){
print "$test $info{$test} \n";
}
For further details please see the man page "perldoc -f keys".
jue
------------------------------
Date: Mon, 20 Oct 2003 17:15:15 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: Displaying variables-list
Message-Id: <DKUkb.7381$PZ1.2927@nwrdny03.gnilink.net>
Andrew Shitov <andy@shitov.ru> wrote:
> > foreach $test (%info){
> > print "$test \n";
> > }
>
> Threre are two keywords in perl: keys and values. In the code abouve you
> try to use a hash in array context. Not good idea ;-) 'Foreach' requires
> array, so give it to it.
Actually -- foreach() operates on a list, not an array. And a %hash
in list (not "array") context is the list of all the key/value pairs
flattened together.
> keys %info returns an array of all the keys of %hash. Likewise values
> %hash produses a list of all of its values.
>
> So, you should run something like this:
>
> foreach my $key (keys %info){
> print "$key=$info{$key}\n";
> }
Right. If you're not going to sort the output, you could also use
while() and each().
while (my ($k,$v) = each %info) {
print "$k => $v\n";
}
--
Steve
------------------------------
Date: Mon, 20 Oct 2003 16:29:42 GMT
From: "Dean Arnold" <darnold@presicient.com>
Subject: Re: Finding all used fileno's ?
Message-Id: <W3Ukb.5339$%b.3949@newssvr29.news.prodigy.com>
"Nicholas Dronen" <ndronen@io.frii.com> wrote in message
news:3f932665$0$199$75868355@news.frii.net...
> Dean Arnold <darnold@presicient.com> wrote:
> DA> I've got an app that calls an external
> DA> 3rd party C lib that opens sockets, but doesn't expose the sockets
> DA> directly outside of the library. I want to use the fileno's
> DA> of those sockets in a Perl select(read,write,error,timeout) call.
> DA> so I need to discover the fileno's of the sockets.
>
> DA> Q: will something like the following do what I need
> DA> (esp. on both Win32 and *nix) ? The upper fileno limit
> DA> is arbitrary, and can probably be tuned as needed.
>
> DA> @fdary = ();
> DA> foreach (0..23) {
> DA> $fdary[$_] = 1, next
> DA> unless open FH, "<&$_";
> DA> close FH;
> DA> }
>
> DA> foreach (0..$#fdary) {
> DA> print "$_ is available\n"
> DA> if defined($fdary[$_]);
> DA> }
>
> I don't know whether this works on Win32, but fstat seems to be
> a better approach than open on UNIX.
>
> #!/usr/bin/perl
> use POSIX qw/fstat/;
> for (0 .. 25) {
> print "$_ is open\n" if fstat $_;
> }
> $ ./fds
> 0 is open
> 1 is open
> 2 is open
>
Many thanks! It works splendidly on WinXP! Even tested
with a DBI conection open, and it caught that fd too.
Dean Arnold
Presicient Corp.
www.presicient.com
------------------------------
Date: Mon, 20 Oct 2003 18:18:58 GMT
From: "Public Interest" <no@no.no>
Subject: Re: Help me with is code
Message-Id: <mGVkb.186701$0v4.14426972@bgtnsc04-news.ops.worldnet.att.net>
"Tom" <tom@nosleep.net> дÈëÓʼþ news:3f938e92@nntp0.pdx.net...
>
> "Public Interest" <no@no.no> wrote in message
> news:h%Kkb.186169$0v4.14374681@bgtnsc04-news.ops.worldnet.att.net...
> > Dear Tom,
> > I work for nobody. I mainly two things:
> > 1 scan stocks: I scan the whole yahoo for dataming. I can also scan
other
> > websites for some paid data. For instance, yahoo asks me to pay $ for an
> > advanced screening and I don't want to pay it, so I scan the whole
website
> > to get the data and save it on my PC. I indeed try to sell the screen
> result
> > on it. For instance, I scan stocks greater than .9 and less than 10 with
> > volume more than 50K and P/B less than 10, then I use the data to scan
> > another Hedge Fund database to see how much hedge funds bought on those
> > shares... Every info I scan is public, but I just use Perl to do an EYE
> job.
> > I also do complicated scans such as finding the real price/book value=
> > marketcap/(equity-goodwill-intengible). This ratio is no where to be
> found,
> > but it is super good at picking value stocks...
> > 2 I run a website, which compete with nobody. I use a free classfies to
> > attrach visitors then I get paid by clicks...
> > I indeed have done great deals on stock research. I am a super Bear who
> > makes money in stocks. I know many are trading like me, but they have no
> > idea on programming. I have not known anyone makes less than 50% average
a
> > year. The best makes 200% this year the worst lost 10% when Nasdaq/S&P
> lost
> > 40%. My program can pin-point intraday highs and lows with 85% accuracy.
I
> > play spreads to make money easiler to make 3% per 2-3 days... Too easy
to
> > make money in stocks. I managed a big stock fund in China, several years
> > ago. It is too easy to make money in US stock market.
> >
> > I guess your AI has a lot of datamining, because Perl is the best
> > programming lang for datamining: Simple to think, less to program.
> Dataming
> > does not require speed or memory functions very much.
> >
> > If you could help me with my code, just show me what is wrong here.
Thank
> > you.
> > My voicemail is 603-316-2556. You will not talk to me personally, but
you
> > can leave a message. I don't post my real email here, but I got 10-60
> virus
> > spam per day after I did so last time.
> >
> > I did not steal your idea. My idea was totally mine. I started doing
that
> > way back in 96-97.
>
> I never said you stole any ideas.
> It doesn't even matter anyway. It's not going to change the market, or
what
> my AI can pick.
> I have features no one else has come up with before, but I'm a long ways
> from being done.
> All I know is the research I did up front, as well as prelim results I am
> calculating, I am confident I can do better than 1 or 2 % each trading
day.
> That's all anyone needs, as I'm sure you know.
> However, I have reason to believe I can even do better than that, we'll
see.
> I answered your email with the addy you posted and it was a borkers, for a
> big firm.
> I'm not interested in helping the enemy. :)
> I'm not sure how I can help you via voice messaging.
>
>
>
>
My dear friend, I work for no brokerage firms. I just put some hated
company's email address here. I can put whatever address here. All of my IPs
are from Dial-up. Do you think if I work in the brokage firm, I would have
to use a dial-up for internet access? Sure, I can hide my IP too, but I am
doing nothing illegal, so I don't think I will run into trouble.
Please contact my via my voicemail at 603-316-2556. All you need to do is to
leave your phone number or email address. My email is speedierco which is in
yahoo. You know what to do with yahoo and speedierco to form an email.
Right? Please put something uniqu in your message subject, otherwise, your
email will be deleted automatically as spam.
I think our ideas are very close from that you say "just 1-2%" better. All
financial indictors are made of Open, High, Low, Close, Volume, those 5
numbers, but there are way many hidden info in the intra-day, tick by tick
data. If you have done datamining before, there are ways to find intra-day
highs and lows... That was my work. But it is just a method for short-term
trading. I found other ways to use datamining for trading totally based on
perl, which is easier: trade only several times a months, not several times
a week...
------------------------------
Date: Mon, 20 Oct 2003 16:06:17 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Help me with is code
Message-Id: <slrnbp8ji9.j7f.tadmc@magna.augustmail.com>
Public Interest <no@no.no> wrote:
> I can put whatever address here.
So long then.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 20 Oct 2003 13:25:37 -0600
From: "Nathaniel Hekman" <hekmanATgeo-slopeDOTcom@no.spam>
Subject: interprocess queue (was Re: win32 interprocess communication on one machine)
Message-Id: <5HWkb.8738$f7.473921@localhost>
Thank you Anand. I played around with that a bit. Signals apparently don't
work well on Windows, and pipes only work between a single parent/child
pair.
I probably wasn't clear on this in my original post (because I didn't
realise it was an issue until I tried your ideas) but really what I'm
looking for is a message queue. I want several siblings all watching a
common queue. The parent puts a job on the queue, and the first child
available takes it off the queue and starts processing it. Meanwhile the
parent puts another job on the queue and when another child is available it
takes it off and processes it, and so on.
Anything out there like this? Or suggestions of alternate approaches?
Nate
"Anand" <some@one.com> wrote in message
news:AdYjb.3214$8x2.1892443@newssrv26.news.prodigy.com...
> You can use unnamed pipes for parent-child communication. Another
> alternative would be to use signals.
>
> --Anand
>
> Nathaniel Hekman wrote:
> > I have a parent process which spawns off several child processes using
> > Win32::Process. The parent is just a controller, the children are perl
> > scripts doing the actual work I'm trying to accomplish. The parent has
a
> > long list of jobs to do, launches three children to handle the first
three
> > jobs, and whenever any child finishes the parent launches another child
with
> > the next job, and so on until they're all done. (Ideally I'd like the
> > children to be threads instead of separate processes, but from what I
can
> > see ActivePerl doesn't support threads yet on Windows.)
> >
> > Unfortunately, if I launch these child processes too quickly one after
> > another, I get errors on the screen saying "could not extract perl
runtime"
> > or something along those lines. If I put a 2-3 second delay between
> > launching each child I don't get that problem, but of course it slows
down
> > the job.
> >
> > I'd like to change the design, and launch three children immediately,
then
> > feed them jobs. When one finishes a job it keeps running and the parent
> > gives another job to do. That would avoid shutting down and recreating
> > processes, and would avoid having to use that 2-second delay.
> >
> > I realise I could do this using sockets, but that seems like overkill
(and a
> > security risk) since the children and parent are running on the same
> > computer. What else would you suggest?
> >
> > Thanks for any ideas.
> >
> >
> > Nate Hekman
> > Calgary, Alberta, Canada
> >
> >
>
------------------------------
Date: Mon, 20 Oct 2003 22:26:41 +0200
From: Matija Papec <perl@my-header.org>
Subject: Mason pipeline style
Message-Id: <k4h8pv02bqpnp47poifo3oqp41msvskpev@4ax.com>
http://www.perl.com/lpt/a/2001/08/21/templating.html
>While the documentation mostly demonstrates a callback execution model, it is possible to use Mason in a pipeline style.
I would like to use Mason in pipeline style like described in article
(templates are strictly separated from code). Can someone show such examples
with Mason? Or should I consider Template Toolkit? :)
tia!
--
Matija
------------------------------
Date: Mon, 20 Oct 2003 20:48:04 GMT
From: "Bob X" <bobx@linuxmail.org>
Subject: Re: Mason pipeline style
Message-Id: <8SXkb.2040$CE2.2039756@news2.news.adelphia.net>
"Matija Papec" <perl@my-header.org> wrote in message
news:k4h8pv02bqpnp47poifo3oqp41msvskpev@4ax.com...
> http://www.perl.com/lpt/a/2001/08/21/templating.html
> >While the documentation mostly demonstrates a callback execution model,
it is possible to use Mason in a pipeline style.
>
> I would like to use Mason in pipeline style like described in article
> (templates are strictly separated from code). Can someone show such
examples
> with Mason? Or should I consider Template Toolkit? :)
> tia!
>
>
>
> --
> Matija
Look at HTML::Template as well. CGI::Application is great as well.
------------------------------
Date: Mon, 20 Oct 2003 13:39:27 +0000
From: Helgi Briem <HelgiBriem_1@hotmail.com>
Subject: Re: my first perl script!
Message-Id: <pvo7pvgfda9ng8fkcooandsedl2rvru9qb@4ax.com>
On Mon, 20 Oct 2003 12:29:02 GMT, "sdfgsd" <sdfg@sdg.com> wrote:
>It's a tough language at first because there is so much functionality to be
>had in so few lines of code that you really have to know ALL the basics
>before developing any non-trivial programs.
I disagree very vehemently. This may be true of Java or C++,
but you can start doing useful stuff *much* earlier in Perl.
>Best approach (IMHO), learn the basics
Yes.
> and study OPC (other peoples code)
With reservations. There's an awful lot of *horrible*
Perl code out there. Yours is very good by comparison.
There are repositories where you can see good Perl
code, for example:
http://www.stonehenge.com/merlyn/columns.html
http://nms-cgi.sourceforge.net/
http://www.perl.com
http://www.perlmonks.org/
> and have a specific need to learn it.
Yes. Learn to use perldoc, too. It will save you no end of
trouble.
------------------------------
Date: 20 Oct 2003 14:30:38 -0700
From: cmjensen@dohnut.org (dohnut)
Subject: Odd Perl bitwise-AND & MySQL problem?
Message-Id: <c6e455b3.0310201330.1df2bd9a@posting.google.com>
Here's one for some bored problem solver :)
I ran across this earlier today and fixed it, but don't exactly know
why. (that usually only happens in C :)
I'm using Perl version 5.8.0 btw.
Ok, let's start here: I end up with an array that comes from a
fetchrow_array() call to MySQL. I return the array to a function.
Ok, then the function does this (roughly):
sub func()
{
my @dat = shift;
my $val = $dat[3] & $dat[4] & $dat[5] & 0x7fff;
print $val;
}
In the MySQL database, element 0 = int, 1 = varchar(32), 2 =
varchar(255), 3 = int, 4 = int, 5 = int, 6 = int, etc..
Ok, so I call the function. Let's assume $dat[3] = 57 (0x39), $dat[4]
= 2045 (0x7fd), $dat[5] = 2047 (0x7ff).
Guess what I get for output? --> "00" (I should get 57 (0x39) btw)
Not just a zero "0" but _2_ zeros. So, clearly it thinks something
stringy is there. But why? I guess that is my question.
Now, if I populate @dat myself (i.e. don't get the values from MySQL
calls) it works fine.
To my knowledge only numbers are in the 3 variables and I've tested
this. If I print the values individually, they print correctly. I
also do a 'length' on them and I get 2, 4, and 4 respectively -- which
is correct.
How did I fix it?
my $val = int($dat[3]) & int($dat[4]) & int($dat[5]) & 0x7fff;
I added int()s around each value. So apparently Perl thought there
was something before the numbers in the variables?? Nothing should be
there but numbers, the values come from table elements that are ints
and are read right into a Perl array. Aside from a bug, I can't see
how this could get corrupted or how I could be missing something.
I've done quite a bit of MySQL/Perl programming and I've never had
this happen before, in fact, this specific problem doesn't happen all
the time even in this code. Only with when returning data from
specific rows (in my case), though it is consistent and reproducable
-- it's not flaky. I can note that $dat[2] (which comes from a
varchar(255)) contains some text and some "/r/n" characters. The ones
that don't fail don't contain "/r/n" characters in $dat[2]. I don't
know if this is related, I only have 3 rows of data (at the moment)
and 1 causes the problem.
I'm thinking this is a problem in the Perl MySQL DBI module? I
realize I can do more troubleshooting to narrow it down a bit better
and I probably will tonight, but just wanted to get it out there and
see what people thought. Maybe this has been seen before?
------------------------------
Date: 20 Oct 2003 09:58:38 -0700
From: brendan@symonty.org (brendan)
Subject: Re: Perl & Apache: modifying index.html while it's used
Message-Id: <282ee219.0310200858.731cc87d@posting.google.com>
Steve Grazzini <grazz@pobox.com> wrote in message news:<bJLkb.4913$Vf7.2741@nwrdny02.gnilink.net>...
> brendan <brendan@symonty.org> wrote:
> > What's the best way to ensure that Apache doesn't display the modified
> > file until it's fully written?
>
> You could write a temporary file and then close and rename() it.
Sure, I had a feeling that might be the best approach. Does Apache
cope alright with having a file being renamed like this?
------------------------------
Date: Mon, 20 Oct 2003 21:53:45 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Perl on AS400
Message-Id: <20031020175412.7f8a731d.jwillmore@remove.adelphia.net>
On 20 Oct 2003 01:00:13 -0700
mbr@petercam.be (Michel) wrote:
> James Willmore <jwillmore@remove.adelphia.net> wrote in message
> news:<20031015131011.1e3968f3.jwillmore@remove.adelphia.net>...
> >
> > If the AS400 is anything like the S390 in any way, you _may_ want
> > to check the translation table for the machine. And also make
> > sure the Perl binary was installed properly.
> >
> Thanks Jim, and you are right the problem state in the conversion
> tables_ When I use _qshell' with the CCSID 37 (US code page) perl
> seems to work ! So I do not understand why it didn't work with
> CCSID 500 (French Belgium, Canada, Switzerland) !
> Anyway I still have problems with the result of query.
> Problems are with characters fields or varchar , date etc .. except
> numeric field
> I give a example :
> 1) in CCSID 37 the query (in direct) works
> > db2 'select * from mbr.junk '
>
> JUNK1 JUNKTXT
> ----------------- --------------
> 1 Message un
> 26 Message 26
> 25 Message 25
>
> 3 RECORD(S) SELECTED.
>
> Now with this little perl script
> > cat mbdb.pl
> #! /usr/bin/perl
> use DBI;
> use DBD::DB2::Constants;
> use DBD::DB2;
> $dbh = DBI->connect("dbi:DB2:DBBABY") or die;
> $stmt = 'SELECT * FROM MBR.junk';
> $cur = $dbh->prepare($stmt);
> $cur->execute();
> die "Prepare error: $DBI::err ... $DBI::errstr" if $DBI::err;
> DBI::dump_results($cur);
> $cur->finish();
>
> And the result is:
> > mbdb.pl
> 1, undef
> 26, undef
> 25, undef
> 3 rows
> So here am I, trying to resolve the 2 problems a) CCSID 500 and 2)
> Why characters based fields are not be taken correctly by the
> constants definition module.
> Again many thanks to you.
I'm at a loss. Basically because I have zero experience with an AS400
:-( The code you published here is correct - it appears that there's
a disconnect between the DBD and DB2.
You _may_ consider installing, by hand (not through CPAN or a package)
the DBD::DB2 module. Maybe there's something funky there.
Sorry I can't be of more help :-(
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
Down with categorical imperative!
------------------------------
Date: Mon, 20 Oct 2003 09:20:13 -0400
From: Chris Mattern <syscjm@gwu.edu>
Subject: Re: Perl security guru needed for a quick, 2 hr, job.
Message-Id: <3F93E10D.2030402@gwu.edu>
Public Interest wrote:
> Javascript only works in IE,
Gee, I guess I must be imagining it when I see my Mozilla
render Javascript for me...
Chris Mattern
------------------------------
Date: 20 Oct 2003 07:16:18 -0700
From: mdshaxted@yahoo.co.uk (MDS)
Subject: Quick Perl question
Message-Id: <c9bc89ba.0310200616.38b201@posting.google.com>
Hi there,
Is there an easy way to write a Perl script for UNIX that returns the
user to the command line on execution, other than using ./myscript.pl
2>&1 or ./myscript.pl & ?
Thanks in advance,
Marc.
------------------------------
Date: 20 Oct 2003 14:24:19 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Quick Perl question
Message-Id: <slrnbp7s0j.oki.abigail@alexandra.abigail.nl>
MDS (mdshaxted@yahoo.co.uk) wrote on MMMDCCII September MCMXCIII in
<URL:news:c9bc89ba.0310200616.38b201@posting.google.com>:
`' Hi there,
`'
`' Is there an easy way to write a Perl script for UNIX that returns the
`' user to the command line on execution, other than using ./myscript.pl
`' 2>&1 or ./myscript.pl & ?
Sure. Start your program with:
(fork // die "Failed to fork: $!") && exit;
Abigail
--
$_ = "\x3C\x3C\x45\x4F\x54";
print if s/<<EOT/<<EOT/e;
Just another Perl Hacker
EOT
------------------------------
Date: Mon, 20 Oct 2003 16:39:10 GMT
From: Anand <some@one.com>
Subject: Re: Quick Perl question
Message-Id: <OcUkb.4571$8x2.2622961@newssrv26.news.prodigy.com>
I tried this but doesn't work. Could you please tell me where is glitch.
--
#!/usr/bin/perl
(fork() || die "Cannot fork: $!") && exit;
$num = "12345";
$res = substr ($num, 0, 3);
print "$res\n";
--
Thanks in advance.
--Anand
Abigail wrote:
> MDS (mdshaxted@yahoo.co.uk) wrote on MMMDCCII September MCMXCIII in
> <URL:news:c9bc89ba.0310200616.38b201@posting.google.com>:
> `' Hi there,
> `'
> `' Is there an easy way to write a Perl script for UNIX that returns the
> `' user to the command line on execution, other than using ./myscript.pl
> `' 2>&1 or ./myscript.pl & ?
>
>
> Sure. Start your program with:
>
> (fork // die "Failed to fork: $!") && exit;
>
>
> Abigail
------------------------------
Date: 20 Oct 2003 20:36:18 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Quick Perl question
Message-Id: <slrnbp8hq2.pik.abigail@alexandra.abigail.nl>
Anand (some@one.com) wrote on MMMDCCII September MCMXCIII in
<URL:news:OcUkb.4571$8x2.2622961@newssrv26.news.prodigy.com>:
** I tried this but doesn't work. Could you please tell me where is glitch.
Not if you top post.
Abigail
--
$=-=4*++$|;{print$"x--$==>"\@\x7Fy~*kde~box*Zoxf*Bkiaox \r"
^
$/x24if!select$,,$,,$,,join+q=.==>$^W=>$|;$=&&redo}sleep$|;
------------------------------
Date: 20 Oct 2003 09:42:58 -0700
From: sctommi@gmx.net (Thomas)
Subject: Re: really hard regex ;(
Message-Id: <5a1109df.0310200842.1d7a1057@posting.google.com>
Brian McCauley <nobull@mail.com> wrote in message news:<u9vfqnpyog.fsf@wcl-l.bham.ac.uk>...
> sctommi@gmx.net (Thomas) writes:
>
> > hi community...
> > i have a hard work with a "really good" regex -
> > my regex should substitute/insert (in pdf) something like
> > /V () with my new value...
> > my regex is working for the first time when i really have /V ()
> > but second time i substitute only until first ) without checked for a
> > \\ before the )
> >
> > s#([^\\]/V\s*\()((\))|(.*?[^\\]?\)))#$1$value)#ms
> >
> > im totally confused and have no idea where my mistake is in this regex
>
> Well since you do not define "something like" it is impossible to know
> what your regex is supposed to match. Without knowing that there's
> only so much one can do.
>
> First we can remove some of the () that do nothing.
>
> s#([^\\]/V\s*\()(\)|.*?[^\\]?\))#$1$value)#ms
>
> Then we can observe that the subpattern /.*?[^\\]?/ will match exactly
> the same as /.*?/
>
> s#([^\\]/V\s*\()(\)|.*?\))#$1$value)#ms
>
> Next we observe that ')', the only thing matched by the subpattern
> /\)/, could also be the 'best' match for /.*?\)/
>
> It follows that /\)|.*?\)/ will simplify to /.*?\)/
> s#([^\\]/V\s*\().*?\)#$1$value)#ms
u done a really nice simplification
> So I've simplified your regex so its easier to see that it does. But
> without knowing what it was supposed to do I can't say how to change
> it so that it does what you want.
that's what i really need to learn - thank u a lot !
> Random shot-in-the-dark. You original mistake was a spurious ? after [^\\]
> s#([^\\]/V\s*\()(\)|.*?[^\\]\))#$1$value)#ms
one of my mistakes...
> Although I'm usually not a fan of negative look-behind I think this is
> a case I would use it.
> s#((?<!\\)/V\s*\().*?(?<!\\)\)#$1$value)#ms
works fine until i use different counts of \
> I'd also consider using the /x qualifier.
only for easier reading or why else ?
> Alternative shot-in-the-dark, see FAQ: Can I use Perl regular
> expressions to match balanced text?
this means i cant do it with perl5 ?! ;)
here is my solution...
(maybe not the shortest - but it works in every case i know) :
$bsl = '\\'; # only for easier reading
$new1 = "$bsl)$bsl$bsl$bsl)simple text$bsl$bsl$bsl$bsl$bsl)$bsl$bsl";
$new2 = "easy text$bsl$bsl$bsl)simple text$bsl$bsl$bsl$bsl$bsl)";
$new3 = "$bsl$bsl$bsl)simple text";
$obj = ".../T (element) /FT /Tx
/V (first text$bsl$bsl$bsl)second text$bsl)last text$bsl$bsl)
/DA (/Cour 10 Tf 0 g)..."
print "$obj\n";
# test a little bit within foreach
foreach $new ($new1,$new2,$new3,$new3,$new3,$new2,$new2,$new1,$new3) {
$obj =~ s#([^\\]/V\s*\()(.*\))#$1#ms; # all what's maybe right after /V
$_ = $2; # to replace and the rest to save
@_ = split (/(\\+\))/ms,$_); # split for BSL's with added )
if (!$#_) { # no BSL's in front of )
s#(.*?)\)#$new)#ms; # until first )
$obj .= $_;
} else {
while (@_) {
$_ = shift @_;
if (/\\+\)/) { # BSL with added )
last if length($_)%2; # pair of BSL => unquoted )
} elsif (/^\)$/) { # single char
last;
} elsif (/.*?\)(.*)/ms) { # ) in the middle or at the end
unshift @_,$1; # save possbile rest
last;
} # i miss the else ;(
}
}
$obj =~ s#([^\\]/V\s*\()#$1$new)#ms;
$obj.=join('',@_);
print "$obj\n";
}
best regards
Thomas
------------------------------
Date: Mon, 20 Oct 2003 16:59:23 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Rookie: Constructing a large SQL INSERT statement
Message-Id: <pan.2003.10.20.14.59.22.671369@aursand.no>
On Mon, 20 Oct 2003 12:23:37 +0000, sdfgsd wrote:
>> The format of the INSERT statement is:
>>
>> INSERT INTO mytable (field_1, field_2, field_3)
>> VALUES (value_1, value_2, value_3),
>> (value_1, value_2, value_3),
>> (value_1, value_2, value_3),
>> (value_1, value_2, value_3),
>> etc. ;
> The above insert statement is used for large, single inserts into a
> MySQL table. Instead of looping over an INSERT statement a few thousand
> times, it is easier to construct the statement as the data is being
> generated, THEN deliver it to the database.
Is it? For me it is the other way around, really;
1. Gather the data.
2. Eventually do some processing before handing the data
over to the database.
3. Insert the data into the database.
4. Cleanup.
Seems like your way to do it combines #1 and #3, thus making it hard to do
#2.
Either way, it's quite trivial to do this in Perl. Let's say that you
have gathered your data as an array of arrays and are ready to insert them
into the database;
my $stInsert = $dbh->prepare( 'INSERT INTO table
(field_1, field_2, field_3)
VALUES (?, ?, ?)' );
foreach $record ( @$data ) {
$stInsert->execute( @$record );
}
$stInsert->finish();
Pretty clean to me.
--
Tore Aursand <tore@aursand.no>
------------------------------
Date: 20 Oct 2003 09:43:53 -0700
From: nobull@mail.com
Subject: Re: Rookie: Constructing a large SQL INSERT statement
Message-Id: <4dafc536.0310200843.486118bc@posting.google.com>
Tore Aursand <tore@aursand.no> wrote in message news:<pan.2003.10.20.06.20.06.732381@aursand.no>...
> On Mon, 20 Oct 2003 01:50:08 +0000, sdfgsd wrote:
> > The format of the INSERT statement is:
> >
> > INSERT INTO mytable (field_1, field_2, field_3)
> > VALUES (value_1, value_2, value_3),
> > (value_1, value_2, value_3),
> > (value_1, value_2, value_3),
> > (value_1, value_2, value_3),
> > etc. ;
>
> Is this valid SQL?
It's certainly not supported on at least one dialect of SQL (MSSQL).
> It seems to me, however, that you should do this in a loop, bind'ing the
> data to into the query. Example:
>
> my $stInsert = $dbh->prepare('INSERT INTO mytable
> (field_1, field_2, field_3)
> VALUES (?, ?, ?)');
> while ( ... ) {
> $stInsert->execute( $value_1, $value_2, $value_3 );
> }
Better still use the execute_array() method.
In most current DBD drivers this is just the same as the above loop
but may in future be more efficient.
> $stInsert->finish();
Unnecessarly calling finish() on DBI statement handles is, IMHO, a bad
habit.
For an explaination of the situations in which it is necessary see the
documentation of the finish() method in the DBI documentation.
------------------------------
Date: 20 Oct 2003 14:25:01 -0700
From: harteta@teleandina.net (Hernan)
Subject: some help
Message-Id: <895432a7.0310201325.5f2c7b34@posting.google.com>
I try to parse this data in another file, it comes from the pbx.
N 074 00 3534 A006028 10/16 09:19:36 00:07:24.0 A95214897
&
000 000
& 000
This formats repeat in every call, my problem comes when I try to fit
all this 3 lines in one line (I can parse 1 string), the data in line
2 and 3 starts after "&".
Please some can help me
Hernan
------------------------------
Date: 20 Oct 2003 10:32:08 -0700
From: usenet@baccus.ca (Grant)
Subject: Re: TCP close_wait problem
Message-Id: <e43eeb25.0310200932.16409c95@posting.google.com>
Bill <wherrera@lynxview.com> wrote in message news:<jh2kb.110226$qj6.5679009@news1.news.adelphia.net>...
> Grant wrote:
> > The Perl script resides on a Solaris 8 box, using Perl 5.8.0. Since
> > I've done a bit of C coding in the past, I've been able to determine
> > what the code is doing. It's a multithreaded script that opens a
> > socket to a number of W2K servers and reads data that is spit out from
> > an app on the W2K servers (data is dumped to port 3000 on its own
> > machine, a socket connection is made to this port, and the data is
> > picked up). The data then is dumped into a Queue from all operating
> > threads, then piped into another probe for further processing.
>
> > The problem occurs when the app on the W2K box initiates a disconnect.
>
> I think perhaps that this is where the problem lies. Maybe your perl
> program needs to initiate the disconnect from the socket it opened itself.
>
This is what I think I have to do. I've even tried a hard shutdown of
the W2K app (sending a RESET packet), and the Perl script acts no
different. I'm thinking I need to initiate a disconnect on the Perl
end, shortly after the W2K end has come back up. The only issue with
this is timing: the W2K app *begins* the application restart at 7am
each day, but it is not automatic... it usually is fully shutdown by
7:02am.
> > I installed Windump on the W2K server, and saw that the app does send
> > a FIN and ACK, and does recieve an ACK back from the Perl probe, but
> > the FIN and ACK from the probe are never sent to the W2K server. Thus,
> > the W2K machine is stuck in a FIN_WAIT_2 state, and the Solaris
> > machine in a CLOSE_WAIT state. The states remain until the Perl probe
>
> Does the Perl program know when it is done with the read, or can it use
> an independent activity timeout routine for this read if it cannot
> otherwise know?
>
> If so, can the perl program initiate the disconnect, or even just exit,
> without the Win32 box doing so first?
Basically, the way I interpret the script, the program as it stands is
stupid to the connection(s) it has going: It doesn't know when the W2K
app is disconnected or reconnected the TCP connection, and it doesn't
know when the read should be done. It only has a timeout value that is
used to determine when a Queue is not recieving data for specified
length of time.
But as you mentioned earlier, I'm thinking I have to initiate the
disconnect on the Perl side.
Thanks a bunch for the suggestion. I think I might've been going at
the solution the wrong way.
Grant
------------------------------
Date: 20 Oct 2003 14:42:32 -0700
From: smith4894@excite.com (gorda)
Subject: using perl on the command line, like sed or awk
Message-Id: <87fbf9fb.0310201342.38bebd84@posting.google.com>
Hello,
Using sed or awk, I can quickly parse and perform operations on the
command line itself as in:
cat file | sed 's/cat/dog'
cat file | awk ' /cat/ {print "found the cat"} '
How can i do something like the above in perl on the command line
without having to write a script in a seperate file?
Thanks
-s
------------------------------
Date: Mon, 20 Oct 2003 22:01:14 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: using perl on the command line, like sed or awk
Message-Id: <KWYkb.8749$PZ1.7667@nwrdny03.gnilink.net>
gorda <smith4894@excite.com> wrote:
> cat file | sed 's/cat/dog'
> cat file | awk ' /cat/ {print "found the cat"} '
Three out of five (useful uses of 'cat') ain't bad, I guess.
> How can i do something like the above in perl on the command line
> without having to write a script in a seperate file?
Have a look at the perlrun manpage.
perl -pe s/cat/dog/g file
perl -lne '/cat/ and print "found the cat"' file
--
Steve
------------------------------
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 5685
***************************************