[19990] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2185 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 22 18:05:49 2001

Date: Thu, 22 Nov 2001 15:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1006470306-v10-i2185@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 22 Nov 2001     Volume: 10 Number: 2185

Today's topics:
    Re: Creating a Perl app.  Help with installation? <mgjv@tradingpost.com.au>
    Re: File locking question <J.E.J.opdenBrouw@st.hhs.nl>
    Re: How can you do a safe unlink? (Mark Jason Dominus)
    Re: How can you do a safe unlink? <mgjv@tradingpost.com.au>
    Re: how to calculate the CRC of a string... <no_mto@hotmail.com>
        Import own Subroutines in Perl <th_gi@hotmail.com>
    Re: Import own Subroutines in Perl <ilya@martynov.org>
        Prototype Mismatch Error <newsgroup_mike@ultrafusion.co.uk>
    Re: Prototype Mismatch Error <Laocoon@eudoramail.com>
    Re: Prototype Mismatch Error (Mark Jason Dominus)
        Renaming directories (Nathan Jones)
    Re: Renaming directories (Mark Jason Dominus)
    Re: Renaming directories <ilya@martynov.org>
    Re: unicode with perl (Mark Jason Dominus)
    Re: Using CGI.pm to obtain a list of params <wsegrave@mindspring.com>
    Re: Using CGI.pm to obtain a list of params <wsegrave@mindspring.com>
    Re: using sendmail from perl <pne-news-20011122@newton.digitalspace.net>
    Re: variable scope (Mark Jason Dominus)
    Re: variable scope <gisle@ActiveState.com>
    Re: Version of Perl at runtime (Chris Fedde)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 22 Nov 2001 21:47:30 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Creating a Perl app.  Help with installation?
Message-Id: <slrn9vqsjl.meb.mgjv@verbruggen.comdyn.com.au>

On 22 Nov 2001 16:46:10 GMT,
	<mcnuttj@dnps-linux1.telecom.missouri.edu> wrote:
> Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
>> brian d foy wrote in comp.lang.perl.misc:
>>> 
>>> Here are some starting resources:
>>> 
>>>     http://www.perldoc.com/perl5.6.1/bin/h2xs.html 
>>>     http://www.perldoc.com/perl5.6.1/lib/ExtUtils/MakeMaker.html
> 
>> Also an article "Building Perl projects with MakeMaker" :
> 
>> http://www-106.ibm.com/developerworks/linux/library/l-make.html
> 
> This last link seems to be the most useful so far, since it pretty
> much walks you through building a quick MakeMaker project.
> 
> I ran 'h2xs -X' and I've been looking at the documentation for 
> MakeMaker, but it all seems to revolve around making a *module*, 
> whereas I'm making an *application* (that happens to contain, 
> among many other things, some modules).

The MakeMaker stuff will handle programs in your package directory as
well as modules. Have a look at the EXE_FILES attribute. You could
also have a look to see how libwww for example does it. That has
several programs that get installed.

> The documentation to MakeMaker is confusing.  First of all, it
> refers (over and over) to "extensions" to Perl.  At first this
> seems synonymous with "modules", but that isn't the case either
> because it also refers to creating perl binaries and linking them.

ExtUtils::MakeMaker and h2xs were/are very geared towards compiling XS
extensions, yes, but if you don't need to do that, you can ignore all
the stuff about that. It is still mainly used to facilitate the
installation of modules, but it can be used equally well for
applications, when these applications consist of executables and
modules.

