[29618] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 862 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 18 16:09:46 2007

Date: Tue, 18 Sep 2007 13:09: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           Tue, 18 Sep 2007     Volume: 11 Number: 862

Today's topics:
    Re: $string =~ /$pattern/i <stoupa@practisoft.cz>
    Re: Can perl start another perl script and then exit? <jgibson@mail.arc.nasa.gov>
    Re: Challenge: CPU-optimized byte-wise or-equals (for a <wahab@chemie.uni-halle.de>
    Re: Command line option for split  xlue897@rogers.com
    Re: Command line option for split <bik.mido@tiscalinet.it>
    Re: how to remove duplicate header line in CGI <stoupa@practisoft.cz>
    Re: how to remove duplicate header line in CGI  dmedhora@gmail.com
    Re: how to remove duplicate header line in CGI <benkasminbullock@gmail.com>
    Re: how to remove duplicate header line in CGI <paduille.4061.mumia.w+nospam@earthlink.net>
    Re: how to remove parentheses from a line in a file - n <chris-usenet@roaima.co.uk>
    Re: how to remove parentheses from a line in a file - n <mritty@gmail.com>
    Re: Installing XS Modules on Windows -- Like Pulling Te <thepoet_nospam@arcor.de>
    Re: Newbie question: load data to array <ben@morrow.me.uk>
    Re: Perl data structure to hold same multiple keys and  <ver_amitabh@yahoo.com>
        threads::shared and nested hash <usenet05@drabble.me.uk>
    Re: threads::shared and nested hash <ben@morrow.me.uk>
    Re: Win32::Daemon for 5.8 <rprp@gmx.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 18 Sep 2007 14:32:20 +0200
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: $string =~ /$pattern/i
Message-Id: <fcogp6$gsm$1@ns.felk.cvut.cz>

Tad McClellan wrote:
> Petr Vileta <stoupa@practisoft.cz> wrote:
>> print quotemeta('This is a string');
>>> This\ is\ a\ string
>>
>> By me the space (0x20h) is not need to escape.
>
>
> Errr, then don't call quotemeta on it!

This was be an example. In real script I mean something like
my $variable = myfunction(quotemeta($ARGV[0]));

where myfunction() need to get escaped string as parameter but escaped space 
is nonsese.
Now I realise it as
my $arg = quotemeta($ARGV[0]);
$arg =~ s/\\\x20/ /g;
my $variable = myfunction($arg);

Know you better way?
-- 

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail 
from another non-spammer site please.)






------------------------------

Date: Tue, 18 Sep 2007 09:55:30 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Can perl start another perl script and then exit?
Message-Id: <180920070955301424%jgibson@mail.arc.nasa.gov>

In article <1190069053.257334.95610@r29g2000hsg.googlegroups.com>, Bill
H <bill@ts1000.us> wrote:

> I need to have a perl script start another script and then exit,
> returning completed header information to a web page. The other
> program will continue running on the server processing some pdf files,
> and when done it will set a flag.
> 
> The web page, once it initiates the 1st program (which starts the
> background program) and receive the status from the 1st program (using
> flash) will then start a 3rd program, which checks for the "done
> flag", if it isn't set it will tell the web page (flash) to try again.
> This will continue to the 2nd program is complete.
> 
> So, can I start a 2nd script in perl and have the 1st program exit
> without effecting the 2nd program? System() would just wait, Exec()
> would start the 2nd and leave the 1st behind.

I do pretty much what you describe in one application. The idea is to
fork the process, return a web page immediately to the client, and use
"client-pull" to monitor the progress of the long child process.

I used the technique described here:

http://www.stonehenge.com/merlyn/LinuxMag/col39.html

-- 
Jim Gibson

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


------------------------------

Date: Tue, 18 Sep 2007 17:47:14 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: Challenge: CPU-optimized byte-wise or-equals (for a meter of beer)
Message-Id: <fcoru1$j6r$1@nserver.hrz.tu-freiberg.de>

Michele Dondi wrote:
> I have two very long (>64k) strings of equal lengths - $s1 and $s2.
> They are strings of bytes, meaning that any value from chr(0) to
> chr(255) is legal. $s2, however, will not have any chr(0). $s1 may or
> may not have any. What I need to do is look at each byte in $s1 and if
> it is chr(0), replace it with the corresponding byte in $s2. So,
> something like the following code:

I looked over the entries, there are some
XS and some inline, but the obvious one
didn't show up. So I created *it*.

I started with the msvc/win32 thingy (works
perfectly for Activeperl w/MSVC installed)
but will eventually produce the gcc/as/unix
variant.

The gnu style seems to be (for me) somehow
complicated (the intel syntax isn't). So
thats the first part. You can't have it
much faster:

(simple test case added)==>


use Inline C => qq{
// ==>
  void wahab_msvc(SV* s, SV* d)
{
  STRLEN srclen, dstlen;
  char *src = SvPV(SvRV(s), srclen), *dst = SvPV(SvRV(d), dstlen);
  if( srclen < dstlen ) croak("block length mismatch!");
  _asm     mov   edi, dst
  _asm     mov   esi, src
  _asm     mov   ecx, dstlen
  _asm     xor   eax, eax
   start:
  _asm     repne scasb
  _asm     jne   done
  _asm     mov   edx, dstlen
  _asm     sub   edx, ecx
  _asm     mov   ah, byte ptr [-1+esi+edx]
  _asm     mov   byte ptr [-1+edi], ah
  _asm     jmp   start
     done: ;
}
// <==
};

my $s1 = 'abcdefghijklmn';
my $s2 = 'abcdefghijklmn';

substr($s2,5,1) = "\x0";

wahab_msvc(\$s1, \$s2);

print "\n$s1\n$s2\n";
<==



Any help (gnu style) much appreciated!

M.


------------------------------

Date: Tue, 18 Sep 2007 07:41:53 -0700
From:  xlue897@rogers.com
Subject: Re: Command line option for split
Message-Id: <1190126513.736673.87080@57g2000hsv.googlegroups.com>

On Sep 17, 3:01 pm, Michele Dondi <bik.m...@tiscalinet.it> wrote:
> On Mon, 17 Sep 2007 10:32:41 -0700, xlue...@rogers.com wrote:
> >Can we specify the [limit] option for split in command line? For perl
> >code, we can do things like
>
> No, I don't really think so.
>
> Michele

If there are fields with trailing empty fields, Perl cannot get the
correct number of fields using command line options.  So Perl is not
convenient and accurate in getting fields numbers with command line
options. And we should avoid using command line options to try to get
fields number.



------------------------------

Date: Tue, 18 Sep 2007 18:09:22 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Command line option for split
Message-Id: <pttve3ljgf3i918hgigj5halpc0ob2g0or@4ax.com>

On Tue, 18 Sep 2007 07:41:53 -0700, xlue897@rogers.com wrote:

>If there are fields with trailing empty fields, Perl cannot get the
>correct number of fields using command line options.  So Perl is not
>convenient and accurate in getting fields numbers with command line
>options. And we should avoid using command line options to try to get
>fields number.

It seems sensible and reasonable: after all command line options are
there for small tasks and not to solve all the problems that one may
face in Perl. In fact they would be better adopted for relatively
small scripts. In longer ones, adding a pair of lines for an explicit
loop or a split() makes things easier to follow and doesn't hurt much.


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: Tue, 18 Sep 2007 03:00:57 +0200
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: how to remove duplicate header line in CGI
Message-Id: <fcofi2$g1j$1@ns.felk.cvut.cz>

dmedhora@gmail.com wrote:
> Hi,
> When I write a CGI script in perl I seem to get this line printed out
> TWICE !
>
> Content-Type: text/html; charset=iso-8859-1
>
> It also shows up in the web browser as the first line, when I execute
> the same from my cgi-bin
> dir.
>
> Any idea how I may get rid of this duplication ? It could be causing
> problems while
> I debug and run my programs..
>
Maybe this can be a problem in web server configuration. If your server is 
configured to "auto-send" this header line then you need not to send the 
same from your script. But better is reconfigure server to "auto-send" no 
headers and generate all headers in your scripts.
-- 

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail 
from another non-spammer site please.)





------------------------------

