[23026] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5246 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 21 00:06:03 2003

Date: Sun, 20 Jul 2003 21:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 20 Jul 2003     Volume: 10 Number: 5246

Today's topics:
    Re: "use" remote modules? <ben.goldberg@hotpop.com>
    Re: Basic "IO::Select" problem <dodgynewsgroups@ewildgoose.demon.co.uk>
    Re: Basic "IO::Select" problem <ben.goldberg@hotpop.com>
    Re: Code to put today's date into MM-DD-YY format <REMOVEsdnCAPS@comcast.net>
    Re: Code to put today's date into MM-DD-YY format <REMOVEsdnCAPS@comcast.net>
    Re: Code to put today's date into MM-DD-YY format <REMOVEsdnCAPS@comcast.net>
    Re: Code to put today's date into MM-DD-YY format <bwalton@rochester.rr.com>
    Re: generalizing cgi handling <pinyaj@rpi.edu>
    Re: generalizing cgi handling <REMOVEsdnCAPS@comcast.net>
    Re: Image::Magick "geometry" atribute ??  user@domain.invalid
    Re: Notepad Bug when editing Perl scripts in Win XP? (Frank Shute)
    Re: Perl variable "leading white spaces" Please help (Greg)
    Re: replacing hex code characters <bwalton@rochester.rr.com>
    Re: Requiring a selection on a dropdown list? (dan baker)
    Re: restricting number of access to cgi <ben.goldberg@hotpop.com>
    Re: retrieve wishlist from Amazon <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 20 Jul 2003 22:18:35 -0400
From: Benjamin Goldberg <ben.goldberg@hotpop.com>
Subject: Re: "use" remote modules?
Message-Id: <3F1B4D7B.7792AA73@hotpop.com>



Michele Dondi wrote:
> 
> On Fri, 18 Jul 2003 18:36:33 -0400, Benjamin Goldberg
> <ben.goldberg@hotpop.com> wrote:
> 
> >Perl 5.6.1 and latter allow you to put a coderef into @INC.
> >
> >When you use or require a file, that coderef will be called with two
> >arguments -- the first one being the coderef itself, the second being
>                                       ^^^^^^^^^^^^^^
> 
> What is the possible use of that? I guess there must have been a good
> reason why it has been implemented that way, but I cannot see what it
> may be...

Well, coderefs aren't the only funny things you can put into @INC.

You can put in an arrayref, which has a coderef as the first element...
when used, the coderef will be called with the first argument as the
arrayref, and the second as the filename.  This way, you can pass extra
data in the rest of the arrayref.

You can put in a blessed object, in which case it's ->INC method will be
called, with the filename as an argument.  The blessed object itself
will, as it always is with methods, be the first argument to the
subroutine.

> [snip]
> 
> >      open(my ($fh), "<:scalar", \$doc) or die horribly;
>                          ^^^^^^
> 
> Browsing through the docs I finally ('perldoc PerlIOl') understood the
> meaning of that layer, but it seems that it wouldn't have been
> necessary while opening \$doc anyway, so I ask you if there's any
> advantage specifying it explicitly or if it "just" for a matter of
> clarity (always an important issue, IMHO).

Both for clarity, and so that the program would die if run under 5.6.1
or earlier.

One can, under 5.6.1, get the same effect by tieing to IO::Scalar, but
that would've been more typing for me :)

> Also, as I said, it was not exactly straightforward to get to the
> pertinent piece of documentation. How is one supposed to learn "this
> kind of things", apart being so fortunate as to decide to read by
> chance such a precious post as this one?

I've no idea... I happen to subscribe to the perl5porters mailing list,
and so learned of it that way.

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Sun, 20 Jul 2003 22:31:29 GMT
From: "Ed W" <dodgynewsgroups@ewildgoose.demon.co.uk>
Subject: Re: Basic "IO::Select" problem
Message-Id: <5LESa.633680$mA4.88486@news.easynews.com>

> I made a few changes to the code and got something back.  Since I
> don't have a real understanding of what multi-client16.pl is suppose
> to output, I used the Unix 'ls' command for a test.  I added comments
> to the new code below to point out what I did.  I anyone sees an error
> in what I did, please let me know.  It works, but it may have some
> pitfalls that are unknown to me.

Thanks James.

