[23079] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5300 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 31 18:06:08 2003

Date: Thu, 31 Jul 2003 15:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 31 Jul 2003     Volume: 10 Number: 5300

Today's topics:
    Re: <input type='image'>  ...  IE fails to pass value w (Tad McClellan)
    Re: <input type='image'>  ...  IE fails to pass value w (Tad McClellan)
        Command or script to get a list of email addresses <deboo@example.com>
    Re: Command or script to get a list of email addresses <clay@panix.com>
    Re: Command or script to get a list of email addresses <biff_the_gorilla_killa@blueyonder.co.uk>
    Re: error validation question <flavell@mail.cern.ch>
    Re: error validation question (Julia Briggs)
    Re: error validation question <uri@stemsystems.com>
    Re: error validation question <noreply@gunnar.cc>
    Re: error validation question <usenet@dwall.fastmail.fm>
    Re: error validation question (Tad McClellan)
        File+Data from Java to Perl & back again. (SOAP?) (Tim M)
    Re: how to know the week of today? <cpryce@pryce.nospam.net>
    Re: how to know the week of today? (JR)
    Re: how to know the week of today? <emschwar@ldl.fc.hp.com>
    Re: how to know the week of today? <cpryce@pryce.nospam.net>
    Re: pod2usage verbose problem (Sam Denton)
    Re: pod2usage verbose problem (Sam Denton)
    Re: regular expression question <bigj@kamelfreund.de>
    Re: semaphore example needed (Greg Bacon)
    Re: Sorting question <trammell+usenet@hypersloth.invalid>
    Re: splicing two arrays <uri@stemsystems.com>
    Re: splicing two arrays <usenet@dwall.fastmail.fm>
    Re: splicing two arrays <grazz@pobox.com>
    Re: splicing two arrays (Greg Bacon)
    Re: splicing two arrays <uri@stemsystems.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 31 Jul 2003 15:14:22 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: <input type='image'>  ...  IE fails to pass value while Mozilla and Netsacpe works
Message-Id: <slrnbiiu4u.1pn.tadmc@magna.augustmail.com>

John Everett <john_k_everett@hotmail.com> wrote:
> Newsgroup...
> 
>   Thanks for the insight and the abuse.
>   Made me feel all warm and fuzzy inside.
>   
>   This news group is full of Perl CGI questions.
>   Seemed like a wise place to post.
>   Suppose not.
> 
>   I strongly suggust that this group becomes a 
>   moderated group before someone has a heart attack ;-)


It is self-moderated.

People post what they want to post, some get good responses, others don't.

People choose which articles they'll read, and which they'll never see.

I'm going to do that one right now!

   *plonk*


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


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

Date: Thu, 31 Jul 2003 15:27:48 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: <input type='image'>  ...  IE fails to pass value while Mozilla and Netsacpe works
Message-Id: <slrnbiiuu4.1pn.tadmc@magna.augustmail.com>

John Everett <john_k_everett@hotmail.com> wrote:


>   This news group is full of Perl CGI questions.
>   Seemed like a wise place to post.


That ditch is full of trash.

Seemed like a wise place to dump.


   "If everyone jumped off of a bridge, would you jump too?"  [1]


   "... looking for another place to put the garbage.  We didn't 
    find one. Until we came to a side road, and off the side of 
    the side road there was another fifteen foot cliff and at 
    the bottom of the cliff there was another pile of garbage. 
    And we decided that one big pile is better than two little 
    piles, and rather than bring that one up we decided to 
    throw our's down." [2]



[1] Mom

[2] "Alice's Restaurant", Arlo Guthrie

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


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

Date: 31 Jul 2003 18:27:52 GMT
From: Deboo <deboo@example.com>
Subject: Command or script to get a list of email addresses
Message-Id: <bgbn37$n4g7d$1@ID-164288.news.uni-berlin.de>


I have quite many irc chat logs and in many of these, there are email
addresses of friends they haf given me during those chats. Can someone
help me make a perl script or tell me the command which would extract
these email addresses from these text files ( and may be also mbox files)
and also irradicate duplicates and put them in a list form in to a text
file?

I tried using grep but then there are some duplicates too and finding
and removing them would be a big hassle.

Thanks,
Deboo


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

Date: Thu, 31 Jul 2003 19:28:27 +0000 (UTC)
From: Clay Irving <clay@panix.com>
Subject: Re: Command or script to get a list of email addresses
Message-Id: <slrnbiirer.f64.clay@panix1.panix.com>

