[17740] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5160 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 20 14:05:47 2000

Date: Wed, 20 Dec 2000 11:05:19 -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: <977339119-v9-i5160@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 20 Dec 2000     Volume: 9 Number: 5160

Today's topics:
        "use" inside a subroutine bdesany@my-deja.com
    Re: "use" inside a subroutine nobull@mail.com
    Re: (Beginner) Simple stuff not working (Arek P)
        ??POST fails, but GET works jrogers42@hotmail.com
    Re: access a shared drive stong123@my-deja.com
        assigning elements to ARGV from within a script <michael@datahost.com>
    Re: assigning elements to ARGV from within a script (Tom Christiansen)
    Re: assigning elements to ARGV from within a script (Abigail)
    Re: beginner question <iltzu@sci.invalid>
    Re: Boolean context in grep <matt@cipherdesign.com>
        calling script from browser with arguments <brill@hfhmn.org>
    Re: calling script from browser with arguments <samuel@knm-e.se>
    Re: calling script from browser with arguments nobull@mail.com
    Re: changing array contents as you iterate over it <iltzu@sci.invalid>
    Re: existing files <ruben@www2.mrbrklyn.com>
    Re: File::Find - meaning of 'symlinks'? <nospam.newton@gmx.li>
        getting output from net::telnet <xuvetyn@my-deja.com>
        GNU Info-Zip & LWP (BUCK NAKED1)
    Re: GNU Info-Zip & LWP nobull@mail.com
        Help with REGEXP and templates! <none@none.ca>
    Re: Home Directory <ruben@www2.mrbrklyn.com>
    Re: Home Directory nobull@mail.com
    Re: How can I access the checkbox value of a form in Pe <s997659@ee.cuhk.edu.hk>
    Re: How can I access the checkbox value of a form in Pe nobull@mail.com
        How do I use form email anver@my-deja.com
    Re: How do I use form email nobull@mail.com
    Re: how to invalidate a hash value during a foreach loo <bart.lateur@skynet.be>
    Re: how to invalidate a hash value during a foreach loo (Tad McClellan)
        html tag stripper needed. <basurero@jazzfree.com>
    Re: html tag stripper needed. (Tad McClellan)
    Re: html tag stripper needed. (Richard Zilavec)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 20 Dec 2000 16:22:50 GMT
From: bdesany@my-deja.com
Subject: "use" inside a subroutine
Message-Id: <91qmce$72r$1@nnrp1.deja.com>

If you have a "utility" module full of subroutines that are called from
sundry scripts, can you reduce overhead by placing "use (module)"
statements inside the subroutines instead of at the beginning of the
module? I am wondering if this would be a good way to make sure only
the specific external modules required for the sub I am calling are
actually loaded up when that sub is called.

Since "use (module)" is really "BEGIN {...}", I guess I am really
asking if BEGIN blocks work the same in a subroutine as they do at
the "top level scope" of a package, or if putting them in a subroutine
in a module somehow delays it until that subroutine is called.

I'm guessing it doesn't make a difference, but its intuition not
reason - could someone enlighten me? And maybe offer an alternative
solution (short of lots of little modules instead of one big one)?


Sent via Deja.com
http://www.deja.com/


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

Date: 20 Dec 2000 17:54:53 +0000
From: nobull@mail.com
Subject: Re: "use" inside a subroutine
Message-Id: <u9wvcvyo42.fsf@wcl-l.bham.ac.uk>

bdesany@my-deja.com writes:

> If you have a "utility" module full of subroutines that are called from
> sundry scripts, can you reduce overhead by placing "use (module)"
> statements inside the subroutines instead of at the beginning of the
> module?

No.

> Since "use (module)" is really "BEGIN {...}", I guess I am really
> asking if BEGIN blocks work the same in a subroutine as they do at
> the "top level scope" of a package,

They do.

> I'm guessing it doesn't make a difference, but its intuition not
> reason - could someone enlighten me? And maybe offer an alternative
> solution (short of lots of little modules instead of one big one)?

