[21721] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3925 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 6 14:07:19 2002

Date: Sun, 6 Oct 2002 11:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 6 Oct 2002     Volume: 10 Number: 3925

Today's topics:
        ANNOUNCE: CGI::Echo <ron@savage.net.au>
        ANNOUNCE: DBIx::HTML::PopupRadio <ron@savage.net.au>
        ANNOUNCE: Module::MakeDist V 1.00 <ron@savage.net.au>
    Re: converting a string into an array <marek@analizy.pl>
        Dealing with database problems gracefully? <ReplyToGroup@thanks.com>
    Re: File upload form question. (Alan Barclay)
    Re: File upload form question. (mike)
        Get file version in Win32 <Avi_Uziel@BMC.com>
        Help! How do you move one html page to another in Perl? (Zordiac)
    Re: Help! How do you move one html page to another in P <ReplyToGroup@thanks.com>
    Re: Help! How do you move one html page to another in P <jeff@vpservices.com>
        How Can I Read a Single Line at a Time from an Open Fil <play.ball@usa.net>
        How to find array element  index efficently <d.adamkiewicz@i7.com.pl>
    Re: Installing Perl Modules: What actually happens? (Peter Scott)
        Is this a bug in perl? (Michael McLagan)
    Re: Is this a bug in perl? (Walter Roberson)
    Re: ithreads, perl 5.8 and shared objects <derek@wedgetail.com>
    Re: matching an unknown pattern. (Doggy)
    Re: merging 2 strings (Jeff Mott)
    Re: regex o modifier <roy@panix.com>
    Re: What does [^\n] mean <No_Mail_Address@cox.net>
    Re: What does [^\n] mean <No_Mail_Address@cox.net>
    Re: What does [^\n] mean (Tad McClellan)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 6 Oct 2002 10:37:33 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: ANNOUNCE: CGI::Echo
Message-Id: <3da076b3$1_4@news.teranews.com>

CGI::Echo is a pure Perl module.

Here is an extract from the README file:

NAME
    "CGI::Echo" - Echo form data to test form design.

Synopsis
    This is complete, tested program:

            #!/usr/bin/perl -wT

            use lib '.';
            use strict;

            use CGI;
            use CGI::Echo;

            # -----------------------------------------------

            my($q) = CGI -> new();

            CGI::Echo -> new(q => $q) -> print();

Description
    This module accepts form data, cleans it, and echos it.

    It is designed for a HTML/CGI student enviroment. It lets, indeed
    encourages, students to design forms and gives their long-suffering
    instructors a simple way to provide a CGI script which accepts the form
    data, and just echos it.

Distributions
    This module is available both as a Unix-style distro (*.tgz) and an
    ActiveState-style distro (*.ppd). The latter is shipped in a *.zip file.

    See http://savage.net.au/Perl-modules/html/installing-a-module.html for
    help on unpacking and installing each type of distro.

--
Cheers
Ron Savage
ron@savage.net.au
http://savage.net.au/index.html





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

Date: Sun, 6 Oct 2002 10:36:32 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: ANNOUNCE: DBIx::HTML::PopupRadio
Message-Id: <3da076cc$1_6@news.teranews.com>

DBIx::HTML::PopupRadio is a pure Perl module.

Here is an extract from the README file:

NAME
    "DBIx::HTML::PopupRadio" - Convert sql into a popup menu or radio group.

Synopsis
            use DBIx::HTML::PopupRadio;

            my($popup_object) = DBIx::HTML::PopupRadio -> new
            (
                    dbh => $dbh,
                    sql => 'select campus_id, campus_name from campus order by campus_name',
            );

            $popup_object -> set(default => '1');

            my($popup_menu)  = $popup_object -> popup_menu();
            my($radio_group) = $popup_object -> radio_group();

            print $popup_menu;

Description
    This module takes a db handle and an SQL statement, and builds a hash.

    Then you ask for that hash in HTML, as a popup menu or as a radio group.

    The reading of the db table is delayed until you actually call one of
    the methods 'popup_menu' or 'radio_group'. Even then, it is delayed
    until any parameters passed in to these 2 methods are processed.

    After a call to one of these 2 methods, you can call the 'size' method
    if you need to check how many rows were returned by the SQL you used.

    Neither the module CGI.pm, nor any of that kidney, are used by this
    module. We simply output pure HTML.

Distributions
    This module is available both as a Unix-style distro (*.tgz) and an
    ActiveState-style distro (*.ppd). The latter is shipped in a *.zip file.

    See http://savage.net.au/Perl-modules/html/installing-a-module.html for
    help on unpacking and installing each type of distro.

