[24250] in Perl-Users-Digest
Perl-Users Digest, Issue: 6441 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 21 14:05:49 2004
Date: Wed, 21 Apr 2004 11:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 21 Apr 2004 Volume: 10 Number: 6441
Today's topics:
Re: .plx <spamtrap@dot-app.org>
Re: .plx <tadmc@augustmail.com>
Re: .plx <spamtrap@dot-app.org>
ANNOUNCE: Readonly 1.03 <sdn.girths00869@zoemail.net>
Creating hash with an array as value <anders_postkasseKEINEJUNK@hotmail.com>
Re: Creating hash with an array as value <jwillmore@remove.adelphia.net>
Re: Creating hash with an array as value <ittyspam@yahoo.com>
Re: Creating hash with an array as value <vetro@online.no>
Re: Creating hash with an array as value <sdn.girths00869@zoemail.net>
Help: DynaLoader.pm chokes on "undefined symbol" <socyl@987jk.com>
Re: Is it possible to 'word wrap' lines just using RegE axel@white-eagle.co.uk
Re: Match Offset: length($`) <hawkesm@on3etel.n5et.u9k>
Re: more code...(unfinished) <kirk@strauser.com>
Moving Directory using win32api::File <b.gaber@pwgsc.gc.ca>
Robust Method For Testing Database Handles (Keg)
Re: Robust Method For Testing Database Handles <tore@aursand.no>
Re: slurp not working? ideas please! <tassilo.parseval@rwth-aachen.de>
Re: sort numeric lists <jgibson@mail.arc.nasa.gov>
Re: sort numeric lists <King@ask.for.email.invalid>
Re: sort numeric lists <uri.guttman@fmr.com>
variable interpolation failed :-( <fred@no-spam.fr>
Re: variable interpolation failed :-( <ittyspam@yahoo.com>
Re: variable interpolation failed :-( <fred@no-spam.fr>
Re: variable interpolation failed :-( <jurgenex@hotmail.com>
Re: variable interpolation failed :-( <tore@aursand.no>
Re: variable interpolation failed :-( <tore@aursand.no>
Re: variable interpolation failed :-( <fred@no-spam.fr>
Writing dupliactes to database file (Testor)
Re: Writing dupliactes to database file <tadmc@augustmail.com>
Re: Writing fast(er) performing parsers in Perl <clint@0lsen.net>
YAML Problem <Zimmermann.David@siemens.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 21 Apr 2004 11:49:11 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: .plx
Message-Id: <__OdnRSK0NNmChvdRVn-gg@adelphia.com>
Robin wrote:
> actually I know quite a bit about nt servers....
... and little about Perl. You're not ready for advanced Perl topics. Heck,
you're barely beginning to get a grasp on the basics.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Wed, 21 Apr 2004 12:35:37 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: .plx
Message-Id: <slrnc8dc79.1lo.tadmc@magna.augustmail.com>
Robin <robin@infusedlight.net> wrote:
> actually I know quite a bit about nt servers....
Do you have any bridges for sale?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 21 Apr 2004 13:57:21 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: .plx
Message-Id: <o5GdnZjXOZifKxvd4p2dnA@adelphia.com>
Tad McClellan wrote:
> Do you have any bridges for sale?
I'll give you one for free! (Link is in my .sig) ;-)
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Wed, 21 Apr 2004 01:20:04 GMT
From: "Eric J. Roode" <sdn.girths00869@zoemail.net>
Subject: ANNOUNCE: Readonly 1.03
Message-Id: <HwJ42y.1osw@zorch.sf-bay.org>
ANNOUNCEMENT
Readonly.pm, v1.03 has been uploaded to PAUSE, and should be available at a
CPAN near you Real Soon Now.
DESCRIPTION
Readonly.pm provides a facility for creating non-modifiable scalars,
arrays, and hashes. This module offers several improvements over
constant.pm.
CHANGES SINCE 1.02
Damian Conway suggested a change in the prototype for the Readonly()
function, to permit the following usage:
Readonly $foo => 1;
Readonly my $bar => 2;
Readonly @foo => (3, 4, 5, 6);
Readonly my @bar => (7, 8, 9);
Readonly %foo => (ten=>10, eleven=>11);
Readonly my %bar => (twelve=>12);
This is cleaner and more obvious than the present usage, which requires
that the first parameter to Readonly() be a backslashed reference to the
variable being created. Alas, this new usage is only available for Perl
versions 5.8 and greater; earlier Perls must still use the backslash form.
LICENSE
The Readonly module is copyright by Eric J. Roode, but is freely
distributable under the same terms as Perl itself.
------------------------------
Date: Wed, 21 Apr 2004 16:02:30 +0200
From: Anders Christensen <anders_postkasseKEINEJUNK@hotmail.com>
Subject: Creating hash with an array as value
Message-Id: <c65uri$u2k$3@news.cybercity.dk>
Hi, I'm selecting two columns from my database. What I want to do with the
fetched data is to organize it into a single hash so that each different A
from the database is used as the hash-key. The hash-value should be an
array containing every B from the database, where A and B is on the same
row. An example:
----------------
| A | B |
----------------
| text1 | foo |
| text2 | bar |
| text1 |foobar |
| text3 | oof |
| text3 | test |
| text1 | rab |
----------------
I want to end up with one hash, where...
$prods->{text1} is the array (foo, foobar, rab)
$prods->{text2} is the array (bar)
$prods->{text3} is the array (oof, test)
I've tried the following code without succes :
my %hack_hash;
my $prods = \%hack_hash;
SendSQL("SELECT A, B FROM table WHERE 1");
while (MoreSQLData()) {
my ($a, $b) = FetchSQLData();
push $prods->{$a}, $b;
}
I receive this error: "Type of arg 1 to push must be array (not hash
element)"
To proof to myself, that it is possible to arrange data as I want, I
executed the following code succesfully - with the desired result. Heres
the "proof-code":
my %hack_hash;
my $prods = \%hack_hash;
my @tmp1 = ('foo', 'foobar', 'rab');
$prods->{'text1'} = \@tmp1;
my @tmp2 = ('bar');
$prods->{'text2'} = \@tmp2;
my @tmp3 = ('oof', 'test');
$prods->{'text3'} = \@tmp3;
Can someone give me a tip? If possible at all, I'd like to do it in one
single loop...
./Anders
------------------------------
Date: Wed, 21 Apr 2004 10:11:23 -0400
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Creating hash with an array as value
Message-Id: <pan.2004.04.21.14.11.16.512266@remove.adelphia.net>
On Wed, 21 Apr 2004 16:02:30 +0200, Anders Christensen wrote:
> Hi, I'm selecting two columns from my database. What I want to do with the
> fetched data is to organize it into a single hash so that each different A
> from the database is used as the hash-key. The hash-value should be an
> array containing every B from the database, where A and B is on the same
> row.
[ ... ]
> Can someone give me a tip? If possible at all, I'd like to do it in one
> single loop...
You might be able to use DBIx::Table2Hash
(http://search.cpan.org/~rsavage/DBIx-Table2Hash-1.12/Table2Hash.pm)
You can read each record from a datasource into a hash reference in a
while loop. This is covered in the DBI documentation.
HTH
--
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 ...
Famous last words:
------------------------------
Date: Wed, 21 Apr 2004 10:13:35 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Creating hash with an array as value
Message-Id: <20040421101043.V15178@dishwasher.cs.rpi.edu>
On Wed, 21 Apr 2004, Anders Christensen wrote:
> Hi, I'm selecting two columns from my database. What I want to do with the
> fetched data is to organize it into a single hash so that each different A
> from the database is used as the hash-key. The hash-value should be an
> array containing every B from the database, where A and B is on the same
> row. An example:
> ----------------
> | A | B |
> ----------------
> | text1 | foo |
> | text2 | bar |
> | text1 |foobar |
> | text3 | oof |
> | text3 | test |
> | text1 | rab |
> ----------------
>
> I want to end up with one hash, where...
> $prods->{text1} is the array (foo, foobar, rab)
> $prods->{text2} is the array (bar)
> $prods->{text3} is the array (oof, test)
>
> I've tried the following code without succes :
> my %hack_hash;
> my $prods = \%hack_hash;
> SendSQL("SELECT A, B FROM table WHERE 1");
> while (MoreSQLData()) {
> my ($a, $b) = FetchSQLData();
> push $prods->{$a}, $b;
> }
>
> I receive this error: "Type of arg 1 to push must be array (not hash
> element)"
You need to tell Perl that $prods->{$a} is an array reference (because at
this point in your code, it's nothing - you need to autovivify it). To
do so, dereference the new reference:
push @{$prods->{$a}}, $b;
That says "Push $b onto the array referenced by the value of the hash
referenced by $prods keyed at $a." If no such array reference exists, it
will spring into existence.
Paul Lalli
------------------------------
Date: Wed, 21 Apr 2004 16:19:12 +0200
From: Vetle Roeim <vetro@online.no>
Subject: Re: Creating hash with an array as value
Message-Id: <m3vfjtza5b.fsf@quimby.dirtyhack.org>
* Anders Christensen
[...]
> I want to end up with one hash, where...
> $prods->{text1} is the array (foo, foobar, rab)
> $prods->{text2} is the array (bar)
> $prods->{text3} is the array (oof, test)
>
> I've tried the following code without succes :
> my %hack_hash;
> my $prods = \%hack_hash;
> SendSQL("SELECT A, B FROM table WHERE 1");
> while (MoreSQLData()) {
> my ($a, $b) = FetchSQLData();
> push $prods->{$a}, $b;
> }
>
> I receive this error: "Type of arg 1 to push must be array (not hash
> element)"
If I'm not mistaken, you'd want to push like this instead:
push @{ $prods->{$a} }, $b;
That should produce the result you want. The trick here is to force
the hash element to be an array reference. :)
Btw; there's no reason to use $prod when you could use %hach_hash
directly like this:
push @{ $hach_hash{$a} }, $b;
HTH.
[...]
--
#!/usr/bin/vr
------------------------------
Date: Wed, 21 Apr 2004 10:09:26 -0500
From: "Eric J. Roode" <sdn.girths00869@zoemail.net>
Subject: Re: Creating hash with an array as value
Message-Id: <Xns94D271A95340Csdn.comcast@216.196.97.136>
Anders Christensen <anders_postkasseKEINEJUNK@hotmail.com> wrote in
news:c65uri$u2k$3@news.cybercity.dk:
> I've tried the following code without succes :
> my %hack_hash;
> my $prods = \%hack_hash;
> SendSQL("SELECT A, B FROM table WHERE 1");
> while (MoreSQLData()) {
> my ($a, $b) = FetchSQLData();
> push $prods->{$a}, $b;
> }
>
> I receive this error: "Type of arg 1 to push must be array (not hash
> element)"
Yeah, the first argument to push *must* begin with an @ symbol. What you
need is:
push @{ $prods->{$a} }, $b;
Other than that, you're on the right track.
------------------------------
Date: Wed, 21 Apr 2004 17:10:35 +0000 (UTC)
From: kj <socyl@987jk.com>
Subject: Help: DynaLoader.pm chokes on "undefined symbol"
Message-Id: <c669ub$emp$1@reader2.panix.com>
I'm trying to install XML::Xerces via the usual
perl Makefile.PL
make
make test
make install
I'm getting wholesale failure at the "make test" stage, with error
messages such as this:
Can't load '/home/jones/.cpan/build/XML-Xerces-2.3.0-4/blib/arch/auto/XML/Xerces/Xerces.so' for module XML::Xerces: /home/jones/.cpan/build/XML-Xerces-2.3.0-4/blib/arch/auto/XML/Xerces/Xerces.so: undefined symbol: _Q211xercesc_2_316XMLPlatformUtils.fgMemoryManager at /opt/lib/perl5/5.8.3/i686-linux/DynaLoader.pm line 229.
at /home/jones/.cpan/build/XML-Xerces-2.3.0-4/blib/lib/XML/Xerces.pm line 7
Compilation failed in require at t/AttributeList.t line 11.
It is not *entirely* clear to me why I'm getting this undefined
"symbol error" now, but not during the earlier "make" stage (which
proceeded without a hitch).
FWIW, the problematic symbol
_Q211xercesc_2_316XMLPlatformUtils.fgMemoryManager is mentioned
both in ./blib/arch/auto/XML/Xerces/Xerces.so and in
./Xerces.o.
One potential source of difficulty is the fact that I'm working
with a Perl that is installed with a non-standard prefix (/opt
instead of /usr or /usr/local), but I have not seen this kind of
problem before when I have installed other modules, including
several whose installation included *.so files.
Any ideas?
Thanks!
kj
--
NOTE: In my address everything before the period is backwards.
------------------------------
Date: Wed, 21 Apr 2004 16:02:21 GMT
From: axel@white-eagle.co.uk
Subject: Re: Is it possible to 'word wrap' lines just using RegEx?
Message-Id: <hWwhc.1095$54.898@dentist.cableinet.net>
Dave Cross <dave@dave.org.uk> wrote:
> Or Text::Wrap.
Although beware of the example of use given in the Camel book as the
sample given manages to ignore single letter words such as 'a'.
Axel
------------------------------
Date: Wed, 21 Apr 2004 17:16:05 +0100
From: Marco <hawkesm@on3etel.n5et.u9k>
Subject: Re: Match Offset: length($`)
Message-Id: <01xhc.92$DK4.30@newsfe1-win>
> But does your benchmark also time other matches (where you don't need
> $PREMATCH)? The slow-down means that even inconspicuous lines such as
>
> if (/^\d+$/)
>
> are now made capturing by perl.
>
> The slow-down does not happen for matches that are capturing anyway. Try
> it on non-capturing matches and see what happens.
My first benchmark didn't include other matches after I'd used
$PREMATCH. Now it does and I can see the real cost of $PREMATCH because
it requires retention of state across all matches, even if they didn't
need it beforehand. Thanks Uri and Tassilo for your explanations.
# slightly better benchmark to measure cost of $PREMATCH
# $text contains 1406 characters (single byte ASCII encoded)
sub get_matched_offset_1 {
$text =~ /\b$keyword\b/;
my $offset = length $`; # rvalue $-[0] tests faster
# other random matches
$text =~ /[\W]\s/ && $text =~ /\w{3}/;
}
If $text is a small string, length($`) isn't much slower than $-[0]. But
as $text gets bigger, the cost of $` gets more noticeable. $-[0] scales
better.
>> # Benchmark::timethis -- runs 89766.61 times per second
>> sub get_matched_offset_2 {
>> $text =~ /(\b$keyword\b)/;
>> index $text, $1;
>> }
As Uri pointed out, this is obviously a mistake because index() won't
respect word boundaries. In fact, that's the reason I used a regex to
begin with, because index() was finding "amber" in "chamber"! Doh!
Many thanks,
Marco
----------------------------------------------------
Please remove digits from e-mail address (tr/0-9//d)
------------------------------
Date: Wed, 21 Apr 2004 14:35:11 GMT
From: Kirk Strauser <kirk@strauser.com>
Subject: Re: more code...(unfinished)
Message-Id: <87pta1bdve.fsf@strauser.com>
=2D----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
At 2004-04-21T06:37:41Z, Uri Guttman <uri@stemsystems.com> writes:
> please learn python and spam their newsgroup.
Take it back! I'm not kidding: retract that at once! If I have to read his
stuff in *two* of my favorite groups, I *will* find you.
=2D --=20
Kirk Strauser
The Strauser Group
Open. Solutions. Simple.
http://www.strausergroup.com/
=2D----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFAhoYF5sRg+Y0CpvERAlfzAKCY8kU3nJQmZi7rmXrghIGy5Pnw4ACfbx8F
smZxPySvHfXPf4uzemMpLPc=3D
=3DJg1N
=2D----END PGP SIGNATURE-----
------------------------------
Date: Wed, 21 Apr 2004 11:09:45 -0400
From: Brian <b.gaber@pwgsc.gc.ca>
Subject: Moving Directory using win32api::File
Message-Id: <40868EB9.EB1D88F@pwgsc.gc.ca>
I am trying to move a directory that contains numerous other
subdirectories, e.g. c:\temp\source\temp1, temp2, to a new directory,
e.d. c:\test. Here is my script:
use Win32API::File qw( :ALL );
use strict;
my $source = "c:\\temp\\source";
my $destination = "c:\\test";
my $mvError = "";
MoveFileEx( $source, $destination, MOVEFILE_REPLACE_EXISTING() )
or die "Can't move $source to $destination: ",fileLastError(),"\n";
I get the following error:
Can't move c:\temp\source to c:\test\: Access is denied
Any ideas?
When I try: MoveFile( $source, $destination )
I get an error stating that the file already exists
------------------------------
Date: 21 Apr 2004 07:09:44 -0700
From: rhugga@yahoo.com (Keg)
Subject: Robust Method For Testing Database Handles
Message-Id: <6c795a35.0404210609.770b1d47@posting.google.com>
Hey all,
Trying to determine a reliable, rock-solid, low-cost method of testing
a database handle.
If the database is down or the connection fails or anything that will
cause operations on a database handle to fail, will my database handle
be undefined then? I wonder because the following code gives me
inconsistent results when the system load gets high:
if (!defined($dbh1)) {
....
Is this a rock solid way of testing your database connection? Does
anyone use $dbh1->ping??? The documentation says that unless you know
for sure you need to use the ping() method, you likely don't.
Basically I have a daemon written in perl that runs 24/7 and analyzes
various processes and logs information to a mysql database. Inside my
main loop I check the database handle each iteration and if it is
down, I spin until a connection can be re-established. However, my
problem lies in the testing of the connection and how to properly do
this.
I can't afford to disconnect and reconnect, this is a very
high-throughput process. I also want to avoid using a SQL query just
to test if the database handle is still valid or not.
My environment is RH 9 running a vanilla 2.4.20-28.9smp kernel, a
vanilla build of mysql-max-4.0.18, perl DBI 1.42, DBD::mysql 2.9003,
and vanilla perl 5.8.
Thx,
Keg
------------------------------
Date: Wed, 21 Apr 2004 16:55:35 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Robust Method For Testing Database Handles
Message-Id: <pan.2004.04.21.14.54.37.347976@aursand.no>
On Wed, 21 Apr 2004 07:09:44 -0700, Keg wrote:
> Trying to determine a reliable, rock-solid, low-cost method of testing
> a database handle.
I happen to use this all the time, which works all the time (and under
heavy load);
unless ( defined $dbh || $dbh->ping() ) {
# Connect
}
--
Tore Aursand <tore@aursand.no>
"The road to hell is full of good intentions." (Bruce Dickinson)
------------------------------
Date: 21 Apr 2004 15:21:14 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: slurp not working? ideas please!
Message-Id: <c663h9$6sl38$1@ID-231055.news.uni-berlin.de>
Also sprach Geoff Cox:
> On 21 Apr 2004 09:26:17 GMT, "Tassilo v. Parseval"
><tassilo.parseval@rwth-aachen.de> wrote:
>
> Tassilo
>
> just one more question!?
>
> In one of the html files I have for example
>
><h2> jkaskdjkla </h2>
>
><option values etc
>
><p> hsajdj ka </p>
>
> The code is giving the data in a different order, ie
>
><h2> jkaskdjkla </h2>
>
><p> hsajdj ka </p>
>
><option values etc
Where is this last line produced? In the snippet you provided, you only
print text wrapped in <h2> and <p> tags so I can't see where the last
line would come from.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Wed, 21 Apr 2004 08:43:41 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: sort numeric lists
Message-Id: <210420040843416205%jgibson@mail.arc.nasa.gov>
In article <x78ygpo5si.fsf@mail.sysarch.com>, Uri Guttman
<uri@stemsystems.com> wrote:
> >>>>> "RL" == René Larsen <rene.larsen@spamfilter.dk> writes:
>
> >> @sorted = sort {$a->[1] <=> $b->[1]} @rows;
> >> @sorted = sort {$a->[2] <=> $b->[2]} @rows;
>
> RL> This is where you are making mistakes. You sort the data twice *but*
> you
> RL> only keep the last. You probably meant:
>
> RL> @sorted = sort {$a->[1] <=> $b->[1]} @rows;
> RL> @sorted = sort {$a->[2] <=> $b->[2]} @sorted;
>
> RL> But normally when sorting by more than one key, one sorts the *last*
> key
> RL> first:
>
> RL> @sorted = sort {$a->[2] <=> $b->[2]} @rows;
> RL> @sorted = sort {$a->[1] <=> $b->[1]} @sorted;
>
> RL> Try sorting your data on paper, and see what happens if you sort it
> from
> RL> left to right or right to left.
>
> that will not be any better than his code. 2 separate sorts will not do it.
I am afraid that is incorrect. You can emulate a multi-column sort by
sorting on individual columns in multiple passes provided 1) you have a
stable sort (sequence-preserving) and 2) you sort in inverse order of
priority. Try it and see.
------------------------------
Date: Wed, 21 Apr 2004 16:15:41 GMT
From: The King of Pots and Pans <King@ask.for.email.invalid>
Subject: Re: sort numeric lists
Message-Id: <N6xhc.68781$U83.68159@fed1read03>
On Wed, 21 Apr 2004 at 12:48 GMT, Uri Guttman spoke:
> this isn't better, it is correct. see my other post where i divined
> his problem without even seeing any code. :)
I appreciate your insight in this matter. You appear to have extensive
education in this area.
For this problem I can only use the standard modules that come with
Perl 5.6. Is perl 5.6 up to the task? Or can the solution only be had
by downloading your module?
--
The King of Pots and Pans
------------------------------
Date: 21 Apr 2004 12:00:43 -0400
From: Uri Guttman <uri.guttman@fmr.com>
Subject: Re: sort numeric lists
Message-Id: <siscbrll5nis.fsf@tripoli.fmr.com>
>>>>> "JG" == Jim Gibson <jgibson@mail.arc.nasa.gov> writes:
JG> In article <x78ygpo5si.fsf@mail.sysarch.com>, Uri Guttman
JG> <uri@stemsystems.com> wrote:
RL> But normally when sorting by more than one key, one sorts the *last*
>> key
RL> first:
>>
RL> @sorted = sort {$a->[2] <=> $b->[2]} @rows;
RL> @sorted = sort {$a->[1] <=> $b->[1]} @sorted;
>> that will not be any better than his code. 2 separate sorts will
>> not do it.
JG> I am afraid that is incorrect. You can emulate a multi-column sort
JG> by sorting on individual columns in multiple passes provided 1)
JG> you have a stable sort (sequence-preserving) and 2) you sort in
JG> inverse order of priority. Try it and see.
yes, that would work. and in older perls the sort function was not
stable (it is now). so that is not always a viable option. so a multikey
sort is still a better choice IMO.
uri
------------------------------
Date: Wed, 21 Apr 2004 16:09:16 +0200
From: "fred" <fred@no-spam.fr>
Subject: variable interpolation failed :-(
Message-Id: <pan.2004.04.21.14.09.16.715800@no-spam.fr>
Hi !
I trie to remove the extention of a file name.
The folowing code work well :
$nom_fichier_final =~ s/pdf// ;
but the folowing one failed and I do not
understand why :-( Indeed according to the
PERL documentation, $motif should be replaced
by pdf during compilation...
my $motif = 'pdf' ;
$nom_fichier_final =~ s/$motif// ;
Thank you for your help !
------------------------------
Date: Wed, 21 Apr 2004 10:17:43 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: variable interpolation failed :-(
Message-Id: <20040421101532.I15178@dishwasher.cs.rpi.edu>
On Wed, 21 Apr 2004, fred wrote:
> Hi !
>
> I trie to remove the extention of a file name.
> The folowing code work well :
>
> $nom_fichier_final =~ s/pdf// ;
>
> but the folowing one failed and I do not
> understand why :-( Indeed according to the
> PERL documentation, $motif should be replaced
> by pdf during compilation...
>
> my $motif = 'pdf' ;
> $nom_fichier_final =~ s/$motif// ;
>
> Thank you for your help !
>
Those two code segments do exactly the same thing. If one did what you
wanted, so shoudl the other. Therefore, you're either not showing us
you're actual code, or there is something else wrong with your program
that you've discounted as the possible cause of your bug. Post a *short
but complete* program demonstrating the problem you're seeing.
BTW, it's "Perl", not "PERL". And also, if you really want to remove the
.pdf extension, wouldn't you want a regexp of
s/\.pdf$//;
rather than what you have?
Paul Lalli
------------------------------
Date: Wed, 21 Apr 2004 16:31:00 +0200
From: "fred" <fred@no-spam.fr>
To: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: variable interpolation failed :-(
Message-Id: <pan.2004.04.21.14.30.57.770891@no-spam.fr>
I just come to find the error : there was a blanck just after $motif and I
did nit see it ! :-)
Le Wed, 21 Apr 2004 10:17:43 -0400, Paul Lalli a écrit :
> On Wed, 21 Apr 2004, fred wrote:
>
>> [texte rapporté caché]
>
> Those two code segments do exactly the same thing. If one did what you
> wanted, so shoudl the other. Therefore, you're either not showing us
> you're actual code, or there is something else wrong with your program
> that you've discounted as the possible cause of your bug. Post a *short
> but complete* program demonstrating the problem you're seeing.
>
> BTW, it's "Perl", not "PERL". And also, if you really want to remove the
> .pdf extension, wouldn't you want a regexp of
> s/\.pdf$//;
> rather than what you have?
>
> Paul Lalli
------------------------------
Date: Wed, 21 Apr 2004 14:39:26 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: variable interpolation failed :-(
Message-Id: <yIvhc.17261$Aq.13844@nwrddc03.gnilink.net>
Paul Lalli wrote:
> On Wed, 21 Apr 2004, fred wrote:
>> I trie to remove the extention of a file name.
[...]
And also, if you really want to remove
> the .pdf extension, wouldn't you want a regexp of
> s/\.pdf$//;
> rather than what you have?
Wouldn't you rather want to use File::Basename instead of a regexp?
jue
------------------------------
Date: Wed, 21 Apr 2004 16:55:35 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: variable interpolation failed :-(
Message-Id: <pan.2004.04.21.14.48.57.324030@aursand.no>
On Wed, 21 Apr 2004 16:09:16 +0200, fred wrote:
> I trie to remove the extention of a file name. The folowing code work
> well :
>
> $nom_fichier_final =~ s/pdf// ;
It doesn't work well, as it doesn't necessarily remove _only_ the
filename's extension; it will remove _all_ occurances of 'pdf' in
$nom_fichier_final.
You probably want this:
$nom_fichier_final =~ s/\.pdf$//i;
> my $motif = 'pdf' ;
> $nom_fichier_final =~ s/$motif// ;
This should also work, so there must be a problem somewhere else in your
code.
--
Tore Aursand <tore@aursand.no>
"Omit needless words. Vigorous writing is concise. A sentence should
contain no unnecessary words, a paragraph no unnecessary sentences,
for the same reason that a drawing should have no unnecessary lines
and a machine no unnecessary parts." (William Strunk Jr.)
------------------------------
Date: Wed, 21 Apr 2004 18:24:14 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: variable interpolation failed :-(
Message-Id: <pan.2004.04.21.16.23.01.449687@aursand.no>
On Wed, 21 Apr 2004 16:31:00 +0200, fred wrote:
> [...]
Please don't top-post. It's a bad thing.
> I just come to find the error : there was a blanck just after $motif and I
> did nit see it ! :-)
You're wrong. According to your original post:
my $motif = 'pdf' ;
$nom_fichier_final =~ s/$motif// ;
No extra space there, except one before the semi-colon (which is ugly, by
the way).
Maybe you _didn't_ copy and paste your code? Maybe you rewrote it (and,
by accident, got it right)?
--
Tore Aursand <tore@aursand.no>
"Time only seems to matter when it's running out." (Peter Strup)
------------------------------
Date: Wed, 21 Apr 2004 19:56:04 +0200
From: "fred" <fred@no-spam.fr>
To: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: variable interpolation failed :-(
Message-Id: <pan.2004.04.21.17.56.03.639904@no-spam.fr>
in fact my programm is more complicated : it removes the extension of the
file, it removes the blancs and truncate the file name. It is ugly but it
works ;-)
while (my $nom_fichier = <LISTE>) {
chomp($nom_fichier); # file name
$nom_fichier =~
m/$source_directory\/(.{5,$longueur_maxi_titre_final}).*$/ ; # truncate
the file name
my $nom_fichier_final = $1;
my $motif = '\.pdf' ;
$nom_fichier_final =~ s/$motif// ; # remove PDF
$nom_fichier_final =~ s/ /_/g ; # remove blancs
$nom_fichier_final = "$target_directory"."/$nom_fichier_final"
.".$extension"; # target file name
$nom_fichier =~ s/ /\\ /g ;
print "intitial : $nom_fichier\n";
print "final : $nom_fichier_final\n";
system ("cp $nom_fichier $nom_fichier_final"); # copy the new file
}
> Wouldn't you rather want to use File::Basename instead of a regexp?
>
> jue
------------------------------
Date: 21 Apr 2004 10:02:44 -0700
From: extended@operamail.com (Testor)
Subject: Writing dupliactes to database file
Message-Id: <19789ad6.0404210902.ee68103@posting.google.com>
Hi all,
I posted this message in comp.lang.perl, but someone suggested I post
to this group instead. I wish I could delete the other one I hope
admins will note this.
Anyway, here goes:
I am writing a simple perl script to learn in the process. The script
is supposed to grab a receipt number from the query-string and write
it into a file.
To do that, here's what I did:
$query = new CGI;
$myreceipt = $query->param('bnkreceipt');
open(DATABASE, ">>bnkrecpts.db") or die "Can't write open file.
Reason: $!";
seek(DATABASE,0,2);
print DATABASE "$myreceipt\n";
close(DATABASE);
This works OK though not sure if it's the best way because I'm writing
duplicate receipt numbers. I tried to use an if statement to make sure
is the number exists in the file before writing it but I'm afraid I
wasn't successful I did something like:
open (THERECEIPT, "bnkrecpts.db") or die "Can't open file. Because:
$!";
flock(THERECEIPT,2);
$receiptnum = <THERECEIPT>;
close (THERECEIPT);
if ($receiptnum eq $myreceipt) {
stop and redirect or print something to the page etc..
}
As you can see since I'm still learning, my logic is out of no where
here :-)
Comments on the above code will be appreciated.
------------------------------
Date: Wed, 21 Apr 2004 12:34:20 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Writing dupliactes to database file
Message-Id: <slrnc8dc4s.1lo.tadmc@magna.augustmail.com>
Testor <extended@operamail.com> wrote:
> I posted this message in comp.lang.perl, but someone suggested I post
> to this group instead. I wish I could delete the other one I hope
> admins will note this.
Admins that carry comp.lang.perl have already demonstrated
a low level of conscientiousness, so I wouldn't count on
them noticing. :-(
> open(DATABASE, ">>bnkrecpts.db") or die "Can't write open file.
> Reason: $!";
> seek(DATABASE,0,2);
Why the seek() ?
> This works OK though not sure if it's the best way because I'm writing
> duplicate receipt numbers.
The Perl FAQ should be checked *before* posting to the Perl newsgroup:
perldoc -q duplicate
How can I remove duplicate elements from a list or array?
Adapt the answer given there to your situation.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 21 Apr 2004 15:11:27 GMT
From: Clint Olsen <clint@0lsen.net>
Subject: Re: Writing fast(er) performing parsers in Perl
Message-Id: <slrnc8d3ov.rg7.clint@poly.0lsen.net>
On 2004-04-21, Uri Guttman <uri@stemsystems.com> wrote:
>
> canyou show your benchmarks? and i didn't see (skipped much of the
> thread) your code that does a read() loop. that isn't true slurping and
> it could be faster as it doesn't have to allocate (or reallocate) a very
> large buffer. file slurping is not good for very large files (for some
> definitions of large - today slurping in megabytes is easy, not so too
> long ago).
I can't show you the entire benchmark, since this is a parser for a
proprietary language, but I can show you excerpts:
The fill() function looks like:
#
# $file is an array reference which is the file descriptor, scalar buffer
# for the data, and EOF flag indicator respectively.
#
sub fill {
my ($file) = @_;
my $buf;
$$file[2] = (read($$file[0], $buf, 8192) != 8192);
$$file[1] .= $buf;
}
The loop of the scanner looks like:
sub scan {
...
...
...
for ($$buf[1]) { {
my @src;
if (!$$buf[2] and (!$$buf[1] or length($$buf[1])) < 128) {
fill($buf);
}
#
# Newlines
#
if (s/^( *\n)//o) {
++$$src[1];
$$src[2] = 1;
redo;
}
#
# Whitespace (not newline)
#
if (s/^([ \t]+)//o) {
$$src[2] += length($1);
redo;
}
if (s/^$KEYWORD//o) {
$$src[2] += length($1);
$tok = [ uc($1), [ $1, \@src ] ]
}
elsif (s/^$SYMBOL//o) {
$$src[2] += length($1);
$tok = [ $1, [ $1, \@src ] ]
}
elsif (s/^$STRING//o) {
$$src[2] += length($1) + 2;
$tok = [ 'STRINGCNST', [ $1, \@src ] ];
}
elsif (s/^$INTEGER//o) {
$$src[2] += length($1);
$tok = [ 'INTEGERCNST', [ $1, \@src ] ];
}
elsif (s/^$REAL//o) {
$$src[2] += length($1);
$tok = [ 'REALCNST', [ $1, \@src ] ];
}
elsif (s/^$ID//o) {
$$src[2] += length($1);
$tok = [ 'ID', [ $1, \@src ] ];
}
elsif (s/^(.)//so) {
perror(\@src, "illegal character '$1'\n");
++$$src[2];
redo;
}
}
}
Where $KEYWORD, $SYMBOL, $STRING, $INTEGER, $REAL, and $ID are all
precompiled regular expressions using qr//.
> that is a different beast. when you need to process the entire file, a
> true slurp is faster. sequential reads into a fixed buffer is totally
> different.
Well, you have to consider the Perl overhead of resizing a large buffer
periodically as a result of the substitutions that occur. As you strip off
the leading text, doesn't perl have to move this data around?
-Clint
------------------------------
Date: Wed, 21 Apr 2004 19:17:22 +0200
From: Zimmermann <Zimmermann.David@siemens.com>
Subject: YAML Problem
Message-Id: <c66ab3$p4s$1@news.mch.sbs.de>
hi *,
I would like to serialize a hash,
that keys contain one or more comma's
serialize works fine, but deserialize say: Invalid element in map
someone can help me?
i use YAML-0.35
small example
DB<16> $a = {'a,b' => 1}
DB<17> x $a
0 HASH(0x12f580c)
'a,b' => 1
DB<18> $b = Dump($a)
DB<19> x $b
0 '--- #YAML:1.0
a,b: 1
'
DB<20> $c = Load($b)
--- !perl/YAML::Error
code: YAML_LOAD_ERR_BAD_MAP_ELEMENT
msg: Invalid element in map
line: 2
document: 1
...
thx
David
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 6441
***************************************