Like you say "use module" is really just a shorthand for "BEGIN {
require module; import module; }".

If you want to do the same thing but without the BEGIN then,
err... err... how can I put this... you should do the same thing but
without the BEGIN.  Of course this'll mean you can't take advantage of
any prototypes or other compile-time effects that are exported by the
module.

> Sent via Deja.com
> http://www.deja.com/

Did you know deja.com has a Usenet search engine?  This is not the
first thread on this subject.  It's not even the first this week.
Actually I doubt it's even the second.

> And maybe offer an alternative solution (short of lots of little
> modules instead of one big one)?

perldoc AutoLoader

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Wed, 20 Dec 2000 12:19:24 EST
From: Arek@nospam.tv (Arek P)
Subject: Re: (Beginner) Simple stuff not working
Message-Id: <91qpms$2es5$1@earth.superlink.net>

glad to learn this from someone who knows his stuff...(have seen Your
other postings).
I hear You about the double negation, english is not my first lang,
will be more carefull next time....

				ArekP


On Tue, 19 Dec 2000 11:11:23 -0500, tadmc@metronet.com (Tad McClellan)
wrote:

 

>Arek P <Arek@nospam._pietruszewski_.com> wrote:
>
>>BTW, the #! notation is not almost never used in Win machines,
>                         ^^^        ^^^^^
>
>(I figure you wanted only one negative in there?)
>
>
>Every good Perl programmer enables warnings.
>
>You can enable warnings on the she-bang line (even in windoze).
>
>Therefore, lots of "Win machines" do in fact use the "#! notation"
>
>:-)
>
>
>
>-- 
>    Tad McClellan                          SGML consulting
>    tadmc@metronet.com                     Perl programming
>    Fort Worth, Texas



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

Date: Wed, 20 Dec 2000 16:41:37 GMT
From: jrogers42@hotmail.com
Subject: ??POST fails, but GET works
Message-Id: <91qng0$7tu$1@nnrp1.deja.com>

I have a cgi script that begins with a html document that has a form in
it with method = POST. It calls a perl script. In that perl script is
if the conditions are met it must create another html form with method
= POST. Now, when I do this the script hangs at the point when it
creates the second form. When, I use GET on the html it works, but
hangs after the second form. When I use GET for both it works fine. But
for security reasons I need to use POST. Any help??


Sent via Deja.com
http://www.deja.com/


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

Date: Wed, 20 Dec 2000 16:41:33 GMT
From: stong123@my-deja.com
Subject: Re: access a shared drive
Message-Id: <91qnfs$7ts$1@nnrp1.deja.com>

thanks Jeff, it worked!

cheers!
st


Sent via Deja.com
http://www.deja.com/


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

Date: Wed, 20 Dec 2000 09:39:35 -0700
From: "Michael Stearns" <michael@datahost.com>
Subject: assigning elements to ARGV from within a script
Message-Id: <Fe606.1035$lz1.187087@news.uswest.net>

Hello:

When I do something like this from the command line:

perl -pi -e 's^foo^bar^gs'*/*.html

the wild cards are evaluated and all pages that match */*.html are
processed.


I would like to do something similar from within a perl script.

Is there a way to set the elements of ARGV in my script without passing them
from the command line, so that the wildcards are still evaluated?

My current approach would be to use the readdir command and loop through the
directories to get all my files into an array. I think this would work, but
I was wondering if there is another recommended approach for something like
this?

Thanks,
Michael








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

Date: 20 Dec 2000 11:02:59 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: assigning elements to ARGV from within a script
Message-Id: <3a40f453$1@cs.colorado.edu>

In article <Fe606.1035$lz1.187087@news.uswest.net>,
Michael Stearns <michael@datahost.com> wrote:
>When I do something like this from the command line:
>
>	perl -pi -e 's^foo^bar^gs' */*.html
>
>the wild cards are evaluated and all pages that match */*.html are
>processed.

>I would like to do something similar from within a perl script.