In article <bgbn37$n4g7d$1@ID-164288.news.uni-berlin.de>, Deboo wrote:

> I have quite many irc chat logs and in many of these, there are email
> addresses of friends they haf given me during those chats. Can someone
> help me make a perl script or tell me the command which would extract
> these email addresses from these text files ( and may be also mbox files)
> and also irradicate duplicates and put them in a list form in to a text
> file?
> 
> I tried using grep but then there are some duplicates too and finding
> and removing them would be a big hassle.

Email::Find

  NAME
      Email::Find - Find RFC 822 email addresses in plain text
  
  SYNOPSIS
        use Email::Find;
  
        # new object oriented interface
        my $finder = Email::Find->new(\&callback);
        my $num_found - $finder->find(\$text);
  
        # good old functional style
        $num_found = find_emails($text, \&callback);
  
  DESCRIPTION
      Email::Find is a module for finding a *subset* of RFC 822 email
      addresses in arbitrary text (see the section on "CAVEATS"). The
      addresses it finds are not guaranteed to exist or even actually be email
      addresses at all (see the section on "CAVEATS"), but they will be valid
      RFC 822 syntax.
  
      Email::Find will perform some heuristics to avoid some of the more
      obvious red herrings and false addresses, but there's only so much which
      can be done without a human.
[...]

-- 
Clay Irving <clay@panix.com>


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

Date: Thu, 31 Jul 2003 22:46:17 +0100
From: "biff_the_gorilla_killa" <biff_the_gorilla_killa@blueyonder.co.uk>
Subject: Re: Command or script to get a list of email addresses
Message-Id: <u6gWa.250$7q1.43@news-binary.blueyonder.co.uk>

You could just pipe what grep outputted into the Unix "sort" command with
the -u option set.

This will sort your email address list and also remove duplicates.

Cheers

Biff
"Deboo" <deboo@example.com> wrote in message
news:bgbn37$n4g7d$1@ID-164288.news.uni-berlin.de...
>
> I have quite many irc chat logs and in many of these, there are email
> addresses of friends they haf given me during those chats. Can someone
> help me make a perl script or tell me the command which would extract
> these email addresses from these text files ( and may be also mbox files)
> and also irradicate duplicates and put them in a list form in to a text
> file?
>
> I tried using grep but then there are some duplicates too and finding
> and removing them would be a big hassle.
>
> Thanks,
> Deboo




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

Date: Thu, 31 Jul 2003 20:24:56 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: error validation question
Message-Id: <Pine.LNX.4.53.0307312008080.670@lxplus009.cern.ch>

On Thu, Jul 31, Peter Stokes inscribed on the eternal scroll:

> Ignore the sarcasm from others, Julia - they know not what they do.

And your usenet record speaks for itself, doesn't it?

> think I know what you're getting at -  have a look at formmail.pl in
> Matt's Script Archive - http://www.scriptarchive.com/

If I had a dollar for every piece of spam that's been delivered (or
rather, attempted to be delivered - the antispam defences are fairly
good these days) courtesy of that piece of nonsense, I'd be a rich
man.  There are even mail relay blocking lists dedicated to it.

Nobody really minds a newcomer turning up and seeming confused, as
long as they're asking a reasonable question.  But there's a special
place reserved in the Tomb of the Unknown Programmer for folks who
turn up without much of a clue and offer dreadful answers to naive
questions, especially when they are so bold as to contradict those who
much better.  Guess what I think I just saw happening here?

-- 
                        "This is not rocket surgery"  - Stan Brown


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

Date: 31 Jul 2003 12:20:15 -0700
From: julia4_me@yahoo.com (Julia Briggs)
Subject: Re: error validation question
Message-Id: <c48f65ef.0307311120.112cd79c@posting.google.com>

Omission of the word 'Perl' in the contruction of my question in this
forum shouldn't automatically mean it was an HTML only question - now
does it?  Zowie!  It's like a bunch of conditioned crickets jumping
all over the place around here!


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

Date: Thu, 31 Jul 2003 19:26:09 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: error validation question
Message-Id: <x7d6fqzeem.fsf@mail.sysarch.com>