> The biggest gripe I have about MakeMaker thus far, though is that
> there seesm to be no provision (or at least, no explanation) for a
> 'make uninstall'.  A quick look at ExtUtils::Install shows that it
> *is* in there, but there's no reference to it in the MakeMaker man
> page nor is there any hint as to how the uninstall function is
> intended to be actually used (there's syntax, but no *context*).

Yep. The documentation of many things Perl is not always complete.
Maybe you could submit some patches after you've worked it out?

> And there's still no help on what to do with all of the MIB files.

Without MakeMaker there would be no help either. MakeMaker automates
the installation of modules and executables. It automates any
compilation steps, if needed. For anything that's not in the realm of
Perl, you still have to write your own Makefile entries, but you can
use many of the variables set by MakeMaker.

> The whole structure looks pretty cool (and useful), but there are
> some gaps that need filling before I'm ready to unleash this on my

Indeed there are.

> coworkers.  :-)  Particularly, there are some interesting things
> that my current Makefile does that I see no provision for in
> MakeMaker.  'make uninstall' is one of them.  Another is that in
> my current Makefile I do this several times:
> 	cp bin/jscan $(BINDIR)/jscan
> 	(cd $(BINDIR) ; ln -s ./jscan ./jscan.cgi)

As said, you can use MakeMaker for the framework, and add anything
else you need yourself. It still means that you'd only need to write
and maintain part of the installation process yourself, and you can
rest assured that your modules end up in the right place.

Instead of just looking at the docs, why don't you have a look at some
of the Makefile.PL in the more complex CPAN distributions. libwww is
one I already mentioned. I'm sure there are some other ones that could
be useful as examples.

> or something similar to create symlinks to my executables.  How
> does MakeMaker handle something like that?

You write the Makefile entry :) Look at the postamble bit in the
ExtUtils::MakeMaker documentation, under "Overriding MakeMaker
methods".

Martien
-- 
                                | 
Martien Verbruggen              | Hi, Dave here, what's the root
Trading Post Australia Pty Ltd  | password?
                                | 


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

Date: Thu, 22 Nov 2001 23:53:07 +0100
From: "J. op den Brouw" <J.E.J.opdenBrouw@st.hhs.nl>
Subject: Re: File locking question
Message-Id: <3BFD81D3.82188B0F@st.hhs.nl>

The question is, how to do it in Perl of course.
But this solution is not doing it with
file locking (so that others cannot play with
the files). So this renders all solutions
useless.

Laocoon wrote:
> 
> Is this a Perl question? If it is..
> 
> example :
> 
> open(IN,"input") or die "Input : $!";
> open(OUT,">output") or die "Output : $!";
> $in = join "" , <IN>;
> close(IN);
> `del input`;
> print OUT $in;
> close(OUT);

--Jesse


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

Date: Thu, 22 Nov 2001 19:09:00 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: How can you do a safe unlink?
Message-Id: <3bfd4d4c.19d$1e7@news.op.net>

In article <C67L7.12897$YD.1245758@news2.aus1.giganews.com>,
Mark <admin@asarian-host.net> wrote:
>Meanwhile, the grizzly bear has, despite any number of cheap personal
>attacks,

I am not aware that I have made any personal attacks, cheap or otherwise.

> The  grizzly bear has growled
>that flock is not a Perl function, that he did not know what OS I was using,
>etc.

Some people might take that as a sign that the OS was relevant to the
question.

>At the end of the day, when all put-downs subside, the grizzly bear will, in
>my estimation, still be stumped for a decent answer. 

I'll go you one better.  I'm still stumped for a decent question.

Good luck with your problem.
-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Thu, 22 Nov 2001 22:03:29 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: How can you do a safe unlink?
Message-Id: <slrn9vqthk.meb.mgjv@verbruggen.comdyn.com.au>

On Thu, 22 Nov 2001 13:31:14 GMT,
	Mark <admin@asarian-host.net> wrote:
> "Helgi Briem" <helgi@decode.is> wrote in message
> news:3bfceca2.3034632911@News.CIS.DFN.DE...
> 
>> On Thu, 22 Nov 2001 02:07:30 GMT, "Mark"
>> <admin@asarian-host.net> wrote:
>>
>> >"Mark Jason Dominus" <mjd@plover.com> wrote in message
>> >news:3bfc52ab.5e7a$338@news.op.net...
>>
>> Reading this thread is like watching a little
>> fluffy white bunny wabbit (Mark@asarian) venturing
>> out of its hole for the first time, attacking a
>> not very hungry grizzly bear (Mark JD) that
>> likes to play with its food before eating it.
>>
>> Let the games begin.
> 
> 
> Meanwhile, the grizzly bear has, despite any number of cheap personal
> attacks, not given a solution to the problem. The grizzly bear has growled