>Is there a way to set the elements of ARGV in my script without passing them
>from the command line, so that the wildcards are still evaluated?

    #!/usr/bin/perl -pi
    BEGIN { @ARGV = glob("*/*.html") unless @ARGV }
    s/foo/bar/gs;

Or

    local *ARGV;
    local @ARGV = glob("*/*.html");
    local $^I = ".orig";  
    while (<>) { 
	s/foo/bar/gs;
	print;
    }

If you won't want the origes, then use 

    local $^I = "";  

instead.

--tom


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

Date: 20 Dec 2000 18:47:47 GMT
From: abigail@foad.org (Abigail)
Subject: Re: assigning elements to ARGV from within a script
Message-Id: <slrn941vmj.7r0.abigail@tsathoggua.rlyeh.net>

Tom Christiansen (tchrist@perl.com) wrote on MMDCLXVIII September
MCMXCIII in <URL:news:3a40f453$1@cs.colorado.edu>:
:} In article <Fe606.1035$lz1.187087@news.uswest.net>,
:} Michael Stearns <michael@datahost.com> wrote:
:} >When I do something like this from the command line:
:} >
:} >	perl -pi -e 's^foo^bar^gs' */*.html
:} >
:} >the wild cards are evaluated and all pages that match */*.html are
:} >processed.
:} 
:} >I would like to do something similar from within a perl script.
:} 
:} >Is there a way to set the elements of ARGV in my script without passing them
:} >from the command line, so that the wildcards are still evaluated?
:} 
:}     #!/usr/bin/perl -pi
:}     BEGIN { @ARGV = glob("*/*.html") unless @ARGV }
:}     s/foo/bar/gs;


Or this:

    #!/opt/perl/bin/perl -pi
    BEGIN {@ARGV = map {glob} @ARGV}
    s/foo/bar/gs;
    __END__

and call the program as:

    program '*/*.html'


Having the application expand the wildcards instead of the shell might
be useful if expanding by the shell leads to hitting command line length
limits.




