[29560] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 804 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 29 03:09:43 2007

Date: Wed, 29 Aug 2007 00:09:07 -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           Wed, 29 Aug 2007     Volume: 11 Number: 804

Today's topics:
        "use strict" in a module <larry.grant.dc@gmail.com>
    Re: "use strict" in a module <paduille.4061.mumia.w+nospam@earthlink.net>
    Re: File locking (Not Flock) <bill@ts1000.us>
    Re: File locking (Not Flock) <jurgenex@hotmail.com>
    Re: File locking (Not Flock) <paduille.4061.mumia.w+nospam@earthlink.net>
    Re: File locking (Not Flock) <allergic-to-spam@no-spam-allowed.org>
    Re: GD install problems <fraser.tim@gmail.com>
        Let's Unite Against Jews and Mongrels! <i_hate_jews@shiftmail.com>
    Re: Mac: Perl script that will run when double-clicked  amirkarger@gmail.com
    Re: Mac: Perl script that will run when double-clicked  amirkarger@gmail.com
        new CPAN modules on Wed Aug 29 2007 (Randal Schwartz)
        Reverse engineering OO perl code <allergic-to-spam@no-spam-allowed.org>
    Re: Reverse engineering OO perl code <mark.clementsREMOVETHIS@wanadoo.fr>
    Re: setting uid gid after fork <dummy@example.com>
    Re: Why can't I access an Array like this? <1usa@llenroc.ude.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 28 Aug 2007 22:09:05 -0000
From:  Larry <larry.grant.dc@gmail.com>
Subject: "use strict" in a module
Message-Id: <1188338945.816280.261750@r34g2000hsd.googlegroups.com>

The following code:

    package FooPkg;

    use strict;
    use Exporter ();
    use vars qw/@ISA @EXPORT/;
    @ISA = qw/Exporter/;
    @EXPORT = qw/$x $y $z/;
    use vars @EXPORT;

    $x = 5;

produces:

    Global symbol "$x" requires explicit package name at FooPkg.pm
line 10.
    FooPkg.pm had compilation errors.

However, if I change:

    use vars @EXPORT;

to

    use vars qw/$x $y $z/;

it works. But I would like to avoid repeating the qw/$x $y $z/ .  Why
won't the original version work?



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

Date: Tue, 28 Aug 2007 17:29:49 -0500
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: "use strict" in a module
Message-Id: <13d9g0rgbhj6521@corp.supernews.com>

On 08/28/2007 05:09 PM, Larry wrote:
> The following code:
> 
>     package FooPkg;
> 
>     use strict;
>     use Exporter ();
>     use vars qw/@ISA @EXPORT/;
>     @ISA = qw/Exporter/;
>     @EXPORT = qw/$x $y $z/;
>     use vars @EXPORT;
> 
>     $x = 5;
> 
> produces:
> 
>     Global symbol "$x" requires explicit package name at FooPkg.pm
> line 10.
>     FooPkg.pm had compilation errors.
> 
> However, if I change:
> 
>     use vars @EXPORT;
> 
> to
> 
>     use vars qw/$x $y $z/;
> 
> it works. But I would like to avoid repeating the qw/$x $y $z/ .  Why
> won't the original version work?
> 

"Use vars ..." is done at compile time, so @EXPORT is unset when the 
command is evaluated. For this to work, you must make sure that @EXPORT 
is set at compile time too:

     package FooPkg;

     use strict;
     use Exporter ();
     use vars qw/@ISA @EXPORT/;
     BEGIN {
         @ISA = qw/Exporter/;
         @EXPORT = qw/$x $y $z/;
     }
     use vars @EXPORT;

__HTH__

http://perldoc.perl.org/perlsub.html



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

Date: Tue, 28 Aug 2007 13:47:03 -0700
From:  Bill H <bill@ts1000.us>
Subject: Re: File locking (Not Flock)
Message-Id: <1188334023.345259.288200@r29g2000hsg.googlegroups.com>

On Aug 28, 2:48 pm, it_says_BALLS_on_your forehead
<simon.c...@fmr.com> wrote:
> On Aug 28, 2:39 pm, Bill H <b...@ts1000.us> wrote:
>
> > Is there a perl / linux way of locking a file? Not the FLOCK method
> > when you open a file, but setting the actual file as read only, or
> > read / write?
>
> my $cnt = chmod 0755, 'foo', 'bar';