Actually, I should point out that everything works ok if the input has an
"eof" in it.  So the ls command works fine, instead create a short program
which runs in an infinite loop, does an ls, then waits 90 seconds, then runs
ls, etc, etc.

I found that the select statement NEVER blocked, and always returned a null
array...?  I will have a closer look at your code to see if it does
something different, but to my eyes, it looked the same?

Note also that this is a win 32 question.  It is highly likely that under
unix the non blocking stuff works, but this certainly is fraught with
problems under win32.  It may also be that select is not working properly
for file handles under win32?

Thanks

Ed




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

Date: Sun, 20 Jul 2003 21:57:22 -0400
From: Benjamin Goldberg <ben.goldberg@hotpop.com>
Subject: Re: Basic "IO::Select" problem
Message-Id: <3F1B4882.342BB128@hotpop.com>

Ed W wrote:
> 
> I have been staring at this for a day now (durr), but I just can't see
> what is wrong with this code: (apart from poor coding style, but it's a
> snippet...)
> 
> It's running under windows XP with activestate perl 5.6.1.  However, the
> code below always returns an empty array from the select call?

That's because you pass in a timeout of 0.  Change it to a postive
number, or to undef(), and it will work.

Oh, and you should be sysread()ing from $H, not from $ARG.

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Sun, 20 Jul 2003 18:50:16 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Code to put today's date into MM-DD-YY format
Message-Id: <Xns93BEC9B373E1Dsdn.comcast@206.127.4.25>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

"Ron" <his_ron@yahoo.com> wrote in
news:Q4xSa.90354$hV.6381454@twister.austin.rr.com: 

> That works great.  Just one more little problem (My Fault)  I need the
> year in YYYY format?
> 
> How would I change this to get MM-DD-YYYY Day?

use Time::Format;
my $date = $time{'mm-dd-yyyy Day'};
print $date;

- -- 
Eric
$_ =  reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPxsqkmPeouIeTNHoEQJ1HQCfaODx8mA5pYTwwyvLpPcWUdmeZvMAoNMM
SbY2cqGWeSVdvMa3EcEAzu65
=ZFBS
-----END PGP SIGNATURE-----


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

Date: Sun, 20 Jul 2003 18:51:16 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Code to put today's date into MM-DD-YY format
Message-Id: <Xns93BEC9DEB6F62sdn.comcast@206.127.4.25>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

Devdas Bhagat <devdas@users.sourceforge.net> wrote in
news:slrnbhlets.3m5.devdas@evita.devdas.geek: 

> On Sun, 20 Jul 2003 13:48:32 GMT, Ron <his_ron@yahoo.com> poured into
> the usenet group comp.lang.perl.misc:
>> Thanks Matija,
>> 
>> That works great.  Just one more little problem (My Fault)  I need
>> the year in YYYY format?
>> 
>> How would I change this to get MM-DD-YYYY Day?

 ...
> I would recommend 
> my $today = sprintf("%02d-%02d-%d", $mm+1, $dd, $yy+1900);
> Much easier to follow and it should be faster.

Don't forget that he wanted the "Day" in there too.

- -- 
Eric
$_ =  reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPxsqzmPeouIeTNHoEQJ1UgCgnBebWzZ7U76D9QtvsKgdV87NwwQAoLak
4CcEJUHUhbgJHrNo7fag7ZO5
=8jxz
-----END PGP SIGNATURE-----


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

Date: Sun, 20 Jul 2003 18:52:43 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Code to put today's date into MM-DD-YY format
Message-Id: <Xns93BECA1E0B534sdn.comcast@206.127.4.25>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

Tony Curtis <tony_curtis32@yahoo.com> wrote in 
news:87oezp9oii.fsf@limey.hpcc.uh.edu:

>>> On 20 Jul 2003 15:57:21 GMT,
>>> Devdas Bhagat <devdas@users.sourceforge.net> said:
> 
>> On Sun, 20 Jul 2003 13:48:32 GMT, Ron
>> <his_ron@yahoo.com> poured into the usenet group
>> comp.lang.perl.misc:
>>
>>> That works great.  Just one more little problem (My
>>> Fault) I need the year in YYYY format?
>>> 
>>> How would I change this to get MM-DD-YYYY Day?

 ...