He has given you information, and asked questions. None of which you
seem to be wanting to answer.

> that flock is not a Perl function, that he did not know what OS I was using,
> etc. But as to the main question, in all its simplicity, as how to obtain a
> lock on a file before unlinking it, without having to create a handle for it

You use flock on the file handle.

> first -- a handle to an open file that will prevent the file from being
> unlinked in the first place (or will allow it to be unlinked, but still

Euhmm.. That, as has been said several times, is platform specific.
Unices have no problems with unlinking a file that a process has open.
The link on the file system disappears, the program that has the file
open keeps it open. No problem.

What The various versions of DOS and Windows do may very well be
different. I know that at least a efw of these versions implement
mandatory locking, which prevents you from unlinking a file while it's
open. But this is not something Perl can do anything about. I doubt
very much that you can do what you want to do on those platforms in
another language either.

> allows it to be readable for already open filehandles to it) -- to that
> quandary this white bunny has yet to hear a decent answer.

The question again is: WHY do you think it's necessary to obtain a
lock before deleting a file? Is it that you want to have some blocking
function that you can use so that when you call unlink you can be
certain that it won't fail because of concurrency issues? There may
very well be something in the Win32 API for that. ActiveState has
Win32 specific modules that allow you to call this API. But there
isn't anything in Perl. Maybe you could use a system-wide semaphore,
as long as all your programs do the same thing.

> At the end of the day, when all put-downs subside, the grizzly bear will, in
> my estimation, still be stumped for a decent answer. History will likely
> prove the white bunny right: that acquiring a lock on a file before
> unlinking it, is not safe: because either the file will not unlink, as you

This statement is wrong. It has nothing to do with safety. Yes, it is
impossible to acquire a file lock from Perl without opening the file.

On some platforms, having the file open prevents you from unlinking
it.

maybe you should stop insisting on this discussion, and the method you
are trying to use, and describe what you want to do, and what the
problems are in words, without any preconception about which functions
or methods you need. There may very well be a Win32 programmer on this
newsgroup who then recognises the problem, and can point you to the
correct solution for your platform (not that for many other platforms
there is never a problem). The problem you're seeing exists only on
platforms that have this sort of mandatory locking, and a solution
should be sought in platform specific APIs. 

Perl has a lot of Unix history, and that shows. The problem you have
does not exist on Unix.

> would want it to (which means you have to unlink without the lock), or it
> will unlink, but not prevent open filehandles to that file from continuing
> to read from / write to it. It may not bother the grizzly bear that
> processes can continue to read from files that have been unlinked from the
> FS, but I call it pretty darn unsafe.

As I have explained. On Unices, you just unlink the file, and every
process that has the file open will still have it open. The file only
has disappeared from the file system.

Windows _could_ have implemented its various file systems that way as
well, but they chose to use mandatory locking instead. 


> At the risk of giving you some more food for laughter, I was actually
> mistaken about the unlinked file being recommitted to disk again. It simply

No one is laughing. There is no need to get defensive.

Please, take a small step back, and describe what it is you want to do
without resorting to function names or methodologies you _think_ you
need.

> the latter. Which is a shame, actually. Acquiring a lock for a file in order
> to safely unlink it, that is, granted, not the world's most enticing
> problem; nor does this white bunny expect an enticing answer; just a normal
> one would do.

But concurrency issues ARE important, and it's GOOD that you think
about it. That isn't why people react to what you say. People react
because you make broad sweeping statements, and get tangled up in
misunderstandings, and you fail to see where the boundary is between
what an OS does, and what Perl does and can do.

Martien
-- 
                                | 
Martien Verbruggen              | If it isn't broken, it doesn't have
Trading Post Australia Pty Ltd  | enough features yet.
                                | 


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