--
Cheers
Ron Savage
ron@savage.net.au
http://savage.net.au/index.html





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

Date: Sun, 6 Oct 2002 10:34:53 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: ANNOUNCE: Module::MakeDist V 1.00
Message-Id: <3da076e1$1_1@news.teranews.com>

Module::MakeDist is a pure Perl module.

Here is an extract from the README file:

NAME
    "Module::MakeDist" - Create Unix and ActiveState distros for a new
    module.

Synopsis
            use Module::MakeDist;

            # Work in /perl-modules/Module-MakeDist-1.00/.

            Module::MakeDist -> new
            (
                    name            => 'Module::MakeDist',
                    verbose         => 0,
                    version         => '1.00',
                    work_dir        => '/perl-modules',
            );

Description
    Say we have a new module, KillerApp V 1.00, and in it's directory
    KillerApp-1.00/ are these files:

    *   KillerApp.pm

    *   Makefile.PL

    *   Other files, such as test.pl, t/*.t, examples/*

    Then this module processes the directory KillerApp-1.00/, and generates
    all files required to create shippable distributions (distros) in both
    Unix-style and ActiveState-style (ppm) formats.

    Files created are:

    *   MANIFEST

    *   README

        We run pod2text on KillerApp.pm to create README.

    *   KillerApp.html

        We run pod2html on KillerApp.pm to create KillerApp.html.

        The fancy *.html docs on my web site are output by fancy-pom2.pl,
        which is available elsewhere on my web site.

    *   KillerApp-1.00.tgz

        The Unix-style distro.

        This can be uploaded to CPAN.

    *   KillerApp.ppd

        This can be input to ppm.

    *   x86/KillerApp-1.00.tar.gz

        This is a copy of KillerApp-1.00.tgz. The last time I tested it, ppm
        choked on a file called *.tgz.

    *   KillerApp-1.00.zip

        The ActiveState ppm-style distro. This file contains KillerApp.ppd,
        README, KillerApp.html and x86/KillerApp-1.00.tar.gz.

    We do not use any external programs such as tar, gzip or zip.

Distributions
    This module is available both as a Unix-style distro (*.tgz) and an
    ActiveState-style distro (*.ppd). The latter is shipped in a *.zip file.

    See http://savage.net.au/Perl-modules/html/installing-a-module.html for
    help on unpacking and installing each type of distro.


--
Cheers
Ron Savage
ron@savage.net.au
http://savage.net.au/index.html





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

Date: Sun, 6 Oct 2002 15:24:21 +0000 (UTC)
From: marek <marek@analizy.pl>
Subject: Re: converting a string into an array
Message-Id: <anpkj5$6ov$1@news2.tpi.pl>

Vivek <vgtek@yahoo.com> wrote:
> Hi,

> I was wondering how do you turn a string into an array?
> For example take a string $string="ABCDE" and make it an array so that
> you can work with each character separately, so that
> $s[0]=A....$s[1]=B....and so on.
> Thanks.  --Vivek

you can also use 'map' with 'unpack':

my @arr = map { chr } unpack("C*", $string);



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

Date: Sun, 6 Oct 2002 13:39:44 +0100
From: "Simon Harvey" <ReplyToGroup@thanks.com>
Subject: Dealing with database problems gracefully?
Message-Id: <iaWn9.3609$Fv2.284616@wards>

Hi all,

I'm doing aproject on behald of my students union. We have a database that
we dont actually control but has kndly been provided by the university
itself.

The downside of that is that we will never know if it is going offline. This
led me onto the question of dealing with errors more genrally in perl, on
which there seems to be very little external comment or documentation. The
official docs are there and are very good (as always) for people who are
good at perl already (not really me), but what would help would be a
discussion of the features and perhaps a faq and tutorial. Something that
newbies can get into. I sent this request to the perl faqs suggestions page
but it doesnt seem that responsive as I know a few people also sent ina
similar request.

Anyway, sorry about the rant. I do actaully have a question. I know a little
bit about eval and was wondering if I should put my database related calls
(such as making the initial connection and executing statements etc) within
eval blocks?

Someone told me that this was a bad idea before but then how else do i make
the application robust? Its not that big a program but because it is
actually being deployed in a real world enviroment it absolutely must have
error control.

Another guy told me that evel was exctly what I should use so now I'm all
confused!

Does anyone have any thoughts or advise about anything above? Does anyone
have the idea of the perl faq guys?

I really think there should be an "Error Handling in Perl" faq (or pehaps
just a section within a faq). Anything would be better than nothing

Kind thanks to all who share their thoughts (and maybe even help me!! :))

Take Care
Simon




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

Date: 6 Oct 2002 11:16:36 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: File upload form question.
Message-Id: <1033903103.713864@elaine.furryape.com>

In article <5e1e1a55.0210060019.21cefd6f@posting.google.com>,
mike <mike@swaylocks.com> wrote:
>Hi,
>
>Working in Perl I have a form that allows people to modify their
>database records if they choose. I'm having the file upload form field
>prepopulated from a database as follows:
>
> <input name="File1" type="FILE" value="<%File1%>"
>
>Unfortunately when the form is submitted the value gets lost. The same
>form, if populated with a new file using the browse feature, the value
>gets passed just fine.
>
>Anybody know why this is happening and if there is any way around it?

This is really an HTML issue.

If there is a way to do it, it will be the same regardless of
which language you use, so you should be in
comp.infosystems.www.authoring.html

However, I think the answer is you can't. For security reasons the
user must enter the filename to be uploaded.


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

Date: 6 Oct 2002 10:07:03 -0700
From: mike@swaylocks.com (mike)
Subject: Re: File upload form question.
Message-Id: <5e1e1a55.0210060907.2e0b6c47@posting.google.com>

Sorry for my hasty question.  I answered it myself.  It's funny --
answering questions is often more an excercise in coming up with the
right key words to search with.

If you search this forum for "File upload default vaulue" 

http://groups.google.com/groups?hl=en&lr=&ie=ISO-8859-1&q=file+upload+default+value

You will quickly discover that you cannot set the default value of a
file upload field.

duh.

Mike


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

Date: Sun, 6 Oct 2002 18:05:55 +0300
From: "Avi Uziel" <Avi_Uziel@BMC.com>
Subject: Get file version in Win32
Message-Id: <uq0k9hg3076ca@corp.supernews.com>

What it the perl equivalent to M$ GetVertionInfo?

thanks,
Avi




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

Date: 6 Oct 2002 09:33:45 -0700
From: zordiac@hotmail.com (Zordiac)
Subject: Help! How do you move one html page to another in Perl?
Message-Id: <7744b29b.0210060833.3b627e63@posting.google.com>

Newbie question - please help!

I have a Perl script that generates and displays
a html page which accepts input.

After a user has input some data I want my Perl script
to then display another html page. 

But what is the best way of moving to another html page?
I thought I would do this in my Perl script but it is not
obvious how. Use POST and read variables passed back to the
script ie have some sort of conditional script start?

There must be a standard way of doing this but...arrghh!...
I cannot see any examples anywhere.


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

Date: Sun, 6 Oct 2002 18:25:17 +0100
From: "Simon Harvey" <ReplyToGroup@thanks.com>
Subject: Re: Help! How do you move one html page to another in Perl?
Message-Id: <_l_n9.3649$Fv2.293178@wards>

I there,

I'm new to this perl game as well but if you are taking in user input then
you must want to process that input by a second script?

The chain of events right from the very begining will be:

1. As you said you have: a perl script generates a html page.
2. The html has a form in it for taking the user data. A simple form might
be:

<form name="myform" method="post" action="/cgi-bin/inputCheckingScript.pl">
  <p>Name:
    <input name="txtName" type="text" id="txtName">
  </p>
  <p>
    <input type="submit" name="Submit" value="Submit">
  </p>
</form>

3. When the botton is pressed the scrip at ="/cgi-bin/inputCheckingScript.pl
will be run and you can give it the information from txtName


So I think what you are after is to understand that when you have perl
output the html of a form, the form element has to have its "action"
attribute set to the perl script that will do some interesting stuff with
your form data.

Maybe I completetly misunderstood! Does that help any?

Simon




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

Date: Sun, 06 Oct 2002 10:08:18 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Help! How do you move one html page to another in Perl?
Message-Id: <3DA06E02.6070705@vpservices.com>

Zordiac wrote:

> But what is the best way of moving to another html page?
> I thought I would do this in my Perl script but it is not
> obvious how. Use POST and read variables passed back to the
> script ie have some sort of conditional script start?


Yes.


> There must be a standard way of doing this 


It's called CGI.pm.  See the docs for it.

> but...arrghh!...
> I cannot see any examples anywhere.


   #!perl -Tw
   $|=1;
   use strict;
   use CGI qw(:standard);
   use CGI::Carp qw(fatalsToBrowser);
   print header,start_html('Test Multi-Invocation');
   if ( !param ) {
       print start_form,
             "What's your name? ",textfield('name'),
             submit,end_form;
   }
   else {
       print "Thanks! Your name is: ",param('name');
   }
   print end_html;
   __END__

-- 
Jeff



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

Date: Sun, 6 Oct 2002 13:30:38 -0500
From: "Jim" <play.ball@usa.net>
Subject: How Can I Read a Single Line at a Time from an Open File?
Message-Id: <WmadnQjqruoD5T2gXTWcow@News.GigaNews.Com>

This may be simple but I am struggling. I am parsing through a file and once
I match a single pattern. I want to process the following lines individually
until I reach another pattern.

I am looking for something like a read statement except it will read the
entire line.

Any help would be appreciated,

Jim




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

Date: Sun, 06 Oct 2002 19:20:12 +0200
From: Darek Adamkiewicz <d.adamkiewicz@i7.com.pl>
Subject: How to find array element  index efficently
Message-Id: <anpqqg$9n$1@news.tpi.pl>

Hello folks
The following subroutine works for me but it's terribly slow
- but it has some flexibility I'd like to retain:
sub k2i {
	my ($keys, $args) = @_;
	my %conv = ();
	@conv{ @$keys } = (0..$#{$keys});
	return wantarray ? @conv{@$args} : $conv{$args->[0]};	
}

Regards
Darek



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

Date: Sun, 06 Oct 2002 14:44:08 GMT
From: peter@PSDT.com (Peter Scott)
Subject: Re: Installing Perl Modules: What actually happens?
Message-Id: <Y_Xn9.463155$v53.20337486@news3.calgary.shaw.ca>

In article <f677762.0210060145.2db09334@posting.google.com>,
 david@tvis.co.uk (david rayner) writes:
>Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net> wrote in message news:<slrnapqq38.142.bernard.el-hagin@gdndev25.lido-tech>...
>> In article <f677762.0210040205.7ccec0e6@posting.google.com>, david rayner wrote:
>> > Obviously it's easiest when PPM does a install for you.
>> > Occasionally however you are asked to do the following
>> > 
>> >>perl makefile.pl
>> >>make
>> >>make test
>> >>make install
>> > 
>> > But my real question is what is actually happenning, what is being
>> > compiled/installed etc?
>> 
>> Look in the makefile. It's all in there.
>
>Just did, sorry it's double dutch. What I'd like to is the principles

(1) "perl Makefile.PL" - turn a short, platform-independent
configuration file into a Makefile that works on your system for your
perl.  (cf "imake" if you're familiar with that.)  Perl knows about
all the specifics of your perl installation (like where binaries go,
how to compile C code, etc) through its Config module.  All the module
developer has to do is fill out a usually simple Makefile.PL which
covers just the things that are specific to this distribution.  But
they can include arbitrarily complex Perl if necessary.

(2) "make" - this is your system running its make command on the
Makefile generated in (1).  N.B.: If you have a system that includes a
make command and utilities it depends on, you should be able to use
CPAN.pm to make these steps as simple as PPM; a module install can be
just "perl -MCPAN -e 'install Foo'".

(3) "make test" - your system runs its make command on the Makefile
and finds the "test" target to run the tests the module developer
thoughtfully included to let you know whether it's working alright.
CPAN.pm won't let a module install if it fails its tests (unless you
force it to).

(4) "make install" - runs make command on "install" target which
copies files from the current location to the place where perl expects
to find them, i.e., somewhere under @INC.

-- 
Peter Scott
http://www.perldebugged.com


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

Date: 6 Oct 2002 09:55:24 -0700
From: mmclagan@invweb.net (Michael McLagan)
Subject: Is this a bug in perl?
Message-Id: <84964d56.0210060855.5ea7509@posting.google.com>

Hello,

   I got a very unexpected result using 5.6.1 on a RH Linux system. 
Specifically, I tried:

   0xFFFFFFFF >> 32

Intuitively, I should have gotten 0.  What I got was 0xFFFFFFFF (-1)!

[mmclagan]$ perl -e 'for ($i=0;$i < 33;$i++) {print sprintf("%02i:
%08X", $i, 0+0xFFFFFFFF >> $i) . "\n";}'

00: FFFFFFFF
01: 7FFFFFFF
02: 3FFFFFFF
03: 1FFFFFFF
04: 0FFFFFFF
05: 07FFFFFF
06: 03FFFFFF
07: 01FFFFFF
08: 00FFFFFF
09: 007FFFFF
10: 003FFFFF
11: 001FFFFF
12: 000FFFFF
13: 0007FFFF
14: 0003FFFF
15: 0001FFFF
16: 0000FFFF
17: 00007FFF
18: 00003FFF
19: 00001FFF
20: 00000FFF
21: 000007FF
22: 000003FF
23: 000001FF
24: 000000FF
25: 0000007F
26: 0000003F
27: 0000001F
28: 0000000F
29: 00000007
30: 00000003
31: 00000001  << -- so far so good!
32: FFFFFFFF  << -- WTF ?  

Please forgive me if this is a FAQ somewhere, I did a Google search
and didn't find anything pertinent.

   Michael


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

Date: 6 Oct 2002 17:09:14 GMT
From: roberson@ibd.nrc.ca (Walter Roberson)
Subject: Re: Is this a bug in perl?
Message-Id: <anpqnq$fqt$1@canopus.cc.umanitoba.ca>

In article <84964d56.0210060855.5ea7509@posting.google.com>,
Michael McLagan <mmclagan@invweb.net> wrote:
:   I got a very unexpected result using 5.6.1 on a RH Linux system. 
:Specifically, I tried:

:   0xFFFFFFFF >> 32

:Intuitively, I should have gotten 0.  What I got was 0xFFFFFFFF (-1)!

0xFFFFFFFF is a signed number. Shifting a signed number moves a '1'
bit in at the top. If want 0's to be shifted in instead, you will
have to force the number to be unsigned.
--
Cannot open .signature: Permission denied


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

Date: Sun, 06 Oct 2002 21:40:43 +1000
From: Derek Thomson <derek@wedgetail.com>
Subject: Re: ithreads, perl 5.8 and shared objects
Message-Id: <3da0215a$0$23168$afc38c87@news.optusnet.com.au>

Benjamin Goldberg wrote:
> Derek Thomson wrote:
> 
>>Uri Guttman wrote:
> 
> [snip]
> 
>>>and what do you mean by the server calling itself directly or
>>>indirectly?
>>
>>Let's say a client calls method 'foo' on object 'A' in one process.
>>Method 'foo' now calls method 'bar' on object 'B' in another process.
>>As part of the execution of method 'bar', method A.fubar is called. As
>>A.foo is already being handled in A's process, we have a deadlock
>>situation.
> 
> 
> Not necessarily... Look at it like this... suppose when the first
> process does:
> 
>    my $result = $B->bar(@args);
> 
> It really does:
>    my $result;
>    send_message( $B, "bar", \@args );
>    RPCLOOP: {
>       my $event = get_next_event();
> 
>       # ->fubar, in this process, will be called from here:
>       $event->dispatch(), redo RPCLOOP
>          if $event->type() ne "response";
> 
>       $result = $event->data();
>    }
> 
> Note that while waiting for a response, it is *not* waiting *only* for a
> response to $B->bar, but it is also dispatching other requests, too!

Yes, I believe that's what I'd call "reactive". Somewhere in the 
dispatch, you'll probably call "select", unless of course you want your 
process to busy-wait, but that's your choice ;)

> 
> 
>>The trivial (direct) case is when A.foo calls A.fubar directly, but
>>that can be avoided by having the ORB (or whatever infrastructure)
>>skip the message dispatch by detecting that it's a local call. That's
>>impossible, however, in the indirect case described above.
> 
> 
> Even if it's not smart enough to skip the message dispatch, there
> shouldn't be a deadlock, if the message dispatching is done as I show
> above.

I think we're agreeing violently.

> 
> 
>>>with message passing that is less than trivial, you just
>>>send a message to yourself (or whatever). as for exploiting
>>>parallelism the above mentioned project partly on a 4 way cpu and it
>>>uses processes and message passing to get parallelism. in fact when
>>>we added that feature, the time for a multiple query search went
>>>down by factor that was almost linear with the number of parallel
>>>processes running. the key to parallel processing is the IPC and
>>>message passing can be simpler and cleaner than threads and locks.
>>>also it is more scalable as the same architecture can be spread to
>>>multiple boxes with no new coding and threads can't do that at all.
>>
>>I don't really understand most of that, as I'm not familiar with this
>>project the you're talking about. Speaky generically, you have two
>>choices if you want to get useful work done while blocking on I/O 1)
>>You use threading, or 2) You make the I/O handler part of the event
>>loop.
>>
>>2) Is harder to get right,
> 
> 
> Isn't it nice that people have already written code with the I/O
> handling built into the event loop?

Yes, but people don't want to wait for you to integrate their blocking 
resource access with the event loop. An advantage with threads is that 
you get decent scheduling for free, with zero effort.

You can disagree if you like, but the vast majority of the world is 
using threads for *some* reason.

>>However, I can't see how you avoid locking - with events you just
>>force everything to be serialized, therefore you've lost any potential
>>parallelism.
> 
> 
> Well, all serialized within the one process, but you can have multiple
> processes, which you talk to through I/O.

Yes, that's what I said. But the access to the resource *must* be 
serialized. Locking by any other name ...

> 
>>I respectfully question this "real parallel scalability" assertion. I
>>think you're being just a teensy bit zealot-ish here.
> 
> 
> He's the president of "Stem Systems", whose main product, stem, is a
> message passing system.  What would you expect?

<blows top>
That does it.

I don't go researching everyone who replies ... and frankly I'll 
definitely check next time to see if I'm replying to a marketing droid 
with a hidden agenda. I asked a technical question about ithreads, and I 
got some reflexive offtopic nonsense about "switching" to a random 
message passing system.

I clearly said I was building an ORB (ie infrastructure), that will help 
Perl play in the CORBA/J2EE space, so "switching" makes no god damned 
sense whatsoever.

(*) My long term goal is to enable EJBs not just to be used from Perl, 
but implemented in it as well. Like it or not, this is necessary and 
important for Perl in the medium term. It's not exactly glamorous, all 
this bit fiddling on the wire, and getting object models exactly right, 
and I don't get to use many buzzwords, but I really think it's 
important. I just need to find more time :(

And what about those programming tasks that have nothing to do with IPC 
or servers, but are simply expressed more elegantly with threads? Can 
those people use Perl? I *was* trying to find out.

Aaargh! Next time someone asks a question about Perl regexes, I'll be 
sure to answer with "don't know, but here's how you do it in Java 
strings, and coincidentally here's my product", and next time someone 
asks about OO, I'll answer, "We didn't need that OO stuff in the '70s. 
And BTW, have you considered 'gotos' instead of those silly structured 
loops?"

Do you see that that's very fucking irritating?! And boring. And lame. 
People should read posts after matching marketing regexes against them, 
and before replying.
</blows top>

> 
> 
>>I'm sure I can do just as well with a threaded server, and you can't
>>*really* avoid race conditions (and locking) unless you throw
>>parallelism out.
> 
> 
> If you use multiprogramming instead of multithreading, any one process
> is purely serial.
> 
> One can avoid deadlocks due to recursion simply by changing RPC of the
> form: "send request and wait for *my* response, and *only* my response"
> into: "send message and wait for *any* messages, dispatching those which
> are requests, until one of those messages is my response"

Yes, that's the "reactive" single threaded pattern. There's plenty 
written about it. It's beaut!

> 
> Other forms of race conditions/deadlocks may still require work, but you
> could create a centralized process which hands out locks, or something
> like that.

Yes. Locking. *Thank you*.

> 
> 
>>I don't see how your model as described can really exploit multiple
>>CPUs,
> 
> 
> Take those components which don't interact nicely into an event
> dispatching model by themselves (DBI, for example), and put them into
> their own processes (and talk to them via RPC/messages).  The OS will
> likely run those processes on the other CPUs.

Sure, if you can afford all these processes, and the overhead of 
communications between them.

> 
> 
>>without exchanging more messages between seperate processes,
> 
> 
> The way I see it, you send one message per request, and get one message
> per response.  Where do you see the extra messages?

[So, there's a response now? I thought we didn't need those troublesome 
responses ...]

Who co-ordinates all this scheduling, and deciding who gets what 
message? Unless it's random, or round-robin, there's going to be some 
overhead in determining who is most lightly loaded, I would have 
thought. This is further up the protocol stack than CORBA though, and 
people run into the same problems building on top of an ORB ...

> 
> 
>>which is certainly a little inelegant.
> 
> 
> It's only inelegant if it's visible to the user.

Agreed.

> 
> 
>>Sure, it probably works in specific cases, but I'm writing an ORB, so
>>I can't be telling people how they should be using it - I just have to
>>give them all the options: that is, threads *and* event loops.
>>
>>I'm starting with threads, as that's what people expect, it's easier
>>to get started with, and damnit, I want to show that it *works* in
>>Perl!
> 
> 
> Perl's threads work, but they are *not* lightweight things.
> 
> The idea of creating a short-lived thread which does a single task, then
> exits, is only a good one if the cost of creating a thread is low.
> 

That's why you would create a thread pool up front, which is what I plan 
to do.

Now I'm going to play some computer games, and let the steam blow out of 
my ears for a bit!

--
Derek Thomson.



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

Date: 6 Oct 2002 05:39:55 -0700
From: tru64dog@yahoo.com (Doggy)
Subject: Re: matching an unknown pattern.
Message-Id: <18239c3a.0210060439.1b6b2840@posting.google.com>

Vespasian <VES@VES.NET> wrote in message news:<aZ6fPdR+=ihrsaTIMVdd89DXfknD@4ax.com>...
> On 5 Oct 2002 15:33:05 -0700, tru64dog@yahoo.com (Doggy) wrote:
> 
> >Is this possible in perl.
> >
> >I would like match more than 5 instances of a one line pattern in a
> >file. Lets say for instance, in a file called data.txt, if a pattern
> >of "dog bite" appears more than 5 times to let me know. But remember,
> >I don't type in the pattern, the objective is PERL to find 5 or more
> >instances of an exact pattern w/o me telling what pattern to look for?
> >
> >TIA
> >
> >Rod
> 
> I don't think you can do the above for a phrase "dog bite", however, I
> thik you can do it for single words, such as "dog" or "bite";

I think Ves understands what I want Perl to do for me, and I apologize
to the others that didn't understand my question. I'll rephrase better
next time.

Ves's suggestion is where I want to go but I need to match phrases,
not a single word.
> 
> my %hash;
> open(IN, "data.txt");
> while(<IN>) {
> 	while(/(\w+)/g) { 
> 		if(++$hash{$1} >= 5) { do_whatever; }
> 	}
> }
> close(IN);


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

Date: 6 Oct 2002 08:35:06 -0700
From: jeffmott@twcny.rr.com (Jeff Mott)
Subject: Re: merging 2 strings
Message-Id: <f9c0ce19.0210060735.2806e67@posting.google.com>

> I'll try to explain what I want a little better. I am encrypting user
> information via the ENCODE() method in MySQL. This is for a website I
> am creating that is powered by mod_perl, thus I am looking for a
> solution in Perl. The ENCODE() method takes a key as an argument which
> is used to encrypt data. The problem is that the encryption is easily
> broken by studying multiple user records. This can be solved by
> encrypting each record with a different key.

It would be far simpler if you used a block cipher instead, which will
allow you to securely encrypt multiple records with the same key. So
this way you would only need one key. Good choices for block ciphers
are 3DES and Rijndael (aka AES) both of which are available as modules
at CPAN.

> One solution I was contemplating was using the userid to change the
> ASCII characters in the static key. Since each ASCII character has a
> numeric value, I could increase the ASCII value of each character in
> the key by the integer value in the userid. Of course I would reach an
> upper limit, so I suppose I would need to wrap around to the beginning
> once I got to the last ASCII character. However, this would be rather
> difficult to code and would be slow. I was hoping someone here could
> suggest a better solution.

$newchar = chr((ord($char1) + ord($char2)) % 256);

Although a block cipher is your best choice, if you choose to use your
current method anyway the best way to merge the two strings are to
just concatenate them and then hash them (you can use SHA1, also
available at CPAN). Otherwise with methods such as adding the
characters values, concatenating, or XORing if just one key becomes
known to some other user they can retrieve the key for every other
user. This is not so if you use the hashing function as a method of
merging.


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

Date: Sun, 06 Oct 2002 13:21:16 -0400
From: Roy Smith <roy@panix.com>
Subject: Re: regex o modifier
Message-Id: <roy-71FAAE.13211606102002@reader1.panix.com>

I've got a code fragment that looks like:

    foreach $filter (@filters) {
        if ($message =~ m/$filter/) {
            return;
        }
     }

Because a different regex is used each time through the loop, I pay for 
a regex compile every time, and the /o flag won't help me.  Is there any 
way to optimize this so all the regexes get compiled once, and saved?

I'm not meaning to start a language war here, but in Python, I would do 
something like:

# Pre-compile all the regexes once
compiledFilters = []
for filter in filters:
    compiledFilters.append (re.compile (filter))

[...]

# Use the compiled versions each time through the main loop
for cf in compiledFilters:
   if cf.search (message):
      return

Is there anything similar in Perl?

I realize I could build one huge composite regex by pasting all the 
individual ones together with "|", but I can't do that.  The individual 
regexes will be arbitrary strings read from an external source, and 
stuff like \1 would break.


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

Date: Sun, 06 Oct 2002 14:11:45 GMT
From: Fred <No_Mail_Address@cox.net>
Subject: Re: What does [^\n] mean
Message-Id: <3DA044C3.2536749D@cox.net>

"John W. Krahn" wrote:
> 
> Fred wrote:
> >
> > Tad McClellan wrote:
> > >
> > > Fred <No_Mail_Address@cox.net> wrote:
> > >
> > > > Also I thought that with $/ = undef;
> > > > all \n are removed.
> > >
> > > What made you think that?
> > >
> > > Did you read it somewhere?
> >
> > When I run the following code, the resulting file is one single line,
> > with one single line break at the very end...:
> 
> That is because _your_ code removes the newlines (and carriage returns
> and form feeds and tabs.)
> 
> > open(IN, '<C:\aa\inbox') or die "Cannot open IN: $! \n";
> > open(OUT, '>C:\aa\RawList.txt')  or die "Cannot open OUT: $! \n";
> >
> > $/ = undef;
> >
> > while(<IN>){
> 
> The file is read into the $_ variable with each line ending with \n.
> 
> >         s/\s+/ /g ;
> 
> The \s+ regular expression matches all " ", "\t", "\n", "\r" and "\f"
> characters and replaces them with a " " character.
> 
> >         print OUT $_, "\n";
> > }
> >
> > close(OUT)      or die "could not close OUT: $!";
> > close(IN)       or die "could not close IN: $!";
> 
> John
> --

Oh - that explains a lot. The books say "\s match a white space
character", and for me that was space and tab. I was not aware that
this is only true when using the default input record separator. 
--
Fred


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

Date: Sun, 06 Oct 2002 14:31:10 GMT
From: Fred <No_Mail_Address@cox.net>
Subject: Re: What does [^\n] mean
Message-Id: <3DA04950.A97F3B96@cox.net>



"Tassilo v. Parseval" wrote:
> 
> Also sprach Fred:
> 
> > "John W. Krahn" wrote:
> 
> >> [^\n]+ means to match one or more characters that is not a newline
> >> character which is the same as .+ when the /s option is not used.  The
> >> substitution operator appears to be removing Received lines from e-mail
> >> headers which can span more than one physical line.  The capturing
> >> parentheses aren't required if that is all it is doing.
> >>
> >>         s/^Received:\s.+\n(?:\s+.+\n)*//mg;
> >>
> > Yes, the result is exactly the same with your much shorter code. What
> > I dont understand is the role of the (?: - the CSPAN manual calls it
> > "non-backreffing grouping paren" - but what does that actually mean?
> 
> Round parens store anything they matched for later use in the variables
> $1, $2, etc. $1 holds what the first pair of parens captured, $2 store
> the match of the second pair of parens etc. When being inside a regex,
> there is the non-variable equivalent \1, \2, ... that can be used to
> match something previously matched again:
> 
> 
>     "abcdab" =~ /(..).*\1/
> 
> matches, because the parens match 'ab', any sequence of characters and
> then they find another occurance of the first match 'ab'.
> 
> Yet, if you use ?: the parens are only used for grouping, that is,
> nothing is stored in $1 or \1 respectively. The above received-pattern
> works just as fine with capturing-parens but since it is of no interest
> what those matches were, you can tell Perl to use non-backreffing
> parens. This will save a few bytes of memory and copying the match into
> a variable. Hence, your regex will be more performant.
> 
> Tassilo
> --

That is a very clear and understandable explanation, thank you, and I
have copied it into my Perl Programmers Reference Guide, Chapter
Regular Expressions, Section (?: pattern).

--
Fred


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

Date: Sun, 6 Oct 2002 09:51:39 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: What does [^\n] mean
Message-Id: <slrnaq0jfr.bq3.tadmc@magna.augustmail.com>

Fred <No_Mail_Address@cox.net> wrote:
> "John W. Krahn" wrote:
>> Fred wrote:
>> > Tad McClellan wrote:
>> > > Fred <No_Mail_Address@cox.net> wrote:
>> > >
>> > > > Also I thought that with $/ = undef;
>> > > > all \n are removed.
>> > >
>> > > What made you think that?

>> > When I run the following code, the resulting file is one single line,

>> That is because _your_ code removes the newlines (and carriage returns
>> and form feeds and tabs.)


>> > $/ = undef;
>> >
>> > while(<IN>){
>> 
>> The file is read into the $_ variable with each line ending with \n.


And, since it reads the whole file in one go, there is no need
to put it in a loop. The loop will always execute one time anyway.


>> >         s/\s+/ /g ;
>> 
>> The \s+ regular expression matches all " ", "\t", "\n", "\r" and "\f"
>> characters and replaces them with a " " character.


> Oh - that explains a lot. The books say "\s match a white space
> character", and for me that was space and tab. 


and now you know that \s is any of 5 characters.


> I was not aware that
> this is only true when using the default input record separator. 


Good, because this is NOT only true when using the default 
input record separator.    :-)

\s always matches those characters, the value of $/ never alters that.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 3925
***************************************


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