> use POSIX qw(strftime);
> my $today = strftime('%m-%d-%Y', localtime);
> 
> Let the module take the strain.

Don't forget that he wanted the "Day" in there too.

- -- 
Eric
$_ =  reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPxsrI2PeouIeTNHoEQJPUQCg+XeX/zJoeSHlyxluk26DgcszU2kAn0kQ
B9imPDEnyxZJlhcGs6PGIArs
=18Dy
-----END PGP SIGNATURE-----


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

Date: Mon, 21 Jul 2003 00:25:07 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Code to put today's date into MM-DD-YY format
Message-Id: <3F1B32DB.9080401@rochester.rr.com>

Ron wrote:

 ...


> 1. Get the current date & day of the week.
> 2. Put it into this format MM-DD-YY Day
> 
> I have no ideal where to start.  Suggestions Please?
 ...


> Ron


You can't get much easier than:


    use Date::Manip;
    $ENV{TZ}='EDT'; #only if your OS doesn't define it
    print UnixDate('today','%m-%d-%y %A');

or

    print UnixDate('today','%m-%d-%Y %A);

for your subsequent request.
-- 
Bob Walton



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

Date: Sun, 20 Jul 2003 19:03:47 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: generalizing cgi handling
Message-Id: <Pine.SGI.3.96.1030720185823.17060B-100000@vcmr-64.server.rpi.edu>

On Sun, 20 Jul 2003, Steve in NY wrote:

>Thank you for the reply and the pointers. To tell you the truth, the
>material about symbolic references is going to take awhile to sink in. I
>am glad to be aware of it....but it confuses the heck out of me at this
>point ;-) 

That's ok.  It's not the easiest stuff in the world.

>Hey, but I did a web search on articles you wrote and found this:
>
>http://www.devarticles.com/art/1/293
>
>which seems to me to be exactly what I was trying to do.

Holy crap.  First of all, that's a very weird headshot -- it's actually
pretty awful.  I look better than that. Second, I never actually published
that, to the best of my knowledge.

I don't like the formatting they've used -- my code appears to be not
indented at all, which I find borders on slanderous.  My original work is
online... I'll give you the URL, but I must make you aware that this was
mostly an exercise for me, and the usefulness of the article was to show
how difficult it is to do things correctly.

  http://www.pobox.com/~japhy/articles/ideas/CGI.html

I'm going to contact the people that run devarticles.com...

-- 
Jeff Pinyan            RPI Acacia Brother #734            2003 Rush Chairman
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



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

Date: Sun, 20 Jul 2003 19:15:03 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: generalizing cgi handling
Message-Id: <Xns93BECDE707471sdn.comcast@206.127.4.25>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

Steve in NY <me@home.com> wrote in
news:a1ilhv8732s730vebhqm1hp3mfifg1atl9@4ax.com: 

> Hi Eric, thank you for taking the time to reply to my post.
 ... 
>>If you really really want to do that (and hey, this is just a learning
>>excercise so what the heck), you have to do something like the
>>following. 
>>
>>    # at start of cgi_handling function
>>    my $caller_package = caller;

This gets the name of the caller's package.  For example, if in your main 
program, you do a "use Whatsis;", and this code is in the module 
"Whatsis", then $caller_package will be assigned "main".

>>
>>    # later, at the point where you currently assign $a{$key}
>>    {
>>        no strict 'refs';
>>        *{$caller_package . '::' . $key) = \$value;
>>    }

Let's take it one step at a time.

$caller_package is 'main' (continuing our example from above).
$key is your variable name, say "mouseketeer".
then:
$caller_package . '::' . $key is "main::mouseketeer".

This is the name of a variable in the package main -- or at least, it 
would be if it had a leading $, @, or %.  Instead, we use *{} to treat it 
as a typeglob.  This is the symbolic reference part --  we had the name 
of a variable in a string, and we dereferenced it as a typeglob.