Date: Tue, 18 Sep 2007 06:24:37 -0700
From:  dmedhora@gmail.com
Subject: Re: how to remove duplicate header line in CGI
Message-Id: <1190121877.112717.141430@r29g2000hsg.googlegroups.com>

On Sep 17, 9:25 pm, dmedh...@gmail.com wrote:
> Hi,
> When I write a CGI script in perl I seem to get this line printed out
> TWICE !
>
> Content-Type: text/html; charset=iso-8859-1
>
> It also shows up in the web browser as the first line, when I execute
> the same from my cgi-bin
> dir.
>
> Any idea how I may get rid of this duplication ? It could be causing
> problems while
> I debug and run my programs..
>
> Thanks:)

Hi and Thanks for your posts, Well, to add more details to this
It happens only when I use CGI::FormBuilder
So, if I use CGI.pm there is no duplication but if I use
CGI::FormBuilder then I get that duplicate.
Here is some code :)
==========================================================
#!/usr/bin/perl

use CGI::FormBuilder;

my @fields = qw(category task status notes);

my $form = CGI::FormBuilder->new(
             method => 'post',
             fields => \@fields,
             validate => {
                status => 'INT',    # validate
             },
             required => 'ALL',
        );

if ($form->submitted)
{
    print $form->confirm(header => 1);
} else {
    print $form->render(header => 1);
}
=========================================================

Note, since I got this problem I've dumped FormBuilder and
settled for plain CGI.pm instead.



------------------------------

Date: Tue, 18 Sep 2007 13:40:55 +0000 (UTC)
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: how to remove duplicate header line in CGI
Message-Id: <fcokh7$d3$1@ml.accsnet.ne.jp>

On Tue, 18 Sep 2007 06:24:37 -0700, dmedhora wrote:

> Hi and Thanks for your posts, Well, to add more details to this
> It happens only when I use CGI::FormBuilder
> So, if I use CGI.pm there is no duplication but if I use
> CGI::FormBuilder then I get that duplicate.

I ran the script you supplied, but I only got the offending message once.


------------------------------

Date: Tue, 18 Sep 2007 10:41:28 -0500
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: how to remove duplicate header line in CGI
Message-Id: <13evt8v4f6jao50@corp.supernews.com>

On 09/18/2007 08:40 AM, Ben Bullock wrote:
> On Tue, 18 Sep 2007 06:24:37 -0700, dmedhora wrote:
> 
>> Hi and Thanks for your posts, Well, to add more details to this
>> It happens only when I use CGI::FormBuilder
>> So, if I use CGI.pm there is no duplication but if I use
>> CGI::FormBuilder then I get that duplicate.
> 
> I ran the script you supplied, but I only got the offending message once.

Same here.



------------------------------

Date: Tue, 18 Sep 2007 14:23:44 +0100
From: Chris Davies <chris-usenet@roaima.co.uk>
Subject: Re: how to remove parentheses from a line in a file - need help!
Message-Id: <0405s4xu4q.ln2@news.roaima.co.uk>

pauls <pauls@nospam.off> wrote:
> I am reading-in  the file in using $_ and I tried to do the following 
> (without success):

> s/)//g;
> s/)//g;