>>>>> "JB" == Julia Briggs <julia4_me@yahoo.com> writes:

  JB> Omission of the word 'Perl' in the contruction of my question in this
  JB> forum shouldn't automatically mean it was an HTML only question - now
  JB> does it?  Zowie!  It's like a bunch of conditioned crickets jumping
  JB> all over the place around here!

no, it means people here understand the difference between a language
related problem and a language independent problem. if the same question
and answer could be made while changing the language, it is not a perl
problem. this is the issue, newbies can't logically distinguish perl
problems from hmtl/web problems. and this is a perl newsgroup where we
discuss perl stuff, not pure web stuff.

and there are plenty of threads here which discuss web AND perl. but
they use perl specific things such as LWP or html::parser or other such
stuff. whereas what javascript or html to create is not a perl problem
as any language can print the same text.

so take the advice you wer given and use matt's scripts. we can only
wish you the best on your site as it gets cracked and hijacked for spam.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Thu, 31 Jul 2003 21:46:01 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: error validation question
Message-Id: <bgbrtm$mrk60$1@ID-184292.news.uni-berlin.de>

web wrote:
> In article <c48f65ef.0307310002.7bdc598e@posting.google.com>,
> julia4 _me@yahoo.com says...
> 
>> What is the cleanest and easiest way to produce on screen
>> (no-popup) error validations for forms?
> 
> I think the best way is to show the form once again with the data
> that the user filled in, print an error message above the form and
>  additionally mark the fields that contain the incorrect values.
> It's not an easiest way but it's the best one in my opinion. The
> user will see the error message and will be able to correct the
> data in the form.

I agree on that. If you click the link in my sig, and click the "Send"
button without filling the form completely, you find a Perl example of
that technique. The form is created by a CPAN module that I wrote:
http://search.cpan.org/author/GUNNAR/CGI-ContactForm-1.14/

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Thu, 31 Jul 2003 20:23:09 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: error validation question
Message-Id: <Xns93C9A6B028F4Bdkwwashere@216.168.3.30>

Alan J. Flavell <flavell@mail.cern.ch> wrote:

> On Thu, Jul 31, Peter Stokes inscribed on the eternal scroll:
> 
>> think I know what you're getting at -  have a look at formmail.pl
>> in Matt's Script Archive - http://www.scriptarchive.com/
> 
> If I had a dollar for every piece of spam that's been delivered
> (or rather, attempted to be delivered - the antispam defences are
> fairly good these days) courtesy of that piece of nonsense, I'd be
> a rich man.  There are even mail relay blocking lists dedicated to
> it. 

The web hosting company I use won't even *allow* the execution of a CGI 
program named formmail.pl even if it's not Matt's program.  (and I have 
no problem with that at all)  Even though there is no program by that 
name in my cgi-bin, that doesn't mean I don't get several attempts per 
day to exploit it.

-- 
David Wall


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

Date: Thu, 31 Jul 2003 15:09:33 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: error validation question
Message-Id: <slrnbiitrt.1pn.tadmc@magna.augustmail.com>

Julia Briggs <julia4_me@yahoo.com> wrote:

> Omission of the word 'Perl' in the contruction of my question in this
> forum shouldn't automatically mean it was an HTML only question - 


Conversely, including the word "Perl" in your question does not
automatically mean that it _is_ a Perl question.  Now does it?

   I use Perl to manage my recipes.

   How do I make a good pecan pie?


The way to send output to some browser, and what output it is
that you should be sending to the browser, do not depend on
the programming language used.

The answer is the same whether you chose to program in Perl
or in Python or in Visual Basic, they all must do the same thing.

Once you find out what that "thing" is (in one of the web newsgroups),
_then_ you are ready to see how to make some particular language
output that "thing" for you.

You must know what you want before you can write a program
that will do what you want!


> now
> does it?  Zowie!  It's like a bunch of conditioned crickets jumping
> all over the place around here!


Are you serious?

You are clearly a beginner at more than just Perl programming, as is
the author of the silly followup.

The other followups were from more experienced people.


But you conclude that the 2 beginners are right and the
"bunch of" Perl programmers are wrong?

With (lack of) logic like that, programming is not the right 
field for you. So long.


   *plonk*


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


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

Date: 31 Jul 2003 14:17:37 -0700
From: Tim.Mundy@babelfish.com (Tim M)
Subject: File+Data from Java to Perl & back again. (SOAP?)
Message-Id: <f070cf9a.0307311317.3b44c892@posting.google.com>