I was hoping to avoid using permissions, but I guess there isn't a
simple read only - read / write attribute in linux like in DOS. Thanks



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

Date: Tue, 28 Aug 2007 21:00:26 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: File locking (Not Flock)
Message-Id: <K10Bi.1148$2p5.493@trndny05>

Bill H wrote:
> On Aug 28, 2:48 pm, it_says_BALLS_on_your forehead
> <simon.c...@fmr.com> wrote:
>> On Aug 28, 2:39 pm, Bill H <b...@ts1000.us> wrote:
>>
>>> Is there a perl / linux way of locking a file? Not the FLOCK method
>>> when you open a file, but setting the actual file as read only, or
>>> read / write?
>>
>> my $cnt = chmod 0755, 'foo', 'bar';
>
> I was hoping to avoid using permissions, but I guess there isn't a
> simple read only - read / write attribute in linux like in DOS. Thanks

You seem to be confused. File permissions/attributes are a matter of the 
file system, not the operating system.
Because DOS doesn't know any fileystem but FAT I guess you are talking about 
read/write attributes for FAT.
First of all of course you can use FAT also in Linux although no sane person 
would recommend to do so.
Now if you want the same functionality as FAT read/write attributes on a 
unixoid file system then file permissions are the correct answer as can 
easily be seen by the customary
     -rwxrwxrwx
They just provide a finer granularity of options which is an absolut 
requirement because of the multi-user nature of Linux.

If you want to set the file to read-only just remove the w for all three 
groups:
    -r-xr-xr-x

jue






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

Date: Tue, 28 Aug 2007 16:47:06 -0500
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: File locking (Not Flock)
Message-Id: <13d961cbct037c1@corp.supernews.com>

On 08/28/2007 03:47 PM, Bill H wrote:
> On Aug 28, 2:48 pm, it_says_BALLS_on_your forehead
> <simon.c...@fmr.com> wrote:
>> On Aug 28, 2:39 pm, Bill H <b...@ts1000.us> wrote:
>>
>>> Is there a perl / linux way of locking a file? Not the FLOCK method
>>> when you open a file, but setting the actual file as read only, or
>>> read / write?
>> my $cnt = chmod 0755, 'foo', 'bar';
> 
> I was hoping to avoid using permissions, but I guess there isn't a
> simple read only - read / write attribute in linux like in DOS. Thanks
> 

I'm not sure about this, but I think you'd do better locking the file 
this way:

my $cnt = chmod 0444, 'foo', 'bar';

Test if a file is "unlocked" this way:

if (-w 'foo') {
     ... write to 'foo' ...
}

Read these:
perldoc -f chmod
perldoc -f -w


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

Date: Wed, 29 Aug 2007 04:17:33 +0200 (CEST)
From: Jim Cochrane <allergic-to-spam@no-spam-allowed.org>
Subject: Re: File locking (Not Flock)
Message-Id: <slrnfd9lpq.bvn.allergic-to-spam@no-spam-allowed.org>

On 2007-08-28, Mumia W. <paduille.4061.mumia.w+nospam@earthlink.net> wrote:
> On 08/28/2007 03:47 PM, Bill H wrote:
>> On Aug 28, 2:48 pm, it_says_BALLS_on_your forehead
>> <simon.c...@fmr.com> wrote:
>>> On Aug 28, 2:39 pm, Bill H <b...@ts1000.us> wrote:
>>>
>>>> Is there a perl / linux way of locking a file? Not the FLOCK method
>>>> when you open a file, but setting the actual file as read only, or
>>>> read / write?
>>> my $cnt = chmod 0755, 'foo', 'bar';
>> 
>> I was hoping to avoid using permissions, but I guess there isn't a
>> simple read only - read / write attribute in linux like in DOS. Thanks
>> 
>
> I'm not sure about this, but I think you'd do better locking the file 
> this way:
>
> my $cnt = chmod 0444, 'foo', 'bar';
>
> Test if a file is "unlocked" this way:
>
> if (-w 'foo') {
>      ... write to 'foo' ...
> }
>
> Read these:
> perldoc -f chmod
> perldoc -f -w

I don't believe there's any way to make the implied set of operations
atomic (unless you add something, like semaphores), so it looks like
you'll have a potential race condition.

-- 



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