Abigail
-- 
map{${+chr}=chr}map{$_=>$_^ord$"}$=+$]..3*$=/2;        
print "$J$u$s$t $a$n$o$t$h$e$r $P$e$r$l $H$a$c$k$e$r\n";


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

Date: 20 Dec 2000 18:13:50 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: beginner question
Message-Id: <977335762.16103@itz.pp.sci.fi>

In article <3A3F776D.1F271D37@pitt.edu>, Martin Schmidt wrote:
>Hi,
>I'm writing a perl program that uses a few array variables named
>something like
>@array1, @array2, @array3

Name them @{ $array[0] }, @{ $array[1] }, @{ $array[2] } instead.

>I want to access them using a variable to represent the number.
>$num = 1;

  push @{ $array[$num] }, $valueA;
  $array[$num][0] = $valueB;

Then read the perllol and perldsc manual pages to understand it.

-- 
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real!  This is a discussion group, not a helpdesk.  You post
 something, we discuss its implications.  If the discussion happens to
 answer a question you've asked, that's incidental." -- nobull in clpm



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

Date: Wed, 20 Dec 2000 17:05:53 +0000
From: Matt Venn <matt@cipherdesign.com>
Subject: Re: Boolean context in grep
Message-Id: <htoq19.ne5.ln@server.localnet>

I think what I was trying to say was:

How do I get something in list context when the operator is scalar?
For example:

$a = "abc";
$a .= ("abc"=~/(...)/);
print $a;	#prints abc1

In my previous post, I wanted to get ($a=~/(pattern)/) in list context so
that I would have access to the matched pattern.

And doing this:

($a=~/(pattern)/)[0]

Is the answer.

Sorry for any confusion caused.
Matt


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

Date: Wed, 20 Dec 2000 10:04:08 -0600
From: "Daniel J. Brill" <brill@hfhmn.org>
Subject: calling script from browser with arguments
Message-Id: <3A40D877.4660F6B8@hfhmn.org>

Hi,

I'm thinking this qualifies as a newbie question.  How can I call a
script with arguments from a browser window?

From the DOS command prompt I issue the following command calling the
following script:

perl test.pl foo

    #!/usr/local/bin/perl
    # script for test.pl
    print "test to begin \n";
    $testvar = $ARGV[0];
    print "$testvar \n";
    print "test complete";

Which gives the output

    test to begin
    foo
    test complete

How do I send the argument "foo" from IE, Netscape, etc. to run this as
a CGI?

Thanks,

Dan



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

Date: Wed, 20 Dec 2000 17:35:38 +0100
From: "Samuel Rydén" <samuel@knm-e.se>
Subject: Re: calling script from browser with arguments
Message-Id: <vg506.115$hH5.168@nntpserver.swip.net>

> I'm thinking this qualifies as a newbie question.  How can I call a
> script with arguments from a browser window?

http://www.server.com/cgi-bin/script.cgi?arguments

common in place of "arguments" after the question mark are
1, argname1=value1&argname2=value2&argname3=value3 eetc.
2, + instead of &

it's your choice.

The arguments then are available from $ENV{QUERY_STRING} instead of the
@ARGV array. You have to split and seperate them yourself, thus the silly
syntax.


> From the DOS command prompt I issue the following command calling the
> following script:
>
> perl test.pl foo
>
>     #!/usr/local/bin/perl
>     # script for test.pl
>     print "test to begin \n";
>     $testvar = $ARGV[0];
>     print "$testvar \n";
>     print "test complete";
>
> Which gives the output
>
>     test to begin
>     foo
>     test complete
>
> How do I send the argument "foo" from IE, Netscape, etc. to run this as
> a CGI?


#!/usr/bin/perl

print "Content-Type: text/plain\n\n" # http header. Change to text/html to
make output html instead of plain text.

print "\$ENV{QUERY_STRING} = \"$ENV{QUERY_STRING}\"\n";



regards,


- Sam




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

Date: 20 Dec 2000 18:04:29 +0000
From: nobull@mail.com
Subject: Re: calling script from browser with arguments
Message-Id: <u9vgsfyno2.fsf@wcl-l.bham.ac.uk>

"Samuel Rydén" <samuel@knm-e.se> writes:

> http://www.server.com/cgi-bin/script.cgi?arguments
> 
> common in place of "arguments" after the question mark are
> 1, argname1=value1&argname2=value2&argname3=value3 eetc.

> The arguments then are available from $ENV{QUERY_STRING} instead of the
> @ARGV array. You have to split and seperate them yourself,

Don't take "you have to ... yourself" too literally. The instuctions
for a self-assembly cupboard may say you have to make holes in a bit
of wood yourself.  This doesn't mean to say that have to make the
holes with your fingers - you are permitted to use power tools.  The
appropriate power tool in this case is CGI.pm.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 20 Dec 2000 18:58:03 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: changing array contents as you iterate over it
Message-Id: <977337831.25277@itz.pp.sci.fi>

In article <91olm7$k83$1@nnrp1.deja.com>, bdesany@my-deja.com wrote:
>
>The array has around 25000 elements (and will grow much larger in the
>future as more data can be incorporated into it), and it is made on-the-
>fly by calling the "vertices" method on a Graph::Undirected object. The
>test whereby the array splicing is determined is a depth first search
>using whatever vertex (array element) foreach happens to pick at the
>start of the loop. All the vertices returned during the dfs need to
>then be removed from the array so that another dfs is not done on them
>(which would be multiply redundant and extremely time consuming).
>
>Eventually, the array gets reduced to zero elements as each dfs set is
>discovered its members are removed from the array.

If I understand you correctly, one solution would be to use a hash:

  my %vertices;
  @vertices{ $graph->vertices() } = ();

  while (%vertices) {
      my $vertex = each %vertices;  # get just one element..
      keys %vertices;               # ..and reset iterator

      my @found = depth_first_search($vertex);
      delete @vertices{ @found };   # assumes @found contains $vertex
  }

Does that solve your problem?  Or did I miss something?

-- 
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real!  This is a discussion group, not a helpdesk.  You post
 something, we discuss its implications.  If the discussion happens to
 answer a question you've asked, that's incidental." -- nobull in clpm




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

Date: Wed, 20 Dec 2000 16:41:18 GMT
From: "Brooklyn Linux Solutions CEO" <ruben@www2.mrbrklyn.com>
Subject: Re: existing files
Message-Id: <Oi506.154211$DG3.3093119@news2.giganews.com>

In article <91m2vb$st$1@dinkel.civ.utwente.nl>, "iLs" <iLs@cyberdude.com>
wrote:
Look up perldoc perlop

You need a unary operator -e

Ruben
http://www.mrbrklyn.com
> I was trying to write a script that could copy files from one dir to
> another, but only if the file doesn't already exist in de second dir.
> 
> How can I check for the file to exist ?
> 
> greets,
> 
> Rob
> 
> 
>


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

Date: Wed, 20 Dec 2000 17:46:34 +0100
From: "Philip 'Yes, that's my address' Newton" <nospam.newton@gmx.li>
Subject: Re: File::Find - meaning of 'symlinks'?
Message-Id: <gnn14t87271ju5715nhdp5ls5s4luf5d4g@4ax.com>

On Wed, 20 Dec 2000 12:56:38 +0100, "tim allen" <timallen449@coldmail.com>
wrote:

>     if (m/\b$srch\b/) {

You almost certainly want \Q$srch\E here.

>   find \&findit, "d:";

And you probably want "d:/" here.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
If you're not part of the solution, you're part of the precipitate.


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

Date: Wed, 20 Dec 2000 18:28:48 GMT
From: entropy <xuvetyn@my-deja.com>
Subject: getting output from net::telnet
Message-Id: <91qtol$dpt$1@nnrp1.deja.com>

having a small problem w/ net::telnet.
i'm using it to telnet to a server, then starting some services. now, i
want to do some things based on if the commands worked or not, therefore
i need to do a regexp on the output. but strangely, it's not working for
most commands. for example:

my @lines = $t->cmd("/usr/bin/who");
print @lines;

returns something like:

user1     lft0        Dec 05 12:04
user2     pts/0       Dec 20 09:08    (172.23.1.153)
user3     pts/1       Dec 20 09:08    (172.23.1.153)
user4     pts/2       Dec 20 09:08    (172.23.1.153)

but:
my @lines = $t->cmd("/local/apache/bin/apachectl start");
print @lines;

returns nothing (yes, the command works and returns output when run
manually from the command-line.

any thoughts?

thanks in advance


Sent via Deja.com
http://www.deja.com/


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

Date: Wed, 20 Dec 2000 10:00:02 -0600 (CST)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: GNU Info-Zip & LWP
Message-Id: <12407-3A40E592-16@storefull-247.iap.bryant.webtv.net>

A Big Thank You to those who tried to help me with the problem that I
was having grabbing and storing a URL. Come to find out, my webhost had
a bad install of libwww-perl, and I had it installed incorrectly
locally, too. When I finally got libwww-perl-5.48 installed correctly,
everything works fine now.

Now to another problem. I have been able to successfully use Archive/Zip
and Archive/Tar to uncompress files. However, I prefer the easier
methods like "gunzip file" or "zip -o file"; but these won't work at my
webhost. Why?

Is it because they don't have Info-Zip installed? If so, can I install
Info-Zip into a local directory? and where do I find an Apache FreeBSD
version of it to download?

Thanks,
Dennis



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

Date: 20 Dec 2000 18:31:56 +0000
From: nobull@mail.com
Subject: Re: GNU Info-Zip & LWP
Message-Id: <u9puinymeb.fsf@wcl-l.bham.ac.uk>

dennis100@webtv.net (BUCK NAKED1) writes:

> Newsgroups: comp.lang.perl.misc

> Now to another problem.

[ snip question about gzip, info-zip and NetBSD but not Perl ]

Each time you start to address "another problem" think from scratch
"what is this problem related to?".  If the list of things it is
related to does not include Perl then don't post here.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Wed, 20 Dec 2000 14:11:50 -0400
From: "k" <none@none.ca>
Subject: Help with REGEXP and templates!
Message-Id: <VD606.9893$t3.15263@tor-nn1.netcom.ca>

I have a Perl object that I use to collect CGI data (form variables, env
variables, cookies, session data, etc). This object is set up to allow for
subobject as follows:

$REQUEST->get()
$REQUEST->form->get()
$REQUEST->session->get()
$REQUEST->session->shopcart->get()

Sub objects can be added at any time, and each subobject can have it's own
subobjects as "session" does.

I would now like to provide template access to these namespaces in the
following way:

  $template = "My name is REQUEST.form.FullName";

In the above, "REQUEST.form.FullName" is parsed out by a REGEXP and
translated into $REQUEST->form->get('FullName')  by a subroutine a have
written. I have created the following REGEXP to do this (Note: In previous
scripts I have surrounded my variables in [delimiters] - I want to avoid
doing this here)

$template =~ s/(REQUEST)\.(\w*|\.*)(\W|$)/&parseVarCall($1,$2).$3/ges;

I am trying to tell the REGEXP:

  - Start matching at REQUEST.
  - Match all letters (\w) or periods (\.) until you hit a non-word
character (or the end of the string).

This of course doesn't work because periods ARE non-word characters, so it
stops at the first period. Is there any way to tell the REGEXP \W command to
ignore the periods, or maybe another way of acheiving this effect?

Greatly appreciated,
kh






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

Date: Wed, 20 Dec 2000 16:54:55 GMT
From: "Brooklyn Linux Solutions CEO" <ruben@www2.mrbrklyn.com>
Subject: Re: Home Directory
Message-Id: <zv506.154229$DG3.3094335@news2.giganews.com>

In article <91m7n6$kjv$1@nnrp1.deja.com>, mgrime@my-deja.com wrote:
$home = $ENV{HOME};

Ruben


> Hello,
> 
> Can anyone tell me if there is there any way to reference your home
> directory as the tilde (~) does in shell?
> 
> Thanks, Mike
> 
> 
> Sent via Deja.com http://www.deja.com/


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

Date: 20 Dec 2000 18:23:21 +0000
From: nobull@mail.com
Subject: Re: Home Directory
Message-Id: <u9r933ymsm.fsf@wcl-l.bham.ac.uk>

"Brooklyn Linux Solutions CEO" <ruben@www2.mrbrklyn.com> writes upside
down without timming the message he is responding to.  Actually it is
worse still: he actually attributes his answer to the person asking
the question.

Jeopardectomy performed:

> In article <91m7n6$kjv$1@nnrp1.deja.com>, mgrime@my-deja.com wrote:
> > Can anyone tell me if there is there any way to reference your home
> > directory as the tilde (~) does in shell?
>
> $home = $ENV{HOME};

This answer is not as complete as the answer in the FAQ.  When
responding to questions that are answered in the FAQ you should always
point out that they are answered in the FAQ.  Unless you feel the
answer in the FAQ is incomplete you should not do anything else as
forcing the OP to read the FAQ will help them (and the community as a
whole) a lot more in the long term than will giving them the answer.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Thu, 21 Dec 2000 00:25:59 +0800
From: Immortal Love <s997659@ee.cuhk.edu.hk>
To: Dimitri Gunsing <somewhere@planet.earth>
Subject: Re: How can I access the checkbox value of a form in Perl?
Message-Id: <Pine.GSO.4.05.10012210023560.24982-100000@sparc53.ee.cuhk.edu.hk>


sorry, sir. may be my question is not clear. my case is that i want to
use checkboxes. and my perl program wants to detect each checkbox and
knows whether they are checked or unchecked. thanks.

On Wed, 20 Dec 2000, Dimitri Gunsing wrote:

> A checkbox is a boolean, it only returns 'on' or 'off'. What you want you
> can do with a radio button (read HTML documentation for the use of radio
> buttons). Then in Perl you can read that value (if in this case the name of
> the radio button is the same as in your code) with :
> 
> use CGI;
> my $query = new CGI;
> my $data = $query->param("medium");
> 
> $data now holds the value the user selected.
> 
> Immortal Love <s997659@ee.cuhk.edu.hk> wrote in message
> news:Pine.GSO.4.05.10012201301530.24493-100000@sparc53.ee.cuhk.edu.hk...
> > I have a form in html and there is a group of checkbox, say
> > <input type="checkbox" name="medium" value="internet">Internet<br>
> > <input type="checkbox" name="medium" value="friends">Friends<br>
> > <input type="checkbox" name="medium" value="itsc">Activities<br>
> >
> > then how can i know which one is being checked?
> >
> > in Perl, i know $FORM{' '} can call a value.
> >
> > thanks
> >
> 
> 
> 
> 



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

Date: 20 Dec 2000 17:45:28 +0000
From: nobull@mail.com
Subject: Re: How can I access the checkbox value of a form in Perl?
Message-Id: <u9y9xbyojr.fsf@wcl-l.bham.ac.uk>

Immortal Love <s997659@ee.cuhk.edu.hk> writes upside down.  I do not
know if he does this because he is rude, stupid or ignorant.  I will
give him the beniefit of the doubt and assume ignorant.

> > use CGI;
> > my $query = new CGI;
> > my $data = $query->param("medium");
> > 
> > $data now holds the value the user selected.

> sorry, sir. may be my question is not clear. my case is that i want to
> use checkboxes. and my perl program wants to detect each checkbox and
> knows whether they are checked or unchecked. thanks.

In that case make the obvious change.

my @data = $query->param("medium");

@data now holds the values the user selected.

To find out if @data contains a specific value and hence if the
corresponding checkbox was checked see FAQ: "How can I tell whether a
list or array contains a certain element?"

Alternatively give each checkbox a different name and call param() in
a boolean context for each.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Wed, 20 Dec 2000 16:39:12 GMT
From: anver@my-deja.com
Subject: How do I use form email
Message-Id: <91qnbf$7qk$1@nnrp1.deja.com>

    I'm new to Perl and CGI but I am rather familiar with HTML. I need
to collect information from a form and send the results to an email
address. All the free scripts available use a function called Sendmail
which is not supported by my host - www.tripod.com. It has its own
version called Tripodmail. If anyone has any information or advice
please reply.

                     Thank You

                         Shamraz


Sent via Deja.com
http://www.deja.com/


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

Date: 20 Dec 2000 18:38:55 +0000
From: nobull@mail.com
Subject: Re: How do I use form email
Message-Id: <u9ofy7ym2o.fsf@wcl-l.bham.ac.uk>

anver@my-deja.com writes:

>     I'm new to Perl and CGI but I am rather familiar with HTML. I need
> to collect information from a form and send the results to an email
> address. All the free scripts available use a function called Sendmail
> which is not supported by my host - www.tripod.com. It has its own
> version called Tripodmail. If anyone has any information or advice
> please reply.

It is not at all clear what is your question is.

Are you asking how to send mail from a Perl script?  (See FAQ).

Anyhow what is this "function called Sendmail" that you talk about?
And in what way is it "not supported"?

Are you asking for a tutorial on how to write CGI scripts in Perl?
(See a tutorial on how to write CGI scripts in Perl)

Are you asking about the API of a Tripod specific mechanism that you
are required to use on Tripod?  (See documentation on Tripodmail, I
guess).

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Wed, 20 Dec 2000 16:27:38 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: how to invalidate a hash value during a foreach loop?
Message-Id: <m5n14tkhrvg2fpjifvoedut04nb98vgdi7@4ax.com>

Olwynn wrote:

>and trying to not execute a
>block of code when the user (of the form) has not entered any data.  The
>idea is that our distributors will be able to send an electronic christmas
>card from a page but be able to include several "To" addresses.

>if(values(%form_results)!='')

Ooh that's an original one. What did you expect this one to do?

What you probablty want, is something along the lines of grep(). I'm
just not sure just *what*. I supposing you have, say, 5 text boxes that
can be used for addresses. You do your own custom form decoding, which
makes it mpossible to use the same name for every text box. So, assuming
their name starts with "to_", followed by, say, a number, so it's "to_1"
till "to_5", then we can do:

	@to = grep length, @form{grep /^to_\d/, keys %form_results};

Now, if two of these five are not empty, then @to will contain their
contents, and nothing else. And:

	unless(@to) {
	    ...
	    # at least one recipient
	}

p.s. Please do proper taint checking on the entered addresses. You never
know what garbage people might fill in for an e-mail address.

-- 
	Bart.


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

Date: Wed, 20 Dec 2000 10:44:38 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: how to invalidate a hash value during a foreach loop?
Message-Id: <slrn941kv6.2gn.tadmc@magna.metronet.com>

Garry Williams <garry@zweb.zvolve.net> wrote:
>On Wed, 20 Dec 2000 07:32:07 GMT, Philip Lees
><pjlees@ics.forthcomingevents.gr> wrote:
>>On Tue, 19 Dec 2000 15:18:45 GMT, "Olwynn" <info@jjmackay.ca> wrote:
>>
>>>I am sure that the problem lies in the line
>>>
>>>if(values(%form_results)!='')
>>
>>For string comparisons, use ne instead of !=.
>
>What makes you think `values(%form_results)' is a string?  


That's a good question.


>"values"
>returns a list.  
 ^^^^^^^^^^^^^^

Oops.

Sometimes (when in list context) it returns a list, but this is 
not one of those times  :-)


>  if ( values(%form_results) ) {


That is scalar context (ie. one of those "other times").

No list here.


>or just 
>
>  if ( %form_results ) {


Now that seems even better than my suggestion. perldata.pod says:

   "If you evaluate a hash in scalar context, it returns false if the
    hash is empty."


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


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

Date: Wed, 20 Dec 2000 18:07:44 +0100
From: Basurero <basurero@jazzfree.com>
Subject: html tag stripper needed.
Message-Id: <3A40E760.7E848C2E@jazzfree.com>

  Any of you know a piece of code that will clean a string from
everything within the < and >, both included ??

  Thank you,


-- 
                                --------BEGIN GEEK CODE BLOCK--------
 Lucas 'Basurero' Vieites       Version: 3.12
     basurero @                 GCS/ d- s+:+ a+ c++ UL+ W++ N++ w PS+
PGP--
     jazzfree .                 t+ 5 X+ tv+ b++ DI+ UF+++ D+ G e h r y+
        com                     ---------END GEEK CODE BLOCK---------


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

Date: Wed, 20 Dec 2000 11:22:07 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: html tag stripper needed.
Message-Id: <slrn941n5f.2kh.tadmc@magna.metronet.com>

Basurero <basurero@jazzfree.com> wrote:

>  Any of you know a piece of code that will clean a string from
>everything within the < and >, both included ??


Anyone who checks the Perl FAQ before posting to the Perl newsgroup
would know how to do that.

You appear to be one of the not-so-well-mannered type of poster.
You should try and change that...


   perldoc -q HTML

      "How do I remove HTML from a string"


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


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

Date: Wed, 20 Dec 2000 17:55:07 GMT
From: rzilavec@tcn.net (Richard Zilavec)
Subject: Re: html tag stripper needed.
Message-Id: <3a40f23e.172339730@news.tcn.net>

On Wed, 20 Dec 2000 18:07:44 +0100, Basurero <basurero@jazzfree.com>
wrote:

>  Any of you know a piece of code that will clean a string from
>everything within the < and >, both included ??

HTML::Parse
HTML::FormatText
HTML::Element

You should check the above out too.

--
 Richard Zilavec
 rzilavec@tcn.net


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 5160
**************************************


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