Date: Thu, 22 Nov 2001 22:03:07 +0100
From: "MAGiC MANiAC^mTo" <no_mto@hotmail.com>
Subject: Re: how to calculate the CRC of a string...
Message-Id: <9tjpgb$2mvc$1@news.kabelfoon.nl>


This crc64.pm from http://swissknife.sourceforge.net is beter than I
expected !
Because I want to have a result that is calculated in a hex format:
"029FFA0091"

I still don't know what what server my host have. stupid me, but I like this
script.
Because I want to create a script that I can release for free to other users
when it's
finished. SO this one is I think beter than the other one don't you think?

I will also try lateron the things you say before for research...

I would thank you for al the help you've given me.

Many thanks!!!!

             MAGiC MANiAC^mTo


"Bart Lateur" <bart.lateur@skynet.be> schreef in bericht
news:ev4qvt00of3ef1nnma21hq8peus1aj37gi@4ax.com...
> MAGiC MANiAC^mTo wrote:
>
> >I like to upload it to my host when I'm ready with my script file.
> >What files do I have to upload to my host?...
>
> Gee. What kind of server does your host have? Because it sure likes like
> you'll have to install it yourself. And, since this module depends on XS
> (a compiled extension in C), simply copying of the necessary files won't
> work, unless the other server is precisely the same architecture as
> yours (same processor, same OS and preferably same OS version, same
> include libs, same perl, ...)
>
> If it is Windows, and he's using a compatible perl, then it could work.
> Check out what's in the .tar.gz file to see what files you need. All you
> need to do is put them in an appropriate subdirectory of your chosen lib
> root.
>
> If it is an Unix compatible, then you'll have to compile it yourself, in
> the traditional manner. It is feasable if you have telnet access. If
> not... it might be possible to temporarily wrap the installer
> instructions it in a CGI script, and call it through the browser,
> installing it in a directory owned by "nobody". Make sure you make all
> installed files world writable, or you'll never succeed in getting rid
> of them again.
>
> For instructions on how to do a custom install, check out these entries
> in the FAQ, perlfaq8 (it is part of the standard perl docs):
>
> Found in D:\programs\indigoperl\lib\pod\perlfaq8.pod
>   How do I install a module from CPAN?
>   How do I keep my own module/library directory?
>
> But honestly, I'd stay away from this as a newbie.
>
> There is a CRC library file avilable somewhere, in pure perl, thus which
> doesn't require installation. Let me see...
>
> Here's one:
>
> <http://www.sph.umich.edu/~aspinall/code/crc32>
>
> but not the one I was thinking of... Ah, there it is:
>
> <http://swissknife.sourceforge.net/>
>
> See the two "CRC64" links at the bottom of the page.
>
> --
> Bart.




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

Date: Thu, 22 Nov 2001 23:25:06 +0100
From: "Th.G" <th_gi@hotmail.com>
Subject: Import own Subroutines in Perl
Message-Id: <3BFD7B42.1060103@hotmail.com>

Hi

I wrote a file with subroutines, which I want to use in other cgi-programs.
The file with the subroutines is called 'test.cgi'.
How can I import the subroutines in 'test.cgi', that the routines are known
in the main program. I tried
use CGI 'test.cgi'
use CGI test
use test.cgi
use 'test.cgi'
all without success.

Please help
Thank you
TOM



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

Date: 23 Nov 2001 01:29:14 +0300
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Import own Subroutines in Perl
Message-Id: <87lmgyv3r9.fsf@abra.ru>

>>>>> On Thu, 22 Nov 2001 23:25:06 +0100, "Th.G" <th_gi@hotmail.com> said:

Th> Hi
Th> I wrote a file with subroutines, which I want to use in other cgi-programs.
Th> The file with the subroutines is called 'test.cgi'.
Th> How can I import the subroutines in 'test.cgi', that the routines are known
Th> in the main program. I tried
Th> use CGI 'test.cgi'
Th> use CGI test
Th> use test.cgi
Th> use 'test.cgi'
Th> all without success.

    require 'test.cgi'

or 

    do 'test.cgi'