Date: Tue, 28 Aug 2007 22:11:10 -0000
From:  simulant <fraser.tim@gmail.com>
Subject: Re: GD install problems
Message-Id: <1188339070.812447.272180@g4g2000hsf.googlegroups.com>

> It's fairly simple to specify gcc as the compiler. Instead of 'perl
> Makefile.PL', run 'perl Makefile.PL CC=gcc'.
>
> But, as Ben has mentioned, it probably won't be that easy. There will likely
> be additional changes to %Config that need to be made.
>

Yeah, just tried the CC=gcc, and some of the options aren't compatible
with gcc:

gcc: unrecognized option `-qmaxmem=16384'
gcc: unrecognized option `-qnoansialias'
gcc: unrecognized option `-q32'
gcc: unrecognized option `-qlonglong'

Regarding the compiler that was used to build Perl on this server, it
was cc_r according to 'perl -V':
  Compiler:
    cc='cc_r', ccflags ='-D_ALL_SOURCE -D_ANSI_C_SOURCE -
D_POSIX_SOURCE -qmaxmem=16384 -qnoansialias -DUSE_NATIVE_DLOPEN -
DNEED_PTHREAD_INIT -q32 -D_LARGE_FILES -qlonglong',

Thanks for the responses.



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

Date: Tue, 28 Aug 2007 23:38:48 -0700
From:  Nenad Milicevic - The Aryan Serb <i_hate_jews@shiftmail.com>
Subject: Let's Unite Against Jews and Mongrels!
Message-Id: <1188369528.744865.11410@d55g2000hsg.googlegroups.com>

Rise up and shine, white sons and daughters
Rise up and shine, you gotta fight to part those waters
When we swim in the light, all will be okay
The black, yellow and brown man will wash away.
 ------------------------------
Let's break the chains of Jewish and black domination! Unite, white
brothers and sisters, and let's defeat those who oppress our white
heritage!

Our skin is our uniform!


Serbian Committee for Aryan Defence
Nenad Milicevic, executive
Usenet name: Raoul Endymion or Raul Endymion
ICQ 208030128
endymion@deadspam.com
endimion@myrealbox.com
Belgrade, Serbia


Corner for white supremacists: yu.forum.politika



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

Date: Wed, 29 Aug 2007 02:41:53 -0000
From:  amirkarger@gmail.com
Subject: Re: Mac: Perl script that will run when double-clicked
Message-Id: <1188355313.975123.173890@r29g2000hsg.googlegroups.com>

On Aug 22, 2:47 pm, Sherm Pendley <spamt...@dot-app.org> wrote:
> amirkar...@gmail.com writes:
> > When I double-clickon a Perl script, it opens in TextEdit. Can I tell
> >Macto run Perl scripts when they're double-clicked? The "Open With"
> > menu only lets me pick .apps, and perl isn't one.
>
> Open it with Terminal.app.
>
> sherm--
>

This seems to work only if I have no Terminal.apps open at the moment.
Or am I hallucinating?

-Amir



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

Date: Wed, 29 Aug 2007 04:17:58 -0000
From:  amirkarger@gmail.com
Subject: Re: Mac: Perl script that will run when double-clicked
Message-Id: <1188361078.041857.68590@57g2000hsv.googlegroups.com>

On Aug 22, 1:28 pm, amirkar...@gmail.com wrote:
> (This may be more aMacquestion than a Perl question.)
>
> When I double-clickon a Perl script, it opens in TextEdit. Can I tellMacto run Perl scripts when they're double-clicked? The "Open With"
> menu only lets me pick .apps, and perl isn't one.
>
> It's hard to get good Google results with words like "macdoubleclick
> perl". Is there something simple like Windows' file types?
>
> -Amir Karger

Apologies for self-responding. At least a partial answer is, if you
save the program with .command suffix (with #!/usr/bin/perl in the
first line), then when you double click on the file, it'll open a new
terminal window and run.
Problems:

1) You need to chmod +x the script, or it won't run. Which sort of
defeats the purpose of creating a double-clickable program, doesn't
it?

2) Depending on your defaults for Terminal.app, the window might or
might not close when the script finishes.

-Amir



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

Date: Wed, 29 Aug 2007 04:42:15 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Wed Aug 29 2007
Message-Id: <JnIqEF.7vq@zorch.sf-bay.org>

The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN).  You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.