Hey,

I'm working on integrating two systems together. One of them is Java
based while the other one is perl based. I'm going to need the two
servers to be able to communicate with one another. They will have to
send parameter data and also binary files back and forth. These files
could be as small as a couple KB, or they could potentially be many
MB's. (20-50+)

I'm not sure what the best method would be to enable this
communication. I'm leaning towards SOAP, but I'm sceptical due to my
need to send large files. Everywhere I've read suggests SOAP is too
bulky to transfer files efficiently.
I believe straight XML is in the same boat too.

What do you think? Is SOAP still a possibility, or do I need some
other solution? Maybe SOAP for parameters & FTP for the file transfer?

All ideas and feedback is welcome!


Tim Mundy
Software Developer

The Babel Fish Corporation
Where the World comes to Communicate!!
www.babelfish.com


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

Date: Thu, 31 Jul 2003 13:17:51 -0500
From: cp <cpryce@pryce.nospam.net>
Subject: Re: how to know the week of today?
Message-Id: <310720031317510686%cpryce@pryce.nospam.net>

In article <etor846a9fv.fsf@wormtongue.emschwar>, Eric Schwartz
<emschwar@ldl.fc.hp.com> wrote:

> $weeknum = int((localtime)[7] / 7);

Isn't that inaccurate? 
int( 365 / 7 ) = 52 

The 365th day of the year ( and on leap years, the 366th also) are in
the 53rd week.. 

The OP might want to check CPAN for any number of Date manipulation
modules. 'The Perl Cookbook'[1] suggests Date::Calc.

[bash:~]user% perl -e 'use Date::Calc qw(Week_Number);\
   print Week_Number('2003', 12, 31), "\n";'

outputs: 53


[1] pp 79 - 80.

-- 
cp


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

Date: 31 Jul 2003 11:30:13 -0700
From: jrolandumuc@yahoo.com (JR)
Subject: Re: how to know the week of today?
Message-Id: <b386d54b.0307311030.61dc8c3a@posting.google.com>

"C&J" <ggkuo@yahoo.com> wrote in message news:<OWlVa.662$Qb7.504188001@newssvr12.news.prodigy.com>...
> Hi,
> Is there any way to know what is the current week?
> January 1 is the first week.
> Thanks
> Chris

## This may be helpful to you.  Good luck. --JR

#!/Perl
use strict;
use warnings;
BEGIN {
   eval "use diagnostics";
   warn "Can't load diagnostics module.\n\n" if $@;
}

## This assumes a seven day week, and that the first day 
## of the year is January 1, xxxx.
printf "This is week %d, of the year %d.", (localtime)[7]/7, 
                                           (localtime)[5]+1900;


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

Date: Thu, 31 Jul 2003 12:42:51 -0600
From: Eric Schwartz <emschwar@ldl.fc.hp.com>
Subject: Re: how to know the week of today?
Message-Id: <eto65lia66s.fsf@wormtongue.emschwar>

cp <cpryce@pryce.nospam.net> writes:
> In article <etor846a9fv.fsf@wormtongue.emschwar>, Eric Schwartz
> <emschwar@ldl.fc.hp.com> wrote:
>
>> $weeknum = int((localtime)[7] / 7);
>
> Isn't that inaccurate? 
> int( 365 / 7 ) = 52 

Yeah, sorry:

use POSIX;
$weeknum = ceil((localtime)[7] / 7);

> The 365th day of the year ( and on leap years, the 366th also) are in
> the 53rd week.. 
>
> The OP might want to check CPAN for any number of Date manipulation
> modules. 'The Perl Cookbook'[1] suggests Date::Calc.

No disrespect intended to either the author of Date::Calc or the
Cookbook, but using Date::Calc for this is rather like swatting a fly
with an M1A1 Abrams.  I use modules just about everywhere I can, but
this is such a trivial problem that doesn't particularly need it.
Now, if I wanted to find out what week the next day fell into, I'd
surely use it.

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: Thu, 31 Jul 2003 15:29:40 -0500
From: cp <cpryce@pryce.nospam.net>
Subject: Re: how to know the week of today?
Message-Id: <310720031529405229%cpryce@pryce.nospam.net>

In article <eto65lia66s.fsf@wormtongue.emschwar>, Eric Schwartz
<emschwar@ldl.fc.hp.com> wrote:

> use POSIX;
> $weeknum = ceil((localtime)[7] / 7);
> 
> > The 365th day of the year ( and on leap years, the 366th also) are in
> > the 53rd week.. 
> >
> > The OP might want to check CPAN for any number of Date manipulation
> > modules. 'The Perl Cookbook'[1] suggests Date::Calc.
> 
> No disrespect intended to either the author of Date::Calc or the
> Cookbook, but using Date::Calc for this is rather like swatting a fly
> with an M1A1 Abrams.  I use modules just about everywhere I can, but
> this is such a trivial problem that doesn't particularly need it.
> Now, if I wanted to find out what week the next day fell into, I'd
> surely use it.

I don't really want to be argumentative, but if you're worried about
overkill, your solution also uses an fairly hefty module, the POSIX
module [1]. True, it does have the advantage of being part of the
standard distribution on most systems. 

Note to the OP, you can limit the amount of code that you import with
either: 

use POSIX qw(ceil); 
Or 
use Date::Calc qw(Week_Number); 

Either will import only the fuctions needed. 



[1] perldoc POSIX: 
NOTE
       The POSIX module is probably the most complex Perl module
       supplied with the standard distribution.  It incorporates
       autoloading, namespace games, and dynamic loading of code
       that's in Perl, C, or both.

-- 
cp


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

Date: 31 Jul 2003 13:03:58 -0700
From: dejanews@email.com (Sam Denton)
Subject: Re: pod2usage verbose problem
Message-Id: <3c863a7a.0307311203.db69766@posting.google.com>

jelias1@evl.uic.edu (Joshua Eliason) wrote in message news:<ce33c90b.0307240635.7886283b@posting.google.com>...
> hi,
> i cannot get pod2usage to produce the associated output for verbose
> levels 0 or 1 from the embedded pod. it prints nothing for verbose
> level 0 and 1. verbose level 2 does produce a man page output though.
> how can i get pod2uage to output the embedded pod info for verbose
> level 0 and 1? i tested, and got the same problem, on cygwin with perl
> 5.8 and linux using perl 5.6. thanks in advance for any help.


I'm seeing the same problem, Josh.  I note that within pod2usage, a
verbosity of 2 causes "system('perldoc', ...)" to be run, while lesser
verbosities don't.  It also appears that Pod::Usage's
preprocess_paragraph method is NOT getting called.

Here's some relevant info about my set-up:

$ mount
C:\Documents and Settings on /home type system (binmode)
C:\cygwin\bin on /usr/bin type system (binmode)
C:\cygwin\lib on /usr/lib type system (binmode)
C:\cygwin on / type system (binmode)
c: on /cygdrive/c type user (binmode,noumount)
d: on /cygdrive/d type user (binmode,noumount)

$ perl -v
This is perl, v5.8.0 built for cygwin-multi-64int
[...]

$ cygcheck -V
cygcheck version 1.32
[...]


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

Date: 31 Jul 2003 14:31:34 -0700
From: dejanews@email.com (Sam Denton)
Subject: Re: pod2usage verbose problem
Message-Id: <3c863a7a.0307311331.35978c6c@posting.google.com>

jelias1@evl.uic.edu (Joshua Eliason) wrote in message news:<ce33c90b.0307240635.7886283b@posting.google.com>...
> hi,
> i cannot get pod2usage to produce the associated output for verbose
> levels 0 or 1 from the embedded pod. it prints nothing for verbose
> level 0 and 1. verbose level 2 does produce a man page output though.
> how can i get pod2uage to output the embedded pod info for verbose
> level 0 and 1? i tested, and got the same problem, on cygwin with perl
> 5.8 and linux using perl 5.6. thanks in advance for any help.

Pod::Usage dervies from Pod::Select.  For verbosity level 0 it does a
$parser->select("SYNOPSIS"), while for verbosity level 1 it does
something a bit more complicated.  Verbosity level 2 doesn't call
'select' at all.  Adding a "\cM?" to the end of the the strings in
Pod::Usage causes everything to start working.  Apparently, our Perl
source lines end with the DOS CF/LF, instead of the Unix newlines,
causing the Pod::Select to break since it's checking for /^SYNOPSIS$/,
etc.

I'm not sure if this is a bug or a feature.  It's generally regarded
as the user's responsibility to get rid of CRs when importing files to
Unix.  OTOH, Perl under Cygwin can expect to see lots of files with
the "wrong" line terminators.


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