See 'perldoc -tf require', 'perldoc -tf do' for explanation.

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)          TIV.net (http://tiv.net/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: Thu, 22 Nov 2001 21:12:53 GMT
From: "Mike Mackay [Ultrafusion]" <newsgroup_mike@ultrafusion.co.uk>
Subject: Prototype Mismatch Error
Message-Id: <pTdL7.275$hu4.50405@news1.cableinet.net>

Hi,
     I wrote a script that incorporates the use of the LWP::Simple module,
when I run the script, it works just as it should. However, when I check the
error log I notice that it's written an entry like the following :

Prototype mismatch: sub main::head vs ($) at /cgi-bin/track-status.pl line
38

What does a 'Prototype Mismatch' error mean? To stop these entries being
written I could turn off the warning switch on the shebang line, but for
good practice I would prefer to leave it in and try to eliminate this error.

Any suggestions?

Regards,
Mike Mackay.





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

Date: Thu, 22 Nov 2001 22:29:45 +0100
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: Prototype Mismatch Error
Message-Id: <Xns9161E4E672244Laocooneudoramailcom@62.153.159.134>

perldoc perldiag  tells us : 

Prototype mismatch: %s vs %s
    (S unsafe) The subroutine being declared or defined had previously
    been declared or defined with a different function prototype.



Lao


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

Date: Thu, 22 Nov 2001 21:41:45 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Prototype Mismatch Error
Message-Id: <3bfd7119.539$235@news.op.net>

In article <pTdL7.275$hu4.50405@news1.cableinet.net>,
Mike Mackay [Ultrafusion] <newsgroup_mike@ultrafusion.co.uk> wrote:
>Prototype mismatch: sub main::head vs ($) at /cgi-bin/track-status.pl line
>38

That means you defined your own 'head' function, and that is
conflicting with the 'head' function that the LWP::Simple module
provides.  You can probably ignore it with no problem.  if it bothers
you, try changing the 'use LWP::Simple' line to say

        use LWP::Simple 'get';

or, in place of 'get', list the names of the functions that you do
want.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: 22 Nov 2001 13:12:24 -0800
From: naughtynath@hotmail.com (Nathan Jones)
Subject: Renaming directories
Message-Id: <47a5c406.0111221312.58a4f8f1@posting.google.com>

This may be considered a newbie question, but ive been looking around
the newsgroups and documentations for perl, and i need a way to rename
directories from my script. is this possible using system() or another
method?


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

Date: Thu, 22 Nov 2001 21:32:39 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Renaming directories
Message-Id: <3bfd6ef7.4ec$2a2@news.op.net>

In article <47a5c406.0111221312.58a4f8f1@posting.google.com>,
Nathan Jones <naughtynath@hotmail.com> wrote:
>This may be considered a newbie question, but ive been looking around
>the newsgroups and documentations for perl, and i need a way to rename
>directories from my script. is this possible using system() or another
>method?

Yes.   You will probably want to use the rename() function.


-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: 23 Nov 2001 00:47:16 +0300
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Renaming directories
Message-Id: <87pu6av5p7.fsf@abra.ru>

>>>>> On Thu, 22 Nov 2001 21:32:39 GMT, mjd@plover.com (Mark Jason Dominus) said:

Mark> In article <47a5c406.0111221312.58a4f8f1@posting.google.com>,
Mark> Nathan Jones <naughtynath@hotmail.com> wrote:
>> This may be considered a newbie question, but ive been looking around
>> the newsgroups and documentations for perl, and i need a way to rename
>> directories from my script. is this possible using system() or another
>> method?

Mark> Yes.   You will probably want to use the rename() function.

Or even better

    use File::Copy;
    move($oldname, $newname);

It works across filesystems unlike rename().

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)          TIV.net (http://tiv.net/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: Thu, 22 Nov 2001 21:29:06 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: unicode with perl
Message-Id: <3bfd6e21.4d8$11c@news.op.net>

In article <l5VK7.5266$aW3.757055@news2-win.server.ntlworld.com>,
Qingning Huo <qhuo@ntlworld.com> wrote:
>I almost knows little of unicode, neither do I know how do change
>user input into unicode coding.  Can somebody tell me how I can
>achieve this target, or at least whether unicode is the right way?

It may be possible to do what you want using unicode.

        http://www.iki.fi/jhi/perlunitut.pod

may be helpful.  However, it describes the Perl 5.8 facilities.  Perl
5.6 may not support all the features described.  if you really want to
use unicode, you may want to wait for 5.8; the support in 5.6 is less
complete.  Perhaps this document will allow you to decide if it is
worth waiting.

Good luck.


-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Thu, 22 Nov 2001 14:08:19 -0600
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Using CGI.pm to obtain a list of params
Message-Id: <9tjp9v$ht8$1@slb4.atl.mindspring.net>

"Alan J. Flavell" <flavell@mail.cern.ch> wrote in message
news:Pine.LNX.4.30.0111221933330.9314-100000@lxplus023.cern.ch...
> On Nov 22, William Alexander Segraves inscribed on the eternal scroll:
>
> > Suppose you know the parameter names; but there are several hundred of
them.
>
> Then I'd conclude I had a user-interface nightmare on my hands, long
> before I even get to the point of invoking the CGI interface...
>

Thanks, Alan, for your insights.

With an Adobe Acrobat PDF form with fillable form fields, one may wish to
process the form data with a Perl script, hosted on a convenient web server,
to provide a means for a user with only Acrobat Reader to save the form
data.

My case is definitely not rhetorical, as a membership application form for
a lineage society, e.g., see http://segraves.tripod.com/index2.htm, may
indeed have several hundred form fields. In my case, transforming the
URL-encoded string of name-value pairs to FDF, the format that is understood
by PDF forms, can be done directly. Snippets of the Perl code follow:

 ...
read(STDIN, $formdat, $ENV{'CONTENT_LENGTH'});
# Required .FDF file headers
 ...
# Code to process Tags and Values
@namevals = split(/&/,$formdat);
foreach (@namevals) {
   print "<< ";
   print "/T \(";
   tr/+/ /;
   s/=/\) \/V \(/;
   s/%(..)/pack("C",hex($1))/ge;
   print "$_\) >>\n";
}
 ...
# Required .FDF file trailers

Having coded this directly as above, as well as using CGI.pm, I can see
advantages and disadvantages for both approaches. In this case, it is for a
"free" method of computer-assisted preparation of membership applications.
You see that I don't even have to know the names of the variables to employ
the above direct method.

> But if you insist:
>
> > Do you still advocate the approach you stated.
>
> Put them in a hash, of course.  It's a natural in Perl.
>

I agree. In fact, that's what is needed when the names of the variables must
be changed, so the data sets from one society can be exported to similar
application forms for other lineage societies.

> Hangonabit, they already come back from CGI.pm in a hash.  So what's
> the problem?  ;-)
>