Array-Suffix-0.5
http://search.cpan.org/~btmcinnes/Array-Suffix-0.5/
----
CGI-Application-Plugin-TmplInnerOuter-1.07
http://search.cpan.org/~leocharre/CGI-Application-Plugin-TmplInnerOuter-1.07/
----
Catalyst-Engine-Wx-0.02_02
http://search.cpan.org/~eriam/Catalyst-Engine-Wx-0.02_02/
Catalyst wxPerl Engine 
----
Catalyst-Manual-5.701002
http://search.cpan.org/~jrockway/Catalyst-Manual-5.701002/
The Catalyst developer's manual 
----
Class-Simple-0.10
http://search.cpan.org/~sullivan/Class-Simple-0.10/
Simple Object-Oriented Base Class 
----
Class-Simple-0.11
http://search.cpan.org/~sullivan/Class-Simple-0.11/
Simple Object-Oriented Base Class 
----
Clone-Fast-0.93
http://search.cpan.org/~wazzuteke/Clone-Fast-0.93/
Natively copying Perl data structures 
----
DBD-Multi-0.12
http://search.cpan.org/~dwright/DBD-Multi-0.12/
Manage Multiple Data Sources with Failover and Load Balancing 
----
Data-Transactional-1.0
http://search.cpan.org/~dcantrell/Data-Transactional-1.0/
data structures with RDBMS-like transactions 
----
Error-0.17009
http://search.cpan.org/~shlomif/Error-0.17009/
Error/exception handling in an OO-ish way 
----
File-LibMagic-0.85
http://search.cpan.org/~fitzner/File-LibMagic-0.85/
Perlwrapper for libmagic 
----
Gantry-3.51
http://search.cpan.org/~tkeefer/Gantry-3.51/
Web application framework for mod_perl, cgi, etc. 
----
HTML-Template-Default-1.03
http://search.cpan.org/~leocharre/HTML-Template-Default-1.03/
unless template file is on disk, use default hard coded 
----
HTML-Tested-ClassDBI-0.14
http://search.cpan.org/~bosu/HTML-Tested-ClassDBI-0.14/
Enhances HTML::Tested to work with Class::DBI 
----
HTTP-ProxySelector-Persistent-0.02
http://search.cpan.org/~mtrowbri/HTTP-ProxySelector-Persistent-0.02/
Locally cache and use a list of proxy servers for high volume, proxied LWP::UserAgent transactions 
----
IPC-MorseSignals-0.07
http://search.cpan.org/~vpit/IPC-MorseSignals-0.07/
Communicate between processes with Morse signals. 
----
Image-Magick-Thumbnail-PDF-1.11
http://search.cpan.org/~leocharre/Image-Magick-Thumbnail-PDF-1.11/
make thumbnail of a page in a pdf document 
----
Linux-SysInfo-0.07
http://search.cpan.org/~vpit/Linux-SysInfo-0.07/
Perl interface to the sysinfo(2) Linux system call. 
----
MIME-Lite-3.020
http://search.cpan.org/~rjbs/MIME-Lite-3.020/
low-calorie MIME generator 
----
Mail-Postini-0.13
http://search.cpan.org/~scottw/Mail-Postini-0.13/
Perl extension for talking to Postini 
----
OIS-0.01
http://search.cpan.org/~slanning/OIS-0.01/
Perl binding for the OIS C++ input framework 
----
PDFLib-PPS-0.04
http://search.cpan.org/~montuori/PDFLib-PPS-0.04/
PDFLib Personalization Server OO Interface 
----
PerlIO-via-ANSIColor-0.04
http://search.cpan.org/~masanorih/PerlIO-via-ANSIColor-0.04/
PerlIO layer for Term::ANSIColor 
----
PowerTools-Upload-Blob-0.02
http://search.cpan.org/~gbshouse/PowerTools-Upload-Blob-0.02/
----
PowerTools-Upload-File-0.02
http://search.cpan.org/~gbshouse/PowerTools-Upload-File-0.02/
Additional Perl tool for Apache::ASP data uploading 
----
Proc-Wait3-0.03
http://search.cpan.org/~ctilmes/Proc-Wait3-0.03/
Perl extension for wait3 system call 
----
Regexp-Wildcards-0.07
http://search.cpan.org/~vpit/Regexp-Wildcards-0.07/
Converts wildcard expressions to Perl regular expressions. 
----
SMS-Send-DE-MeinBMW-0.03
http://search.cpan.org/~borisz/SMS-Send-DE-MeinBMW-0.03/
An SMS::Send driver for the www.meinbmw.de website 
----
Template-Recall-0.11
http://search.cpan.org/~gilad/Template-Recall-0.11/
"Reverse callback" templating system 
----
Test-AbstractMethod-0.01
http://search.cpan.org/~claesjac/Test-AbstractMethod-0.01/
Make sure your abstract methods croaks like they should 
----
Text-Positional-Ngram-0.5
http://search.cpan.org/~btmcinnes/Text-Positional-Ngram-0.5/
----
Tie-STDOUT-1.03
http://search.cpan.org/~dcantrell/Tie-STDOUT-1.03/
intercept writes to STDOUT and apply user-defined functions to them. 
----
Tripletail-0.31
http://search.cpan.org/~hio/Tripletail-0.31/
Tripletail, Framework for Japanese Web Application 
----
URI-Template-0.09
http://search.cpan.org/~bricas/URI-Template-0.09/
Object for handling URI templates 
----
VCI-0.0.1
http://search.cpan.org/~mkanat/VCI-0.0.1/
A generic interface for interacting with various version-control systems. 
----
VRML-1.10
http://search.cpan.org/~hpalm/VRML-1.10/
Specification independent VRML methods (1.0, 2.0, 97) 
----
VRML-1.10de
http://search.cpan.org/~hpalm/VRML-1.10de/
spezfikationsunabh?ngige VRML-Methoden (1.0, 2.0, 97) 
----
Variable-Magic-0.04
http://search.cpan.org/~vpit/Variable-Magic-0.04/
Associate user-defined magic to variables from Perl. 
----
WWW-Google-PageRank-0.14
http://search.cpan.org/~ykar/WWW-Google-PageRank-0.14/
Query google pagerank of page 
----
WWW-Spamla-0.02
http://search.cpan.org/~gray/WWW-Spamla-0.02/
interface to Spam.la 
----
Web-Scraper-0.11
http://search.cpan.org/~miyagawa/Web-Scraper-0.11/
Web Scraping Toolkit inspired by Scrapi 
----
WebService-Validator-HTML-W3C-0.22
http://search.cpan.org/~struan/WebService-Validator-HTML-W3C-0.22/
Access the W3Cs online HTML validator 


