[28849] in Perl-Users-Digest
Perl-Users Digest, Issue: 93 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 1 14:06:28 2007
Date: Thu, 1 Feb 2007 11:05:16 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 1 Feb 2007 Volume: 11 Number: 93
Today's topics:
Re: check in mysql DB <DJStunks@gmail.com>
hot string <rocco_milano@yahoo.it>
Re: hot string <wahab-mail@gmx.de>
Re: hot string <bik.mido@tiscalinet.it>
Re: hot string <tadmc@augustmail.com>
Re: HTML:Parser how to remove "//<![CDATA[ ... //]]>" ? <rvtol+news@isolution.nl>
Re: HTML:Parser how to remove "//<![CDATA[ ... //]]>" ? <bik.mido@tiscalinet.it>
Re: Memory leak with XMLRPC and Perl... <scobloke2@infotop.co.uk>
Re: Memory leak with XMLRPC and Perl... xhoster@gmail.com
PAR and Sybase::CTlib on HP-UX <batty.koda@cox.net>
Problem building P5NCI <bol@adv.magwien.gv.at>
problem function length <john.swilting@wanadoo.fr>
Re: problem function length <john.swilting@wanadoo.fr>
Re: problem function length xhoster@gmail.com
Re: problem function length <bik.mido@tiscalinet.it>
Re: problem function length <bik.mido@tiscalinet.it>
sort filename array the same way as windows explorer panofish@gmail.com
Re: sort filename array the same way as windows explore <wahab-mail@gmx.de>
Re: sort filename array the same way as windows explore <mritty@gmail.com>
substitution in perl raj.somla@gmail.com
Re: substitution in perl <wahab-mail@gmx.de>
Re: Tool to execute thousands of commands in parallel <zentara@highstream.net>
Upload file fails <stefan.braun@orca.ch>
Re: Upload file fails <purlgurl@purlgurl.net>
Re: Upload file fails <cwilbur@chromatico.net>
Re: Upload file fails <purlgurl@purlgurl.net>
Re: Upload file fails <bart.lateur@pandora.be>
Re: Upload file fails <bart.lateur@pandora.be>
Re: Upload file fails <noreply@gunnar.cc>
Re: Upload file fails <purlgurl@purlgurl.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 1 Feb 2007 08:48:27 -0800
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: check in mysql DB
Message-Id: <1170348507.610959.151410@v33g2000cwv.googlegroups.com>
On Jan 31, 8:48 pm, "PB0711" <hpben...@gmail.com> wrote:
> Hello all ,
>
> First THX.
Did George Lucas pay you to say that?
> Second I have a program that looks through a file
> extracting data and then puts it into a database. I thought I had
> designed a nice check with the select * from table where name = $name
> and number = $num; . Then I had an if statement to see if that
> reported anything but of course it did cus sql gives the nothing found
> stuff. I know this is pretty easy but I cannot think of a way to do.
> So can someone suggest a way to check if the entry already exist.
define a UNIQUE index and use INSERT IGNORE
-jp
------------------------------
Date: 1 Feb 2007 00:11:44 -0800
From: "kkbyte" <rocco_milano@yahoo.it>
Subject: hot string
Message-Id: <1170317504.400139.205510@p10g2000cwp.googlegroups.com>
Hi all,
I have this problem ...
I have a file with only long string separated by " | " for
example ...
|accrued=0|fee=0|commission=0|change_in_volume=0|
change_in_invested=4494367|change_in_accrued=0|
and I want to've another file so
accrued=0
fee=0
commission=0
change_in_volume=0
change_in_invested=4494367
change_in_accrued=0
Help me!
Tks
------------------------------
Date: Thu, 01 Feb 2007 10:03:36 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: hot string
Message-Id: <epsan4$pdk$1@mlucom4.urz.uni-halle.de>
kkbyte wrote:
> I have a file with only long string separated by " | " for
> example ...
>
> |accrued=0|fee=0|commission=0|change_in_volume=0|
> change_in_invested=4494367|change_in_accrued=0|
>
> and I want to've another file so
>
> accrued=0
> fee=0
> commission=0
> change_in_volume=0
> change_in_invested=4494367
> change_in_accrued=0
Please post some Perl code where you tried that already.
You mean, you have a string like:
my $fromfile = '|accrued=0|fee=0|commission=0|change_in_volume=0'
. '|change_in_invested=4494367|change_in_accrued=0|';
and you need to get the 'fields' between |...|?
You should apply a simple split
my @contents = split /\|/, $fromfile;
after which you may print the extracted contents
in the desired way:
print join "\n", @contents;
To suppress empty lines (coming from empty fields), write:
print join "\n", grep length, @contents;
Regards
M.
------------------------------
Date: Thu, 01 Feb 2007 11:53:31 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: hot string
Message-Id: <mkh3s25dvm04nqjig1pi83vi4p8jdvjr0q@4ax.com>
On 1 Feb 2007 00:11:44 -0800, "kkbyte" <rocco_milano@yahoo.it> wrote:
>I have a file with only long string separated by " | " for
>example ...
>
>|accrued=0|fee=0|commission=0|change_in_volume=0|
>change_in_invested=4494367|change_in_accrued=0|
>
>and I want to've another file so
>
>accrued=0
>fee=0
[snip]
$ perl -F'\|' -lane 'print for @F' file
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Thu, 1 Feb 2007 06:15:03 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: hot string
Message-Id: <slrnes3me7.l8h.tadmc@tadmc30.august.net>
kkbyte <rocco_milano@yahoo.it> wrote:
> I have a file with only long string separated by " | " for
> example ...
>
>|accrued=0|fee=0|commission=0|change_in_volume=0|
> change_in_invested=4494367|change_in_accrued=0|
>
> and I want to've another file so
>
> accrued=0
> fee=0
> commission=0
> change_in_volume=0
> change_in_invested=4494367
> change_in_accrued=0
perl -pe 'tr/|/\n/' a_file >another_file
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 1 Feb 2007 09:45:42 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: HTML:Parser how to remove "//<![CDATA[ ... //]]>" ?
Message-Id: <epsct8.15o.1@news.isolution.nl>
anno4000@radom.zrz.tu-berlin.de schreef:
> Gerwin:
>> Gerwin:
>>> I'm using HTML::Parser to strip HTML tags from my files. I noticed
>>> how //<![cdata[ ... //]]> and the javascript between that is not
>>> stripped. Any idea how to do this?
>>
>> Well i made a regex to do it:
>> $content =~ s/(\/\/<!\[.*\/\/]]>)//;
A different separator makes it more legible:
$content =~ s~(//<!\[.*//]]>)~~;
>> Is this efficient? If not, what is?
>
> Why do you think efficiency matters?
Maybe HTML::Parser already offers a better way.
Or maybe one doesn't always want to remove it, there can be plain text
inside. Or, but that is more about effectiveness, maybe some CDATA
sections are spread over more than one line.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Thu, 01 Feb 2007 11:47:06 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: HTML:Parser how to remove "//<![CDATA[ ... //]]>" ?
Message-Id: <68h3s2lc6f0d7jl6ub95ckqjb49n7rcc32@4ax.com>
On Wed, 31 Jan 2007 23:50:30 -0500, Uri Guttman <uri@stemsystems.com>
wrote:
> s> Use ROBIC0's RxParse, it handles CDATA correctly
>
>you must either be kidding or an alter moron ego of his. his module is
>horrible in too many ways to count.
It sounded like sarcasm to me...
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Thu, 01 Feb 2007 10:40:58 +0000
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: Re: Memory leak with XMLRPC and Perl...
Message-Id: <45c1c3bb$0$27104$db0fefd9@news.zen.co.uk>
findingAri@gmail.com wrote:
> Hello,
> I wrote a program in Perl (using version 5.8.4), that using XMLRPC to
> communicate between the client and the server. The call from the
> client to the server sitting in a infinite loop
When I see "infinite loop" ... alarm bells ring in my head.
> that can be run in random inteval time.
I've no idea what that means but I'll assume you mean it is waiting for
the other end to respond and that the exact time it takes to response is
somewhat unpredictable.
> After sometime that the client is running the perl's proccess taking
> ~70MB of ram and ~100% of the CPU usage.
> May you know why?
Probably because your program is executing a tight "infinite loop".
Usually a crazy way of waiting for an event. There are much better ways
of doing this.
You'd get better help if you posted a SMALL but COMPLETE example, that
people can EASILY run, which reproduces your problem.
------------------------------
Date: 01 Feb 2007 17:10:32 GMT
From: xhoster@gmail.com
Subject: Re: Memory leak with XMLRPC and Perl...
Message-Id: <20070201121250.060$6Z@newsreader.com>
findingAri@gmail.com wrote:
> Hello,
> I wrote a program in Perl (using version 5.8.4), that using XMLRPC to
> communicate between the client and the server. The call from the
> client to the server sitting in a infinite loop that can be run in
> random inteval time.
> After sometime that the client is running the perl's proccess taking
> ~70MB of ram and ~100% of the CPU usage.
Sounds more like a CPU leak than a memory leak.
> May you know why?
Not without seeing some code.
I'd strace it.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 1 Feb 2007 09:35:19 -0800
From: "BaTTy" <batty.koda@cox.net>
Subject: PAR and Sybase::CTlib on HP-UX
Message-Id: <1170351317.379487.305830@k78g2000cwa.googlegroups.com>
OK, here's the deal: I have a perl script that uses Sybase::CTlib
(and Sybase::Simple). I need to deploy it to other machines that
don't have those modules installed. I'm using the PAR Perl Packager
(pp) to do that. The script by itself runs fine on the dev machine,
but when I create a standalone perl script or an exe using pp, it runs
with the following errors (dev machine or other):
test.pl - Standalone perl script using Sybase::CTlib:
Loading 'Sybase::CTlib' (use Sybase::CTlib;) [COLOR="red"]#output from
a BEGIN tag[/COLOR]
Loading 'Sybase::CTlib' (use Sybase::CTlib;) [COLOR="red"]#duplicated
output from a BEGIN tag, only shows once running original perl script[/
COLOR]
Before use Sybase::CTlib; [COLOR="red"]#debug print before use
Sybase::CTlib[/COLOR]
After use Sybase::CTlib; [COLOR="Red"]#debug print after use
Sybase::CTlib[/COLOR]
Out of memory!
Segmentation fault
test.pl - compiled into exe:
Loading 'Sybase::CTlib' (use Sybase::CTlib;)
Can't load '/tmp/par-joeuser/temp-3467/vUojlib6La.sl' for module
Sybase::CTlib: Not enough space at /opt/perl/lib/5.8.2/PA-RISC1.1-
thread-multi/DynaLoader.pm line 229.
at /opt/perl/lib/site_perl/5.8.2/PAR/Heavy.pm line
81[COLOR="red"]#vUojlib6La.sl is actually a copoy of CTlib.sl[/COLOR]
Compilation failed in require at script/test.pl line 43.
BEGIN failed--compilation aborted at script/test.pl line 43.
[COLOR="red"]#Below is output from an END tag[/COLOR]
*********
use Sybase::CTlib; Failed!
*********
Error removing /tmp/par-joeuser/temp-3467/vUojlib6La.sl at /opt/perl/
lib/5.8.2/File/Temp.pm line 852. [COLOR="red"]#separate issue with PAR
not being able to remove temp files, I'm guessing because they have
been loaded into memory and not released.[/COLOR]
testsyb.pl - Standalone perl script using Sybase::Simple:
Can't locate object method "new" via package "Sybase::Simple" at
script/testsyb.pl line 33.
testsyb.pl - compiled into exe:
[COLOR="red"]#pretty much the same as test.pl compiled into exe except
the failure is in the require Sybase::CTlib in Simpl.pm[/COLOR]
Can't load '/tmp/par-joeuser/temp-5006/dNM2lR1pNS.sl' for module
Sybase::CTlib: Not enough space at /opt/perl/lib/5.8.2/PA-RISC1.1-
thread-multi/DynaLoader.pm line 229.
at /opt/perl/lib/site_perl/5.8.2/PAR/Heavy.pm line 81
Compilation failed in require at Sybase/Simple.pm line 19.
BEGIN failed--compilation aborted at Sybase/Simple.pm line 19.
Compilation failed in require at script/testsyb.pl line 13.
BEGIN failed--compilation aborted at script/testsyb.pl line 13.
Error removing /tmp/par-joeuser/temp-5006/dNM2lR1pNS.sl at /opt/perl/
lib/5.8.2/File/Temp.pm line 852.
I have beat this dead horse to death! :D
Any ideas?
P.S. I'm hoping that Michael Peppler runs across this... Michael?
------------------------------
Date: Thu, 1 Feb 2007 09:33:53 +0100
From: "Ferry Bolhar" <bol@adv.magwien.gv.at>
Subject: Problem building P5NCI
Message-Id: <1170318836.546131@proxy.dienste.wien.at>
Hi,
I downloaded P5NCI-0.30 from CPAN and tried to build it.
After extracting and cd to P5NCI-0.30, I tried
$ perl Build.PL
and got this:
Checking whether your kit is complete...
Looks good
Checking prerequisites...
Looks good
Deleting Build
Removed previous script 'Build'
Creating new 'Build' script for 'P5NCI' version '0.30'
$
Next, I entered:
$ Build
and I got this
gcc -I/usr/lib/perl5/5.8.6/i386-linux-thread-multi/CORE -fPIC -c -D_REENTRAN
T
-D_GNU_SOURCE -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm -O2 -g -pipe
-Wp,
-D_FORTIFY_SOURCE=2 -fexceptions -m32 -march=i386 -mtune=pentium4
-fasynchronous-unwind-tables -o src/nci_test.o src/nci_test.c
src/nci_test.c: In function 'make_struct':
src/nci_test.c:64: warning: incompatible implicit declaration of built-in
function 'malloc'
gcc -shared -L/usr/local/lib -o src/nci_test.so src/nci_test.o
Use of uninitialized value in numeric lt (<) at build_lib/P5NCI/Build.pm
line 43.
Copying lib/P5NCI.pm -> blib/lib/P5NCI.pm
Copying lib/P5NCI/Declare.pm -> blib/lib/P5NCI/Declare.pm
Copying lib/P5NCI/Library.pm -> blib/lib/P5NCI/Library.pm
lib/P5NCI.xs -> lib/P5NCI.c
gcc -I/usr/lib/perl5/5.8.6/i386-linux-thread-multi/CORE -DXS_VERSION="0.30"
-DVE
RSION="0.30" -fPIC -c -D_REENTRANT -D_GNU_SOURCE -DDEBUGGING -fno-strict-ali
asin
g -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/u
sr/i
nclude/gdbm -O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -m32 -march=i3
86 -
mtune=pentium4 -fasynchronous-unwind-tables -o lib/P5NCI.o lib/P5NCI.c
Thereafter, the procedure hangs. No errors, but the gcc command never ends.
When using "top", I can see a command "cc1" consuming almost all CPU time
and memory usage continously increases. Looks like an endless loop.
When aborting with ^C, I get
error building lib/P5NCI.o from 'lib/P5NCI.c' at
/usr/lib/perl5/site_perl/5.8.6/
ExtUtils/CBuilder/Base.pm line 108.
$
What's wrong here?
BTW: This is perl 5.8.6 on Linux Fedora 4.
MTIA and kind greetings from Vienna,
Ferry
--
Ing Ferry Bolhar
Magistrat der Stadt Wien - MA 14
A-1010 Wien
E-Mail: bol@adv.magwien.gv.at
------------------------------
Date: Thu, 01 Feb 2007 16:30:38 +0100
From: "john.swilting" <john.swilting@wanadoo.fr>
Subject: problem function length
Message-Id: <45c20788$0$27384$ba4acef3@news.orange.fr>
I recover a file via a form
my $attachement = $cgi->param('attachement');
then
my $oct_long = eval { do {use bytes;length $attachement;};};
and I find myself with the length of characters of the way of the file
whereas I would like to calculate the size of the file
------------------------------
Date: Thu, 01 Feb 2007 16:32:51 +0100
From: "john.swilting" <john.swilting@wanadoo.fr>
Subject: Re: problem function length
Message-Id: <45c2080c$0$27384$ba4acef3@news.orange.fr>
john.swilting wrote:
>
> I recover a file via a form
> my $attachement = $cgi->param('attachement');
>
> then
> my $oct_long = eval { do {use bytes;length $attachement;};};
>
> and I find myself with the length of characters of the way of the file
> whereas I would like to calculate the size of the file
how to make
------------------------------
Date: 01 Feb 2007 17:18:23 GMT
From: xhoster@gmail.com
Subject: Re: problem function length
Message-Id: <20070201122041.581$d8@newsreader.com>
"john.swilting" <john.swilting@wanadoo.fr> wrote:
> I recover a file via a form
> my $attachement = $cgi->param('attachement');
>
> then
> my $oct_long = eval { do {use bytes;length $attachement;};};
>
> and I find myself with the length of characters of the way of the file
> whereas I would like to calculate the size of the file
Do you mean "name of the file" rather than "way of the file"? Is so, that
is exactly what I would expect to happen.
You probably want to us ->upload, not ->param. And then you can either use
"-s" on the filehandle (haven't tried it), or just read it and count its
size.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Thu, 01 Feb 2007 18:55:05 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: problem function length
Message-Id: <8e94s29k71k6g7iuve7isfbdp4p9ikulue@4ax.com>
On Thu, 01 Feb 2007 16:30:38 +0100, "john.swilting"
<john.swilting@wanadoo.fr> wrote:
>I recover a file via a form
>my $attachement = $cgi->param('attachement');
>
>then
>my $oct_long = eval { do {use bytes;length $attachement;};};
Do you really need that? The eval() is unnecessary in any case.
>and I find myself with the length of characters of the way of the file
>whereas I would like to calculate the size of the file
This is to be expected. $attachment is both a file name (whose content
is actually browser dependent) and a filehandle. Since you seem to be
using CGI.pm, you find everything explained quite clearly in its docs
under the "CREATING A FILE UPLOAD FIELD" heading.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Thu, 01 Feb 2007 18:55:27 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: problem function length
Message-Id: <38a4s25kl66bmg5q9kofola66sal893g5f@4ax.com>
On Thu, 01 Feb 2007 16:32:51 +0100, "john.swilting"
<john.swilting@wanadoo.fr> wrote:
>> and I find myself with the length of characters of the way of the file
>> whereas I would like to calculate the size of the file
>
>how to make
perldoc -f -X
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 1 Feb 2007 10:04:06 -0800
From: panofish@gmail.com
Subject: sort filename array the same way as windows explorer
Message-Id: <1170353045.962985.64500@k78g2000cwa.googlegroups.com>
I've searched and searched... I've seen references to sort:naturally
and other, but I do not have enough experience to write a piece of
code that will sort an array the same way that windows explorer sorts
its file list.
Here is my list I want sorted:
AsM-00 (EPC) 20070125 173425.wmf
AsM-01 (EPC) 20070125 173425.wmf
AsM-01-01 (EPC) 20070125 173425.wmf
AsM-01-02 (EPC) 20070125 173425.wmf
AsM-01-03 (EPC) 20070125 173425.wmf
AsM-01-04 (EPC) 20070125 173425.wmf
AsM-01-05 (EPC) 20070125 173425.wmf
AsM-01-06 (EPC) 20070125 173425.wmf
AsM-02 (EPC) 20070125 173425.wmf
CpM-00 (EPC) 20070125 173425.wmf
CpM-01 (EPC) 20070125 173425.wmf
CpM-01-01 (EPC) 20070125 173425.wmf
CpM-01-02 (EPC) 20070125 173425.wmf
The desired sorted result should look the same as it would in windows
explorer like this:
AsM-00 (EPC) 20070125 173425.wmf
AsM-01-01 (EPC) 20070125 173425.wmf
AsM-01-02 (EPC) 20070125 173425.wmf
AsM-01-03 (EPC) 20070125 173425.wmf
AsM-01-04 (EPC) 20070125 173425.wmf
AsM-01-05 (EPC) 20070125 173425.wmf
AsM-01-06 (EPC) 20070125 173425.wmf
AsM-01 (EPC) 20070125 173425.wmf
AsM-02 (EPC) 20070125 173425.wmf
CpM-00 (EPC) 20070125 173425.wmf
CpM-01-01 (EPC) 20070125 173425.wmf
CpM-01-02 (EPC) 20070125 173425.wmf
CpM-01 (EPC) 20070125 173425.wmf
The difference is subtle.
I hope some one can provide a robust, and elegant piece of source code
that can do this sort.
That would be very appreciated.
------------------------------
Date: Thu, 01 Feb 2007 19:21:01 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: sort filename array the same way as windows explorer
Message-Id: <eptdep$654$1@mlucom4.urz.uni-halle.de>
panofish@gmail.com wrote:
> I've searched and searched... I've seen references to sort:naturally
> and other, but I do not have enough experience to write a piece of
> code that will sort an array the same way that windows explorer sorts
> its file list.
>
> AsM-00 (EPC) 20070125 173425.wmf
> AsM-01 (EPC) 20070125 173425.wmf
> AsM-01-01 (EPC) 20070125 173425.wmf
> ...
> The desired sorted result should look the same as it would in windows
> explorer like this:
>
> AsM-00 (EPC) 20070125 173425.wmf
> AsM-01-01 (EPC) 20070125 173425.wmf
> AsM-01-02 (EPC) 20070125 173425.wmf
> ..
Looks like the explorer converts spaces to asc(255)
before sorting strings (guessed).
That would imply sth. like:
...
sub newkey { (my $s=shift) =~ s/\x20+/\xff/; $s }
...
sub explorersort { sort {newkey($a) cmp newkey($b)} @_ }
print explorersort <DATA>
__DATA__
AsM-00 (EPC) 20070125 173425.wmf
AsM-01 (EPC) 20070125 173425.wmf
AsM-01-01 (EPC) 20070125 173425.wmf
AsM-01-02 (EPC) 20070125 173425.wmf
...
if thats too slow (large lists) use sth. like:
...
sub newkey { (my $s=shift) =~ s/\x20+/\xff/; $s }
...
print map $_->[0],
sort {$a->[1] cmp $b->[1]}
map [$_, newkey($_)],
<DATA>
__DATA__
AsM-00 (EPC) 20070125 173425.wmf
AsM-01 (EPC) 20070125 173425.wmf
...
Regards
M.
------------------------------
Date: 1 Feb 2007 11:03:10 -0800
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: sort filename array the same way as windows explorer
Message-Id: <1170356590.231590.169800@s48g2000cws.googlegroups.com>
On Feb 1, 1:04 pm, panof...@gmail.com wrote:
> I've searched and searched... I've seen references to sort:naturally
> and other, but I do not have enough experience to write a piece of
> code that will sort an array the same way that windows explorer sorts
> its file list.
>
> Here is my list I want sorted:
>
> AsM-00 (EPC) 20070125 173425.wmf
> AsM-01 (EPC) 20070125 173425.wmf
> AsM-01-01 (EPC) 20070125 173425.wmf
> AsM-01-02 (EPC) 20070125 173425.wmf
> AsM-01-03 (EPC) 20070125 173425.wmf
> AsM-01-04 (EPC) 20070125 173425.wmf
> AsM-01-05 (EPC) 20070125 173425.wmf
> AsM-01-06 (EPC) 20070125 173425.wmf
> AsM-02 (EPC) 20070125 173425.wmf
> CpM-00 (EPC) 20070125 173425.wmf
> CpM-01 (EPC) 20070125 173425.wmf
> CpM-01-01 (EPC) 20070125 173425.wmf
> CpM-01-02 (EPC) 20070125 173425.wmf
>
> The desired sorted result should look the same as it would in windows
> explorer like this:
>
> AsM-00 (EPC) 20070125 173425.wmf
> AsM-01-01 (EPC) 20070125 173425.wmf
> AsM-01-02 (EPC) 20070125 173425.wmf
> AsM-01-03 (EPC) 20070125 173425.wmf
> AsM-01-04 (EPC) 20070125 173425.wmf
> AsM-01-05 (EPC) 20070125 173425.wmf
> AsM-01-06 (EPC) 20070125 173425.wmf
> AsM-01 (EPC) 20070125 173425.wmf
> AsM-02 (EPC) 20070125 173425.wmf
> CpM-00 (EPC) 20070125 173425.wmf
> CpM-01-01 (EPC) 20070125 173425.wmf
> CpM-01-02 (EPC) 20070125 173425.wmf
> CpM-01 (EPC) 20070125 173425.wmf
>
> The difference is subtle.
> I hope some one can provide a robust, and elegant piece of source code
> that can do this sort.
> That would be very appreciated.
I don't know for a fact that this is true, but it *appears* that
Windows is sorting the filenames as they would be sorted if the non-
alphanumeric characters were not present. If that's true, the
following does the job:
@sorted = map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map { [ $_, do { $t = $_; $t =~ s/[^a-zA-Z0-9]//g;
$t } ] } @files
We're using a Schwartzian Transform to generate a list of all the
files that have the non-alphanumerics removed, and have them
correspond to their originals. Then we sort on the modified version,
and return back the originals.
For more information:
perldoc -f map
perldoc -f sort
Hope this helps,
Paul Lalli
------------------------------
Date: 1 Feb 2007 00:10:55 -0800
From: raj.somla@gmail.com
Subject: substitution in perl
Message-Id: <1170317455.850063.204360@p10g2000cwp.googlegroups.com>
Hi,
I have a string in curly brackets {121,121,121,asa,afr,ssf}. I want
to remove the { and chage it to nothing.
How do I do it?
------------------------------
Date: Thu, 01 Feb 2007 09:28:30 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: substitution in perl
Message-Id: <eps8l8$otg$1@mlucom4.urz.uni-halle.de>
raj.somla@gmail.com wrote:
> Hi,
>
> I have a string in curly brackets {121,121,121,asa,afr,ssf}. I want
> to remove the { and chage it to nothing.
>
> How do I do it?
Please post some Perl code where you tried that already.
You mean, you have a string like:
my $stuff = '{121,121,121,asa,afr,ssf}';
and you need to keep only the content between {...}?
You should apply a simple Regex
$stuff =~ s/[{}]//g;
or just a transliteraton,
$stuff =~ y/{}//d;
Regards
M.
------------------------------
Date: Thu, 01 Feb 2007 07:11:46 -0500
From: zentara <zentara@highstream.net>
Subject: Re: Tool to execute thousands of commands in parallel
Message-Id: <kul3s2pqio0i9s0tochvd113ihgv9739rn@4ax.com>
On Thu, 25 Jan 2007 13:18:52 -0600, Ignoramus26157
<ignoramus26157@NOSPAM.26157.invalid> wrote:
>I am writing some perl scripts right now that execute certain
>commands. Though the scripts work, they take a while each to execute
>and I am consuming a lot of computer time just waiting.
>
>Each command can be either done with perl (using LWP::UserAgent) or in
>shell (using wget). Right now I am using the former.
>
>What I would like to do is to be able to run them in parallel, but no
>more than N at a time. Typical would be 20,000 commands, run no more
>than 4-5 at a time.
>
>So. Is there some sort of an engine, either as a perl module, or a
>standalone execution system, that can be fed with commands and execute
>them in parallel, making sure that the maximum is not exceeded.
>
>One solution is to generate giant makefiles and run make -j 5, but I
>am afraid that make may choke on that many targets.
>
>My perl is perl, v5.8.5 built for i386-linux-thread-multi
>
>Any other solutions? Thanks.
Well, one of the smartest perlmonks ever, named Abigail, posted
these awhile back.
#!/usr/bin/perl
#by Abigail of perlmonks.org
#Some times you have a need to fork of several children, but you want to
#limit the maximum number of children that are alive at one time. Here
#are two little subroutines that might help you, mfork and afork. They
are very similar.
#They take three arguments,
#and differ in the first argument. For mfork, the first
#argument is a number, indicating how many children should be forked.
For
#afork, the first argument is an array - a child will be
#forked for each array element. The second argument indicates the
maximum
#number of children that may be alive at one time. The third argument is
a
#code reference; this is the code that will be executed by the child.
One
#argument will be given to this code fragment; for mfork it will be an
increasing number,
#starting at one. Each next child gets the next number. For afork, the
array element is
#passed. Note that this code will assume no other children will be
spawned,
#and that $SIG {CHLD} hasn't been set to IGNORE.
mfork (10,10,\&hello);
sub hello{print "hello world\n";}
print "all done now\n";
###################################################
sub mfork ($$&) {
my ($count, $max, $code) = @_;
foreach my $c (1 .. $count) {
wait unless $c <= $max;
die "Fork failed: $!\n" unless defined (my $pid = fork);
exit $code -> ($c) unless $pid;
}
1 until -1 == wait;
}
##################################################
sub afork (\@$&) {
my ($data, $max, $code) = @_;
my $c = 0;
foreach my $data (@$data) {
wait unless ++ $c <= $max;
die "Fork failed: $!\n" unless defined (my $pid = fork);
exit $code -> ($data) unless $pid;
}
1 until -1 == wait;
}
#####################################################
__END__
Otherwise, it is recommeded to use the
cpan module Parallel::ForkManager
#!/usr/bin/perl
use warnings;
use strict;
use Parallel::ForkManager;
my @collections = qw (col1 col2 col3 col4 col5);
my $max_tasks = 3;
my $pm = new Parallel::ForkManager($max_tasks);
$|++;
my $start = time();
for my $collection (@collections) {
my $pid = $pm->start and next;
printf "Begin processing $collection at %d secs.....\n", time() -
$start;
sleep rand(10) + 2;
printf ".... $collection done at %d secs!\n", time() - $start;
$pm->finish;
}
__END__
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
------------------------------
Date: Thu, 1 Feb 2007 15:30:48 +0100
From: "Stefan Braun" <stefan.braun@orca.ch>
Subject: Upload file fails
Message-Id: <52ebspF1nv141U1@mid.individual.net>
Hello,
I'm trying to upload files (pictures) from browser to server using a perl
script.
If I run the script under windows/apache it works perfect. If I run the
script under linux/apache I get a empty file.
The relevant part of the script:
my $file = $cgi->param("myfile");
my $fname = 'file_'.$$.'_'.$ENV{REMOTE_ADDR}.'_'.time;
open DAT,'>'.$fname or die 'Error processing file: ',$!;
binmode $file;
binmode DAT;
my $data;
while(read $file,$data,1024) {
print DAT $data;
}
close DAT;
In the errorlog is no entry
Thanks for your ideas
Stefan
------------------------------
Date: Thu, 01 Feb 2007 06:51:06 -0800
From: Purl Gurl <purlgurl@purlgurl.net>
Subject: Re: Upload file fails
Message-Id: <45C1FE5A.3070104@purlgurl.net>
Stefan Braun wrote:
> If I run the script under windows/apache it works perfect. If I run the
> script under linux/apache I get a empty file.
> binmode $file;
> binmode DAT;
Do not use binmode for Unix / Linux systems.
Test and discover if this resolves your problem.
Purl Gurl
------------------------------
Date: 01 Feb 2007 11:14:04 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: Upload file fails
Message-Id: <87veilsvn7.fsf@mithril.chromatico.net>
>>>>> "PG" == Purl Gurl <purlgurl@purlgurl.net> writes:
PG> Do not use binmode for Unix / Linux systems.
From perldoc -f binmode on perl 5.8.8, second and third paragraphs:
On some systems (in general, DOS and Windows-based systems)
binmode() is necessary when you're not working with a text file.
For the sake of portability it is a good idea to always use it
when appropriate, and to never use it when it isn't appropriate.
Also, people can set their I/O to be by default UTF-8 encoded
Unicode, not bytes.
In other words: regardless of platform, use binmode() on binary
data, like for example images.
There's further discussion there, but I assume you can find it and
read it yourself.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Thu, 01 Feb 2007 08:25:55 -0800
From: Purl Gurl <purlgurl@purlgurl.net>
Subject: Re: Upload file fails
Message-Id: <45C21493.4030406@purlgurl.net>
Charlton Wilbur wrote:
> Purl Gurl wrote:
>> Do not use binmode for Unix / Linux systems.
> From perldoc -f binmode on perl 5.8.8, second and third paragraphs:
What version of Perl is the originating author using?
What version of CGI.pm is the originating author using?
You do not know, yes?
Purl Gurl
------------------------------
Date: Thu, 01 Feb 2007 17:06:28 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Upload file fails
Message-Id: <5f74s25eiqga8d66cnbue0gn47vohi93eb@4ax.com>
Purl Gurl wrote:
>> binmode $file;
>> binmode DAT;
>
>Do not use binmode for Unix / Linux systems.
binmode on Unix does nothing. But it doesn't hurt.
>Test and discover if this resolves your problem.
It won't, because binmode is a noop.
--
Bart.
------------------------------
Date: Thu, 01 Feb 2007 17:08:05 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Upload file fails
Message-Id: <mh74s25ej86k2pr1vojdsu2h5hotqp2vaa@4ax.com>
Stefan Braun wrote:
>I'm trying to upload files (pictures) from browser to server using a perl
>script.
>
>If I run the script under windows/apache it works perfect. If I run the
>script under linux/apache I get a empty file.
I think it must be a webserver configuration issue. In other words:
don't blame your script. Once you find the proper webserver
configuration, it'll likely just work.
--
Bart.
------------------------------
Date: Thu, 01 Feb 2007 18:14:42 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Upload file fails
Message-Id: <52elcbF1nutchU1@mid.individual.net>
Stefan Braun wrote:
> I'm trying to upload files (pictures) from browser to server using a perl
> script.
>
> If I run the script under windows/apache it works perfect. If I run the
> script under linux/apache I get a empty file.
Try the CPAN module CGI::UploadEasy. It's not known to have that limitation.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 01 Feb 2007 09:21:49 -0800
From: Purl Gurl <purlgurl@purlgurl.net>
Subject: Re: Upload file fails
Message-Id: <45C221AD.8090509@purlgurl.net>
Bart Lateur wrote:
> Purl Gurl wrote:
>>> binmode $file;
>>> binmode DAT;
>>Do not use binmode for Unix / Linux systems.
> binmode on Unix does nothing. But it doesn't hurt.
>> Test and discover if this resolves your problem.
> It won't, because binmode is a noop.
The originating author is using a Linux system, yes?
What version of Linux?
Is this a dual boot Windows / Linux version?
Is this Linux being run with Windows in the background?
Is the author's system running VM Ware?
Does binmode behave the same for all versions of Perl?
You do not know, yes?
This makes two responses to my article, neither
of which offer any solution for the originating
author. Do you boys have solutions to offer or is
your, plural, only intent to troll?
Most obvious problem is binmode.
Next most obvious problem is file name creation.
In line next is write permission.
Finally, failure of CGI.pm to function correctly with Linux.
I intend to offer step-by-step methods for testing of
this problem, should the originating author elect to
respond to offered solutions.
Your, plural, intent appears simply to troll this newsgroup.
Do consider offering information of value to readers rather
than affording yourselves a chance to troll a person you
are known to dislike.
Purl Gurl
------------------------------
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 V11 Issue 93
*************************************