No problem, really. If CGI.pm is available on the host web server, it is
sometimes preferable to use it. If CGI.pm is not available, then ...

Off Topic: Happy Thanksgiving to all!

Bill Segraves
Auburn, AL






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

Date: Thu, 22 Nov 2001 15:00:25 -0600
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Using CGI.pm to obtain a list of params
Message-Id: <9tjpa0$ht8$2@slb4.atl.mindspring.net>

"Jon Bell" <jtbell@presby.edu> wrote in message
news:Gn7s6w.GL7@presby.edu...
> The original poster wants to assign each param to a specific variable. If
> you have several hundred parameter names, then using my approach, you have
> to have several hundred statements of the form given above.
>
> Using an intermediate hash, you first have the loop shown by Brian, then
> you have several hundred statements like
>
>   my $FirstName = $Hash{'firstname'};
>
> I don't see much difference in terms of programmer convenience.
>

How so? I see a lot of difference. When I first started working with CGI.pm,
I wondered if i was going to have to write several hundred statements

In my case (see response to Alan F.), there's an advantage to letting Perl
and CGI.pm (if necessary) do the work. For the URL-encoded name-value pairs
from a submittal of form data from an Adobe Acrobat PDF form, I simply let
CGI.pm extract the variable names into an array, then use the variable names
as arguments as I print the entire transformed set of tag-value pairs in the
required format for FDF. See code snippet below:

 ...