If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.

This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
  http://www.stonehenge.com/merlyn/LinuxMag/col82.html

print "Just another Perl hacker," # the original

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Wed, 29 Aug 2007 04:24:55 +0200 (CEST)
From: Jim Cochrane <allergic-to-spam@no-spam-allowed.org>
Subject: Reverse engineering OO perl code
Message-Id: <slrnfd9m7k.bvn.allergic-to-spam@no-spam-allowed.org>

I suspect this question has been asked before, and I suspect the answer
may be "It's not practical.", but from a couple quick searches in
google groups I could not find anything.  (Maybe I picked the wrong
search words.)

My question is Are there any tools available to effectively reverse
engineer existing, relatively well-constructed OO Perl code to produce
(or aid in producing) design artifacts/documentation, such as UML
diagrams/code or diagrams in other notations?  (Free, FOSS, or not-free)

It seems that this would be very valuable in some situations, but I've
not seen any evidence of such tools.  Perhaps this is because the task
is too complex to be done for real code.


Thanks.

-- 



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

Date: Wed, 29 Aug 2007 07:27:59 +0200
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: Reverse engineering OO perl code
Message-Id: <46d503e2$0$27388$ba4acef3@news.orange.fr>

Jim Cochrane wrote:
> I suspect this question has been asked before, and I suspect the answer
> may be "It's not practical.", but from a couple quick searches in
> google groups I could not find anything.  (Maybe I picked the wrong
> search words.)
> 
> My question is Are there any tools available to effectively reverse
> engineer existing, relatively well-constructed OO Perl code to produce
> (or aid in producing) design artifacts/documentation, such as UML
> diagrams/code or diagrams in other notations?  (Free, FOSS, or not-free)
> 
> It seems that this would be very valuable in some situations, but I've
> not seen any evidence of such tools.  Perhaps this is because the task
> is too complex to be done for real code.

There are a number out there, but the only one with which I am familiar 
is Autodia.

Mark


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