Date: Thu, 31 Jul 2003 21:23:56 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: regular expression question
Message-Id: <pan.2003.07.31.19.23.13.341211@kamelfreund.de>

Jay Flaherty wrote at Thu, 31 Jul 2003 13:14:50 -0400:

> Janek Schleicher wrote:
> 
>> perl -e '$_ = "foobarbarbar"; /((.*)\2+)$/; print length($1)/length($2)'
> 
> perl -e '$_ = "foobarbarbarbar"; /((.*)\2+)$/; print length($1)/length($2)'
> returns 2 (barbar x 2)
> So it seems to work with odd number of concats only.

No, it only returns prime numbers.
In fact "barbarbarbar" is "barbar" x 2.
And only prime number occurences can't be divided:

But if it is meant that the shortest repeating part should be counted,
you can use instead the non greedy version:

perl -e '$_ = "foobarbarbarbar"; /((.*?)\2+)$/; print length($1)/length($2)'
                                      ^

Greetings,
Janek


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

Date: Thu, 31 Jul 2003 18:22:06 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: semaphore example needed
Message-Id: <viinie62tvvr78@corp.supernews.com>

In article <3f293a14$1@newsgate.hknet.com>,
    j <perseus_medusa@hotmail.com> wrote:

: Thanks for your example but I don't quite understand some points :
: 
: 1) If more than 1 person is trying to change the semaphore, are they
: contending for the same lock to update the semaphore? If yes, will
: this become the bottleneck of the script ? Or is there anyway like
: preparing $max number of locks which client can wait for either one to
: reduce contention?

That program makes use of what's sometimes called a counting semaphore,
hence the $sem->setall($max).  We only have a single semphore, and it's
available so long as its value is positive.

Yes, synchronization can be a bottleneck, but it shouldn't be for your
application.

: 2) It just exit and then it can release the lock ? Or is there ways I
: could release the lock in the middle ?

You can get away with this because of the SEM_UNDO flag, which arranges
for the release of the semphore upon process exit, specified when we
take the semaphore.

To release the semaphore, you could use the following:

    sub release {
        my $sem = shift;
        $sem->op(0, 1, IPC_NOWAIT);
    }

Hope this helps,
Greg
-- 
A wise and frugal government, which shall restrain men from injuring one
another, which shall leave them otherwise free to regulate their own pursuits
of industry and improvement, and shall not take from the mouth of labor the
bread it has earned.        -- Thomas Jefferson


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

Date: Thu, 31 Jul 2003 18:15:35 +0000 (UTC)
From: "John J. Trammell" <trammell+usenet@hypersloth.invalid>
Subject: Re: Sorting question
Message-Id: <slrnbiin67.ad0.trammell+usenet@hypersloth.el-swifto.com.invalid>

On Thu, 31 Jul 2003 19:34:17 +0800, Derek Fountain
<nomail@hursley.ibm.com> wrote:
> I have a set of names, each of which has an associated size value.
> I want to list these names in size order.
>  

http://www.google.com/search?q=schwartzian+transform



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

Date: Thu, 31 Jul 2003 18:14:14 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: splicing two arrays
Message-Id: <x7smomzhqh.fsf@mail.sysarch.com>

>>>>> "MP" == Matija Papec <mpapec@yahoo.com> writes:

  MP> my @arr1 = 30..60;
  MP> my @arr2 = 10..40;

  MP> my %h = (
  MP>   33 => 'value',
  MP>   43 => 'value',
  MP>   45 => 'value',
  MP>   51 => 'value',
  MP>   53 => 'value',
  MP> );


  MP> Now, simple grep does a right thing,
  MP> @arr1 = grep exists $h{$_}, @arr1;

  MP> but it leaves me with @arr2 where corresponding elements to @arr1
  MP> should also be removed(when removing n-th from @arr1, remove n-th
  MP> from @arr2 too).

grep on the indexes and not on the values. then slice both arrays.

my @indexes = grep $h{$arr1[$_]}, @arr1 ;

@arr1 = @arr1[@indexes] ;
@arr2 = @arr2[@indexes] ;

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Thu, 31 Jul 2003 18:33:22 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: splicing two arrays
Message-Id: <Xns93C99412FEA63dkwwashere@216.168.3.30>

Uri Guttman <uri@stemsystems.com> wrote:

>>>>>> "MP" == Matija Papec <mpapec@yahoo.com> writes:
> 
>   MP> my @arr1 = 30..60;
>   MP> my @arr2 = 10..40;
> 
>   MP> my %h = (
>   MP>   33 => 'value',
>   MP>   43 => 'value',
>   MP>   45 => 'value',
>   MP>   51 => 'value',
>   MP>   53 => 'value',
>   MP> );

> grep on the indexes and not on the values. then slice both arrays.
> 
> my @indexes = grep $h{$arr1[$_]}, @arr1 ;

You mean like this? :-)

  my @indexes = grep $h{$arr1[$_]}, 0..$#arr1 ;


 
> @arr1 = @arr1[@indexes] ;
> @arr2 = @arr2[@indexes] ;


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

Date: Thu, 31 Jul 2003 18:34:36 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: splicing two arrays
Message-Id: <0jdWa.7$mZ6.3@nwrdny02.gnilink.net>

Matija Papec <mpapec@yahoo.com> wrote:
> I have two arrays of same length and want to remove 
> elements from them depending on %h(all values are just
> for illustration, there is no relation between them),
> 
> my @arr1 = 30..60;
> my @arr2 = 10..40;
> 
> my %h = (
>   33 => 'value',
>   43 => 'value',
>   45 => 'value',
>   51 => 'value',
>   53 => 'value',
> );
> 
> 
> Now, simple grep does a right thing,
> @arr1 = grep exists $h{$_}, @arr1;
> 
> but it leaves me with @arr2 where corresponding elements 
> to @arr1 should also be removed(when removing n-th from 
> @arr1, remove n-th from @arr2 too).
> 
> I ended up with simultaneous array rotation and I'm curios
> now if there is a better way? :)

How about:

  for my $i (0..$#arr1) {
    next unless exists $h{$arr1[$i]};
    splice @arr1, $i, 1;
    splice @arr2, $i, 1;
  }

Or is that the "simultaneous rotation"?

-- 
Steve


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

Date: Thu, 31 Jul 2003 18:34:28 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: splicing two arrays
Message-Id: <viio9knvapft29@corp.supernews.com>

In article <ntgiivk5e809danfdfuba5khga29aptu11@4ax.com>,
    Matija Papec  <mpapec@yahoo.com> wrote:

: Here is the problem which IMHO isn't trivialy(in one line) solvable in
: perl5; I have two arrays of same length and want to remove elements from
: them depending on %h(all values are just for illustration, there is no
: relation between them),
: 
: my @arr1 = 30..60;
: my @arr2 = 10..40;
: 
: my %h = (
:   33 => 'value',
:   43 => 'value',
:   45 => 'value',
:   51 => 'value',
:   53 => 'value',
: );
: 
: Now, simple grep does a right thing,
: @arr1 = grep exists $h{$_}, @arr1;

I can do that in one line!

    @$_ = grep exists $h{$_}, @$_ for \(@arr1, @arr2);

Whee!

: but it leaves me with @arr2 where corresponding elements to @arr1
: should also be removed(when removing n-th from @arr1, remove n-th
: from @arr2 too).

Oh, that's a different problem.  Is there a reason you're using parallel
arrays rather than a list of lists?

Greg
-- 
George Bush is just Bill Clinton in drag.
    -- Harry Browne


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

Date: Thu, 31 Jul 2003 18:49:05 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: splicing two arrays
Message-Id: <x7k79yzg4e.fsf@mail.sysarch.com>

>>>>> "DKW" == David K Wall <usenet@dwall.fastmail.fm> writes:

  DKW> Uri Guttman <uri@stemsystems.com> wrote:
  >>>>>>> "MP" == Matija Papec <mpapec@yahoo.com> writes:
  >> 
  MP> my @arr1 = 30..60;
  MP> my @arr2 = 10..40;
  >> 
  MP> my %h = (
  MP> 33 => 'value',
  MP> 43 => 'value',
  MP> 45 => 'value',
  MP> 51 => 'value',
  MP> 53 => 'value',
  MP> );

  >> grep on the indexes and not on the values. then slice both arrays.
  >> 
  >> my @indexes = grep $h{$arr1[$_]}, @arr1 ;

  DKW> You mean like this? :-)

  DKW>   my @indexes = grep $h{$arr1[$_]}, 0..$#arr1 ;

yeah. too quick on the reply.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

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


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