# Code to process Tags and Values
$data = new CGI;
@names = $data->param;
foreach $name (@names) {
 print "<< /T \(" . $name . "\) /V \(" . param($name) . "\) >>\n";
}
 ...

Perl and CGI.pm experts on the NG will no doubt have better ways to do this.
I just saw no need in this case to use a hash, when an array suffices.

> Now, if I actually had several hundred parameters to deal with, I'd
> probably be using a design that didn't involve several hundred individual
> variables for them in the first place.  For example, I can imagine a
> form for inputting a rectangular table of numbers, with parameters named
> 'row0col0', 'row0col1', etc.  Then I could generate parameter names
> dynamically as needed, and extract the individual entries using
> $cgi->param().  If I needed to use each entry repeatedly, I'd probably
> use a loop to extract them into an array of arrays or something similar.
>

Jon, thanks for your ideas.

You may note that your naming scheme would play havoc with renaming data
items to move them to a different place, e.g., moving all of the lineage
data on a lineage society application form down by one generation to allow
reuse of a parent's data to do an application for a child. Example follows:

Suppose each generation has variable names, e.g.,

Note: This example did not use CGI.pm; but rather, includes snippets of code
used to transform URL- encoded name-value pairs, to another format directly
with Perl code, as in the example I used in the separate response to Alan
F.)

Name_G1
Address_G1
 ...
Name_G12
Address_G12

You can see that the following statements

# Move all gens down one position, allowing new Gen1 data to be inserted
   s/G12/G13/;
   s/G11/G12/;
   s/G10/G11/;
   s/G9/G10/;
 ...
   s/G2/G3/;
   s/G1/G2/;

could be employed to move all data down by a generation, except that some of
the data would be corrupted by the final statement. The best fix appears to
be to use enough characters in the variable name to allow efficient code to
accomplish the desired translation, e.g.,

Name_G01
Address_G01
 ...

fixes the problem in the variable names; and

 ...
   s/G01/G2/;

fixes the corruption that occurs because of the extraneous substitutions
from the previous format.

Jon, thanks again for your ideas. If form designers are aware of the means
which might be used after the form data is captured, they might produce
better forms.

In the cases I've cited, the forms had already been designed, leaving the
programmer with the problem of dealing with the poor design decisions made
earlier.

Bill Segraves
Auburn, AL



> --
> Jon Bell <jtbell@presby.edu>                        Presbyterian College
> Dept. of Physics and Computer Science        Clinton, South Carolina USA






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

Date: Thu, 22 Nov 2001 20:19:28 +0100
From: Philip Newton <pne-news-20011122@newton.digitalspace.net>
Subject: Re: using sendmail from perl
Message-Id: <6rgqvtkpa994m6726ii1lhu0ptejc3it03@4ax.com>

On 21 Nov 2001 09:03:35 -0800, wil@fbagroup.co.uk (Wiliam Stephens)
wrote:

>   $mail !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/)
>    { error_sub... }

How many people actually use address literals (or whatever they're
called) in email addresses? I think the only time I saw an address like
pne@[192.104.77.119] (with an IP address in square brackets) was when I
had to use something like that in a b0rked mail environment in our LAN.

And the {2,3}, of course, means that postmaster@example.info won't be
able to use his email address. Nor will postmaster@example.museum or
postmaster@example.aero.

Why not just do it correctly? For example, the regex in _Mastering
Regular Expressions_ matches email address with not more than two levels
(IIRC) of nested comments, and I believe Abigail's RFC::RFC822::Address
uses a parser rather than a regex.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Thu, 22 Nov 2001 19:39:55 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: variable scope
Message-Id: <3bfd548a.276$276@news.op.net>