Date: Tue, 28 Aug 2007 20:25:11 GMT
From: "John W. Krahn" <dummy@example.com>
Subject: Re: setting uid gid after fork
Message-Id: <Hw%Ai.2345$bO6.1667@edtnps89>

hakim wrote:
> 
> I have the following script, and it gets started as root:
> 
> #!/usr/bin/perl -w
> 
> use strict;
> use POSIX;
> 
> my $uid;
> my $gid;
> 
> if(($uid = getpwnam("iday")) && ($gid = getgrnam("iday"))) {
>         print "iday:\n";
>         print "UID = $uid\n";
>         print "GID = $gid\n";
>         $< = $> = $uid;
>         $( = $) = $gid;
> } elsif(($uid = getpwnam("idayserv")) && ($gid =
> getgrnam("idayserv"))) {
>         print "idayserv:\n";
>         print "UID = $uid\n";
>         print "GID = $gid\n";
> } else {
>         print "Sorry\n";
> }
> 
> 
> while(1) {
>         sleep 10;
> }
> 
> 
> With "ps -ax -o euid,egid,user,group,command":
>  EUID  EGID USER     GROUP    COMMAND
> 1001     0 iday     root     /usr/bin/perl -w ./test
> 
> The user iday has uid 1001 and gid 1001 (groupname iday), but that
> does not show up.
> 
> How can I change the process uid and gid for example like an apache
> server does?

Once you change the UID you don't have permission to then change the GID so 
change:

         $< = $> = $uid;
         $( = $) = $gid;

To:

         $( = $) = $gid;
         $< = $> = $uid;

And change the GID first.



John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


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

Date: Wed, 29 Aug 2007 01:28:11 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Why can't I access an Array like this?
Message-Id: <Xns999ADA5FA15B6asu1cornelledu@127.0.0.1>

Bill H <bill@ts1000.us> wrote in
news:1188175383.166812.89070@19g2000hsx.googlegroups.com: 

> SNAME0001, SPASS0001, FRONT0001, BACK0001, TITLE0001, COPY0001,
> TOC0001, FOR0001, ACK0001, CHAP0001 and the person using the form can
> add / remove groups of fields (these 10 fields all ending with the
> same numbers). I add and remove the fields dynamically in the perl
> script to the web page, so I only know the starting letters of the
> field (ie SNAME, SPASS, FRONT etc) and how many groups are on the
> page. So I have to work my way through the groups of fields using a
> for loop (hence the need for the 0001 - ????) to build the page.

No, there is no need for that. The following script is *very* quick and 
dirty but it might be useful:

#!perl

use strict;
use warnings;

use CGI;
use Data::Dumper;
use HTML::Entities;
use HTML::Template;

my $tmpl = <<EO_TMPL;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
    "http://www.w3.org/TR/html4/strict.dtd"><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Field Adder Test</title>
</head>
<body>
<h1>Test Form</h1>
<form method="POST">
<TMPL_LOOP FIELDS>
<p><input name="myfield" value="<TMPL_VAR MYFIELD_VALUE>"></p>
</TMPL_LOOP>
<p><input type="submit" name="action" value="Submit">
<input type="submit" name="action" value="Add Field"></p>
</form>
</body>
</html>
EO_TMPL

my $cgi = CGI->new;

my $action = $cgi->param('action');

if ( $action eq 'Add Field' ) {
    handle_add_field();
}
elsif ( $action eq 'Submit' ) {
    handle_dump_form();
}
else {
    handle_show_form();
}


sub handle_show_form {
    my $template = HTML::Template->new( scalarref => \$tmpl );
    $template->param( FIELDS => [ { MYFIELD_VALUE => q{} } ] );

    print $cgi->header('text/html'), $template->output;
}

sub handle_dump_form {
    print $cgi->header('text/plain'), Dumper( $cgi );
}

sub handle_add_field {
    my @fields_loop;

    push @fields_loop, map { 
        { MYFIELD_VALUE => encode_entities( $_ ) }
    } $cgi->param('myfield');

    push @fields_loop, { MYFIELD_VALUE => q{} };

    my $template = HTML::Template->new( scalarref => \$tmpl );
    $template->param( FIELDS => \@fields_loop );

    print $cgi->header('text/html'), $template->output;
}

__END__




-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>



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

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


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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

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

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


------------------------------
End of Perl-Users Digest V11 Issue 804
**************************************


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