This has already been answered by others, but what's puzzling me is that
over here on perl 5.8.8 this triggers an appropriate error message:

  $ perl -e 's/(//' 
  Unmatched ( in regex; marked by <-- HERE in m/( <-- HERE / at -e line 1.

Yet pauls doesn't allude to this at all. Is this message a relatively
new feature?

Cheers
Chris


------------------------------

Date: Tue, 18 Sep 2007 07:14:46 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: how to remove parentheses from a line in a file - need help!
Message-Id: <1190124886.058632.25440@n39g2000hsh.googlegroups.com>

On Sep 18, 9:23 am, Chris Davies <chris-use...@roaima.co.uk> wrote:
> pauls <pa...@nospam.off> wrote:
> > I am reading-in  the file in using $_ and I tried to do the
> > following (without success):
> > s/)//g;
> > s/)//g;
>
> This has already been answered by others, but what's puzzling me
> is that over here on perl 5.8.8 this triggers an appropriate error
> message:
>
>   $ perl -e 's/(//'
>   Unmatched ( in regex; marked by <-- HERE in m/( <-- HERE / at
>   -e line 1.
>
> Yet pauls doesn't allude to this at all.

pauls's descriptions of the error were: "I tried to do the following
(without success):"  and "Why do both of these attempts fail?".  He
never indicated whether that failure was incorrect results or syntax
errors.  I'm 95% willing to bet he got the same syntax error you did,
but didn't think it was worth mentioning.

Paul Lalli



------------------------------

Date: Tue, 18 Sep 2007 21:07:18 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Installing XS Modules on Windows -- Like Pulling Teeth
Message-Id: <46f0218a$0$30382$9b4e6d93@newsspool4.arcor-online.net>

Michele Dondi wrote:
> On Mon, 17 Sep 2007 11:42:00 +0100, Ben Morrow <ben@morrow.me.uk>
> wrote:
[concerning ppm repositories]
>> Given the number of questions that come up with this answer, do you
>> suppose ActiveState could be persuaded to include them by default? I
>> guess they don't want support requests for things they cannot support...
> 
> Well, pehaps they should. After all, they would still include their
> own repository as the first one.

They're almost doing it. Just tried

ppm install PPM-Repositories
ppm repo suggest

Seems like all the well-known third party repositories are there,

-Chris


------------------------------

Date: Tue, 18 Sep 2007 14:29:04 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Newbie question: load data to array
Message-Id: <0e05s4-s73.ln1@osiris.mauzo.dyndns.org>


Quoth Tad McClellan <tadmc@seesig.invalid>:
> Ben Morrow <ben@morrow.me.uk> wrote:
> > Quoth Martijn Lievaart <m@rtij.nl.invlalid>:
> 
> >> close $fh;
> >
> > If you're not going to check the return value of close there's no need
> > (with a lexical FH) to call it.
> 
> There's no need if the FH was opened for input.
> 
> If, however, it was opened for output, then an explicit close() is
> a pretty good idea, even when you don't check its return value.
> 
> If you like to see others in pain, then check out my tale of woe:
> 
>    http://groups.google.com/group/comp.lang.perl.misc/msg/73d4587743c64e2f

Yes, but that's about using global filehandles, which are only closed
when you re-open them. Lexical filehandles are explicitly closed by perl
at the point where they go out of scope, so don't cause that problem
(as, indeed, Anno pointed out in that thread... :) ).

Ben



------------------------------

Date: Tue, 18 Sep 2007 03:55:48 -0700
From:  Ami <ver_amitabh@yahoo.com>
Subject: Re: Perl data structure to hold same multiple keys and different values
Message-Id: <1190112948.914815.199310@w3g2000hsg.googlegroups.com>

On Sep 17, 4:25 pm, kens <kenslate...@hotmail.com> wrote:
> On Sep 17, 6:42 am, Ami <ver_amit...@yahoo.com> wrote:
>
> > may be i am not clear with my question so once again:
> > I need a hash kind of data structure where I can store multiple values/
> > objects with same key value. I need to create a group on base of same
> > key. Associated values/objects will be processed on the base of groups
> > created.
> > Any help is appreciated.
> > Thanks
>
> Hello. It sounds like you may want a hash of arrays. I have a simple
> example below. See if this is something close to what you want.
>
> use strict;
> use warnings;
>
> my %hashOfArrays;
>
> foreach my $friend ( 'James', 'John', 'etc' )
> {
>    push @{$hashOfArrays{'Ami'}}, $friend;
>
> }
>
> foreach my $name ( sort keys %hashOfArrays )
> {
>    print "$name\'s friends:\n";
>    foreach my $friend ( @{$hashOfArrays{$name}} )
>    {
>       print "   $friend\n";
>    }
>
> }
>
> Each element of the array could be a reference to an object if so
> desired.
>
> HTH, Ken

Hi Ken,
   Many thanks for your help and example code. It is exactly same what
i wanted.
Thanks again,
-Ami



------------------------------

Date: Tue, 18 Sep 2007 14:31:41 +0100
From: Graham Drabble <usenet05@drabble.me.uk>
Subject: threads::shared and nested hash
Message-Id: <Xns99AF93CA1BB89grahamdrabblelineone@ID-77355.user.dfncis.de>

Hi,

I have a list of IP addresses in @nes. I need to create a hash in 
%alarms where the keys are the IP addresses and the values are a hash 
with keys being an event and value the severity.

I have done this as follows

use strict;
use warnings;

my @nes = ('172.18.0.1','172.18.0.2');

my %alarms;

foreach my $ne (@nes){
        $alarms{$ne}{'Disconnected'} = 5;
        $alarms{$ne}{'LOS.1'} = 3;
        check_colour($ne);
}

I am now trying to use this in a threaded environment and need %
alarms to be shared. I have tried

use strict;
use warnings;
use threads;
use threads::shared;

my @nes = ('172.18.0.1','172.18.0.2');

my %alarms : shared;

foreach my $ne (@nes){
        $alarms{$ne}{'Disconnected'} = 5;
        $alarms{$ne}{'LOS.1'} = 3;
        check_colour($ne);
}

This says that "Invalid value for shared scalar at ems.pl line 11". I 
guess I need to use &share({}) somewhere but I can't see how.

-- 
Graham Drabble
http://www.drabble.me.uk/


------------------------------

Date: Tue, 18 Sep 2007 16:09:54 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: threads::shared and nested hash
Message-Id: <2b65s4-ak41.ln1@osiris.mauzo.dyndns.org>


Quoth Graham Drabble <usenet05@drabble.me.uk>:
> Hi,
> 
> I have a list of IP addresses in @nes. I need to create a hash in 
> %alarms where the keys are the IP addresses and the values are a hash 
> with keys being an event and value the severity.
<snip>
> 
> I am now trying to use this in a threaded environment and need %
> alarms to be shared. I have tried
> 
> use strict;
> use warnings;
> use threads;
> use threads::shared;
> 
> my @nes = ('172.18.0.1','172.18.0.2');
> 
> my %alarms : shared;
> 
> foreach my $ne (@nes){
>         $alarms{$ne}{'Disconnected'} = 5;
>         $alarms{$ne}{'LOS.1'} = 3;
>         check_colour($ne);
> }
> 
> This says that "Invalid value for shared scalar at ems.pl line 11". I 
> guess I need to use &share({}) somewhere but I can't see how.

Autoviv (the automatic creation of intermediate hashes/arrays whenever
you use them) on a shared hash doesn't work. Given that this bug is
mentioned in the perldoc, I guess it's rather hard to fix. You need to
explicitly create and share the intermediate hashes:

    foreach my $ne (@nes) {
        $alarms{$ne} = &share({});
        $alarms{$ne}{'Disconnected'} = 5;
        $alarms{$ne}{'LOS.1'} = 3;
        check_colour($ne);
    }

Hmmm, that &share({}) is really smelly, in the perldoc or no... I'd
probably rather write it as

    foreach my $ne (@nes) {
        my %ne : shared;

        $ne{'Disconnected'} = 5;
        $ne{'LOS.1'} = 3;

        $alarms{$ne} = \%ne;
        check_colour($ne);
    }

which is arguably cleaner anyway.

Ben



------------------------------

Date: Tue, 18 Sep 2007 16:35:59 +0200
From: Reinhard Pagitsch <rprp@gmx.net>
To: Ferry Bolhar <bol@adv.magwien.gv.at>
Subject: Re: Win32::Daemon for 5.8
Message-Id: <46EFE24F.30803@gmx.net>

Hello Ferry,

Ferry Bolhar wrote:
> Hi to all,
> 
> I want to run a perl script as a Win32 service. Someone
> pointed my to Win32::Daemon
> 
> http://www.roth.net/perl/Daemon/
> 
> and it looks like the one I was looking for.
> 
> Unfortunately, the binary kits are for Perl 5.005 and 5.6
> only. I would need a version for 5.8. Perhaps someone
> can tell me where I can get this version from?
> 
> Many thanks and kind greetings,

If you want I can send you a Perl5.8 compiled daemon.dll per Mail, but 
without any warranties that it work. The source code is very old (from 
2002), I had also to change some settings in the source code.

Write me at the mail address in the signature.

regards,
Reinhard

-- 
PM Mails an rpirpag <at> gmx dot at


------------------------------

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 862
**************************************


home help back first fref pref prev next nref lref last post