In article <m3vgg27m4f.fsf@mumonkan.sunstarsys.com>,
Joe Schaefer  <joe+usenet@sunstarsys.com> wrote:
>But then you went on to say something silly about strictures 
>(which are a red herring here) and fictitious 20,000-line
>scripts with dozens of massive, nested foreach loops.  Sorry, 
>but programming languages were not designed to handle stupidity
>on such a massive scale.  The only appropriate action for 
>such an input is electro-shock therapy.

I haven't been paying too much attention to this thread, so I may have
the idea wrong, but from what I understood of Matt's argument, I
thought he made a reasonable point.

Whether to allow inner declarations to shadow outer ones is a language
design decision.  Most languages seem to allow it, but we shouldn't
let what is blind us to what might be.  If Matt is pointing out that
it can be hard for programmers to know, while writing inner blocks,
which variables they are implicitly importing from outer blocks, then
he's not the first person to do so.

For example, in Edsger Dijkstra's _A Discipline of Programming_, the
examples are written in a language in which lexical variables from
outer blocks do *not* automatically extend their scope to include
inner blocks.  You can import them, by an explicit declaration
('glovar'), or shadow them, by a different explicit declaration
('privar'), but you can't use any variable in a block that hasn't been
declared *in that block*.  Dijkstra explains in some detail why he
made this decision:

        The fact that this convention smoothly catered to the
        embedding of inner blocks within a "growing" environment . . .
        has for a long time been regarded as a sufficient
        justification for the priority of innermost
        declarations. . . .

        From a user's point of view, however, the convention is less
        attractive, for it makes the variables declared in his outer
        block extremely vulnerable. . . . Under the assumption that
        the programmer does not need to refer everywhere to anything
        he seems to be better served by more explicit means for
        restricting the textual scope of names than the more or less
        accidental re-declaration.
 
Even if it's only Matt and Dijkstra against the rest of the world, I'd
have to think twice before picking the rest of the world.

>> The thread has since descended into something else entirely.  All I
>> wanted was to know how the scoping of a foreach block works, and why
>> it wouldn't catch the multiple declarations as an error.  
>                                                    ^^^^^ 
>
>Grrr- it's *not* an error;

He didn't say it was.  He was using the subjunctive.  Growling seems
unnecessary.

Fact is, Perl *could* catch such declarations as errors; it just
doesn't.  It is a language design decision.

> rather a "potential" error, or just "bad style". 

Shadowing a loop index variable for its entire scope surely seems like
more than just bad style to me.  I think it is a lot more likely to be
an error than a lot of the things Perl warns about.  

> perl emits a _diagnostic warning_ if you ask it to.

I have not noted such a warning in this case.

>Now piss off.

Personal foul.  Two minutes in the penalty box.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Thu, 22 Nov 2001 21:04:29 GMT
From: Gisle Aas <gisle@ActiveState.com>
Subject: Re: variable scope
Message-Id: <m3snb67bss.fsf@ActiveState.com>

mjd@plover.com (Mark Jason Dominus) writes:

> Even if it's only Matt and Dijkstra against the rest of the world, I'd
> have to think twice before picking the rest of the world.

They seem to have a significant ally.  C# does not allow you to
redefine a variable in an inner scope.

-- 
Gisle Aas


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

Date: Thu, 22 Nov 2001 19:11:51 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Version of Perl at runtime
Message-Id: <X5cL7.440$Fbh.190852096@news.frii.net>

In article <3bfa6b84$0$8505$cc9e4d1f@news.dial.pipex.com>,
Peter Cameron  <peterca@ukgateway.net> wrote:
>Ilya Martynov wrote:
>
>>> $^V IS NOT a string like '5.6.0'. Let me quote 'perldoc perlvar':
>
>Thanks. I had read that, and it had obviously gone in one ear and out the 
>other, so to speak.
>
>Looks like I'm stuck with $] for >=5.005.
>

Consider using:

           if ($^V and $^V gt v5.6.0) {
               # new features supported
           }

Read about it in the perldelta manual page under the "Support for strings
represented as a vector of ordinals" section

-- 
    This space intentionally left blank


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

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


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