Why a typeglob?  Because this is how you manipulate symbol tables in 
Perl.  (well, it's one way).  Now: put this thought on hold for a second 
while I digress.

====BEGIN DIGRESSION====
In perl, a typeglob is sort of a glob of all the types of a variable name 
in the current package.  That is: *foo is a collection of $foo, @foo, 
%foo, &foo, and a couple other things.

One use for this is to set up aliases.  If you do:

    *foo = *bar;

then $foo and $bar are exactly the same (assigning to one will set the 
other, since they point to the same memory location). Ditto @foo/@bar, 
etc.

If you do:

    *foo = \@bar;

that is, you assign a reference to ONE type of variable to a typeglob, 
then ONLY that one variable is aliased.  In the above line, @foo becomes 
an alias for @bar, but $foo and $bar remain separate, as do &foo and 
&bar, etc.
====END DIGRESSION====

Modules can use this mechanism to export variables.  In the code I sent 
you:

    *{$caller_package . '::' . $key) = \$value;

which, given the example values we were working with, is:

    *{"main::mouseketeer"} = \$value;

This assigns a scalar reference to a typeglob.  Thus, $main::mouseketeer 
becomes an alias for $value.

The Exporter module uses this very mechanism.  It's a big complex module 
to wade through, but if you dig down deeply enough, you'll find a 
statement like:

    *{$caller_package . '::' . $sub} = \&{$this_pkg . '::' . $sub};

In fact, in my copy of Exporter.pm (versioon 5.566), this is on line 59.


This sort of manipulation is a very powerful tool, and it's one of the 
things that make Perl great, but it's not useful in a whole lot of 
situations.  So don't be tempted to start using this technique all over.  
It's an excellent thing to learn and know, but others have cautioned you 
against using it, and wisely so.  Symbolic manipulation can be a potent 
source of hard-to-find bugs.

- -- 
Eric
$_ =  reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPxswYWPeouIeTNHoEQL9iwCffDlP0jpqVVPzS5M2osqjTBCVr0UAnAqs
wHr2+c1N7okkUqvGPFUSyYu1
=A4GP
-----END PGP SIGNATURE-----


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

Date: Mon, 21 Jul 2003 04:16:59 GMT
From:  user@domain.invalid
Subject: Re: Image::Magick "geometry" atribute ??
Message-Id: <47b45927f461d457bf8c6bc7ff4aee56@free.teranews.com>

Martien Verbruggen wrote:
> [Please, do not ask for follow-up to poster if the response could be
> useful for all readers of the newsgroup. Followup to poster is generally
> only used when a discussion has reached a point where it should no
> longer be continued on the group anymore.]

I didn't know I did.  But sorry.

> More information about geometry can be found in the generic manual pages
> for the ImageMagick tools, and under the command line options to these
> tools.  See, for example
> 
> http://www.imagemagick.org/www/utilities.html
> 
> Without writing a complete reference for all methods (been there, done
> that), I can't be that much more helpful.
> 
> I'd advise you to not use the geometry attribute, when there are options
> that allow you to avoid it.

I didn't know I could avoid it anywhere, but hey, I'll try!  Thanks for the 
info.  Really, thanks very much.

-- 
   -Tommy Butler
    see if I'm online »http://ooopps.sourceforge.net/online

    Tommy Butler <tommy@atrixnet.com>
    phone: (817)-466-2245
    912 Greenridge Drive
    Arlington, TX
         76017-6243

    the ooOPps Code Library
    http://ooopps.sourceforge.net/pub/



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

Date: Mon, 21 Jul 2003 04:45:16 +0100
From: frank@SPAMLESSesperance-linux.co.uk (Frank Shute)
Subject: Re: Notepad Bug when editing Perl scripts in Win XP?
Message-Id: <c74su-0ge.ln1@peach.esperance-linux.co.uk>

On Sat, 19 Jul 2003 11:03:33 -0500, randy wrote:
>
> Has anyone else tried editing perl scripts in notepad in XP? I am
> getting some characters inserted into the scripts.....

If you're doing any text editing on XP on a regular basis then you're
probably best off installing a "Unix" text editor. I know that you can
get a Windows port of Vim: http://www.vim.org/

-- 

 Frank



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

Date: 20 Jul 2003 17:33:26 -0700
From: gdsafford@hotmail.com (Greg)
Subject: Re: Perl variable "leading white spaces" Please help
Message-Id: <a8f367ed.0307201633.645d0684@posting.google.com>

Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote in message news:<Pine.SGI.3.96.1030720131001.5139A-100000@vcmr-64.server.rpi.edu>...
> [posted & mailed]
> 
> On Sun, 20 Jul 2003, "Dandy" Randy wrote:
> 
> >Hello everyone. I have been following misc posts, as well as reading several
> >FAQ's on this issue, unfortunatley I cannot locate a solution. I am hoping
> >that someone will be able to provide me with the simple answer. My problem
> >has to do with the leading white spaces after the first line when calling
> >data using the @ variable. Here is my code:
> 
> I suggest you look in the FAQ:
> 
>   perldoc -q spaces
> 
> yields the following:
> 
> =======================================================================
> =head1 Found in /usr/lib/perl5/5.00503/pod/perlfaq5.pod
> 
> =head2 Why do I get weird spaces when I print an array of lines?
> 
> Saying
> 
>     print "@lines\n";
> 
> joins together the elements of C<@lines> with a space between them.
> If C<@lines> were C<("little", "fluffy", "clouds")> then the above
> statement would print:
> 
>     little fluffy clouds
> 
> but if each element of C<@lines> was a line of text, ending a newline
> character C<("little\n", "fluffy\n", "clouds\n")> then it would print:
> 
>     little
>      fluffy
>      clouds
> 
> If your array contains lines, just print them:
> 
>     print @lines;
> =======================================================================
> 
> There are a couple ways you can fix this problem:
> 
> 1. join the elements of the array together into a scalar beforehand, and
>    print the scalar
> 
>      $text = join "", @array;
> 
> 2. set the $" variable to "" (locally); this means that when you print an
>    array in double quotes, it will insert "" (nothing) in between the
>    elements, instead of the default which is " " (a space)
> 
>      {
>        local $" = "";
>        print "... @lines ...";
>      }

If the idea is to put the content of the file in the textarea, an
alternative to fixing the interpolation of the array might be to slurp
the file contents into a scalar and interpolate that, maybe localizing
the file handle as well:

my $text = '';
{
  local $/;
  local *PREVIEW;
  open (PREVIEW, "<preview.txt") or die "Unable to open file: $!";
  flock PREVIEW, 2;
  $text = <PREVIEW>;
}

Not an expert. So, FWIW.


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

Date: Mon, 21 Jul 2003 00:10:27 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: replacing hex code characters
Message-Id: <3F1B2F6A.7080403@rochester.rr.com>

Boudga wrote:

> Is it possible to substitute a hex code of "A0" with "20" in a text file
> using Perl REGEX?

Yes, but you would be (slightly) better off using the translate operator 
if you want to translate characters:

    $string=~tr/\240/\040/;

or, if you want to remove the 8th bit from all ASCII characters:

    $string=~tr/\200-\377/\000-\177/;

-- 
Bob Walton



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

Date: 20 Jul 2003 19:21:37 -0700
From: botfood@yahoo.com (dan baker)
Subject: Re: Requiring a selection on a dropdown list?
Message-Id: <13685ef8.0307201821.7217b43c@posting.google.com>

"Ron" <his_ron@yahoo.com> wrote in message news:<2x_Ra.85066$hV.5920326@twister.austin.rr.com>...
> Maybe more of an html question but here goes.  I have a form with a
> drop-down list I would like to require the user to make a selection on.  How
> would I go about doing this?
> -----------

well, the cgi group IS more in line with this, but if you are sending
the form to a perl script... you just have to check the contents of
the parameter, and send the user an error message or back to where
they came from...

	use CGI qw( param );
	my $FilePath = param( 'FilePath' );
        unless ( $FilePath ) {

            print "Content-type: text/plain \n\n".
                  "you need to make a selection for FilePath...\n" ;
        }

remember that checking with javascript on the webpage is ok, but wont
protect you from anyone TRYING to send bad stuff as they can write a
script to feed your script whatever they want. You HAVE to check it
server-side.

d


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

Date: Sun, 20 Jul 2003 21:44:42 -0400
From: Benjamin Goldberg <ben.goldberg@hotpop.com>
Subject: Re: restricting number of access to cgi
Message-Id: <3F1B458A.A31572B4@hotpop.com>



j wrote:
> 
> Hi all ,
> 
>     I have a cgi but I'd like to limit the number concurrent user for
> this cgi. I am now using `ps -ef | grep -v | grep mycgi | wc -l` and get
> the number and limit it to a number. But I found that this take quite
> some seconds. Is there faster way and safer ways to limit that if
> database is not allowed ?
>
> 
>     I am thinking of using variable written in a file to record the
> process with some locking mechanism. If the cgi is triggered, the
> variable inside the file is added by one and reduced when the cgi exit.
> But I am worrying if the cgi failed in the middle for whatever reason in
> the middle, the number will be not correctly reflecting the number of
> process.
> 
>     Can some one suggest a way to provide a more appropriate way or
> solve the above problem ?

Besides the settings file for the httpd, you could write, not the
*number* of processes performing this cgi, but rather the process ids
themselves.

E.g.:

   my $count = 0;
   open LOCKFILE, "<+", "/absolute/path/to/lockfile.txt"
      or die horribly;
   $| = 1, select $_ for select LOCKFILE;
   TRY_LOOP: {
      seek LOCKFILE, 0, SEEK_SET or die horribly;
      flock LOCKFILE, LOCK_EX or die horribly;
      my @pids = split ' ', scalar <LOCKFILE>;
      @pids = grep kill(0, $_), @pids;
      if( @pids >= 5 ) {
         if( ++$count < 10 ) {
            flock LOCKFILE, LOCK_UN or die horribly;
            fseek LOCKFILE, 0, SEEK_SET or die horribly;
            sleep 1; redo TRY_LOOP;
         }
         print "Status: 503\n";
         print "Retry-after: 30\n";
         print "Content-type: text/plain\n\n";
         print "Our server is overloaded.\n";
         print "Please try again in a few minutes.\n"
         exit;
      }
      push @pids, $$;
      fseek LOCKFILE, 0, SEEK_SET or die horribly;
      print LOCKFILE "@pids\n" or die horribly;
      my $len = tell LOCKFILE;
      truncate LOCKFILE, $len;
      # explicit unlocking is *usually* a Bad Thing,
      # but since $| is 1 for this filehandle, it's ok.
      flock LOCKFILE, LOCK_UN or die horribly;
   }
   END {
      flock LOCKFILE, LOCK_EX or die horribly;
      my @pids = split ' ', scalar <LOCKFILE>;
      @pids = grep kill(0, $_) && $_ != $$, @pids;
      seek LOCKFILE, 0, SEEK_SET;
      print LOCKFILE "@pids\n" or die horribly;
      my $len = tell LOCKFILE;
      truncate LOCKFILE, $len;
      close LOCKFILE or die horribly;
   }

[untested]

I probably could have chosen to close the handle after writing our own
pid to the file, and then re-open inside the END block... if the cost of
keeping the handle open for the duration of the cgi is too high (if
you're limited in terms of how many handles your cgi may open), then I
would suggest you do that.

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Sun, 20 Jul 2003 23:52:38 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: retrieve wishlist from Amazon
Message-Id: <3F1B2B3D.5010807@rochester.rr.com>

Patrick Flaherty wrote:

 ...
>   Would like to use Perl to retrive my wishlist periodically from Amazon.
> 
>   Checked CPAN and there's actually a module to do this: WWW::Amazon::Wishlist 
> 
> Written by someone in the UK so I had to modify it slightly.  Did so and tried
> but then realized that it wasn't logging into my account (maybe this didn't
> exist in 2001 when the script was first written).
> 
 ...


>>  my $my_amazon_com_id = "002-1656974-7132841";


You picked the wrong bit for your wish list ID.  It is the string that 
has the mixed numbers and cap letters that you want.  And no, you don't 
need to log in to look at someone's wish list.  And, I didn't have to 
modify WWW::Amazon::Wishlist.pm (version 0.9).

The following, for example, gets my wish list, although not very nicely 
formatted:

  use WWW::Amazon::Wishlist qw(get_list);
  my @wishlist;
  $my_amazon_com_id='3YBOF9YU9Q1E';
  @wishlist = get_list ($my_amazon_com_id);       # gets it from amazon.com
  # the elements of @wishlist are hashrefs that contain ...
  foreach my $book (@wishlist)
  {
print $book->{title},   # the, err, title
      $book->{author},  # and the author(s) 
      $book->{asin},    # the asin number, its unique id on Amazon
$book->{price},# how much it will set you back
      $book->{type};    # Hardcover/Paperback/CD/DVD etc
  }

 ...


>>  pat
 ...

-- 
Bob Walton



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

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


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