[17196] in Perl-Users-Digest
Perl-Users Digest, Issue: 4608 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 13 14:10:40 2000
Date: Fri, 13 Oct 2000 11:10:21 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <971460621-v9-i4608@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 13 Oct 2000 Volume: 9 Number: 4608
Today's topics:
Need Urgent help on File reading <Murugesu.Sivaparan@tellabs.com>
Re: Need Urgent help on File reading <anders@wall.alweb.dk>
Re: Need Urgent help on File reading <jeff@vpservices.com>
Newbie first time post. looking for the FAQ to this gro Alan B. smonella@netscape.net
Re: Newbie first time post. looking for the FAQ to this <zakazan@gmx.de>
Re: Newbie first time post. looking for the FAQ to this (Clay Irving)
Re: Newbie needs advice <kellikellin@netscape.net>
Re: Newbie needs advice <jeff@vpservices.com>
Re: Newbie Q: LWP $results split into an array? (Mark-Jason Dominus)
Re: newbie questions (Gary O'Keefe)
Re: newbie questions (Mark-Jason Dominus)
Re: OOP- Abstract Derived Classes ? <joe+usenet@sunstarsys.com>
Re: OOP- Abstract Derived Classes ? <joe+usenet@sunstarsys.com>
Re: OOP- Abstract Derived Classes ? <bart.lateur@skynet.be>
Re: OOP- Abstract Derived Classes ? <joe+usenet@sunstarsys.com>
Re: Parsing form parameters using $$ nobull@mail.com
Re: passing and returning hashes <ren.maddox@tivoli.com>
Re: Perl conditional functions (Liam)
Re: Perl conditional functions <eric.kort@vai.org>
Re: Perl conditional functions <eric.kort@vai.org>
Re: Perl conditional functions (Mark-Jason Dominus)
Re: Perl conditional functions (Mark-Jason Dominus)
Re: Perl conditional functions (Liam)
Re: Perl conditional functions nobull@mail.com
Re: Perl conditional functions (Craig Berry)
Re: Perl conditional functions (Craig Berry)
Re: Perl conditional functions (Tramm Hudson)
Re: Perl conditional functions <eric.kort@vai.org>
Re: Perl/Windows problem <barbr-en@online.no>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 13 Oct 2000 10:27:07 -0500
From: Murugesu Sivaparan <Murugesu.Sivaparan@tellabs.com>
Subject: Need Urgent help on File reading
Message-Id: <39E729CB.253826C8@tellabs.com>
Hi,
Please help me to solve a file reading problem in Windows NT.
The following code works on DOS command.
However, when I try to use it using Netscape 4.5, it doesn't
work.
In the DOS prompt, the "while" loop is working ok and
the "read" function is reading from the file.
But when I use it with netscape 4.5, it looks like that the
"while" loop is not working and the "read" function is not
reading from the file.
I also tried with different read methods("<>") and it doesn't work.
Is this a bug?
What is the workaround?
Thank you.
M.Sivaparan
====================================>
$MyValue = "NE 1,"."Day 1,"."Shift 1,";
open(BOOKREAD, "<NE1.txt"); #
while(read(BOOKREAD, $line, 1024)) {
if($line =~ /$MyValue/) {
#print $line;
@Shift1 = ("Tom","Dave");
}
} #end while
close(BOOKREAD);
print "<html><head>";
print "<title> Schedule Table</title>";
print "</head>";
print "<body>";
print "<table border=\"1\" cellpadding=\"2\" width=\"640\">";
print "<tr>";
print "<td width=\"87\"><b>8:00 - 1:00</b></td>";
print "<td width=\"61\">$Shift1[0]</td>";
print "<td width=\"71\">$Shift1[1]</td>";
print "</tr>";
print "</table>";
print "</body></html>";
------------------------------
Date: Fri, 13 Oct 2000 17:53:14 +0200
From: Anders Lund <anders@wall.alweb.dk>
Subject: Re: Need Urgent help on File reading
Message-Id: <zeGF5.450$Uy5.31220@news000.worldonline.dk>
Murugesu Sivaparan wrote:
> Hi,
> Please help me to solve a file reading problem in Windows NT.
>
> The following code works on DOS command.
> However, when I try to use it using Netscape 4.5, it doesn't
> work.
>
> In the DOS prompt, the "while" loop is working ok and
> the "read" function is reading from the file.
>
> But when I use it with netscape 4.5, it looks like that the
> "while" loop is not working and the "read" function is not
> reading from the file.
I think you should buy a good perl book, like "Learning Perl" by Randolph
Schwartz.
Or read some of the documentation coming with perl, and all the
introductions and tutorials you can find on the web.
And something about HTTP and HTTP servers.
-anders
--
[ the word wall - and the trailing dot - in my email address
is my _fire_wall - protecting me from the criminals abusing usenet]
------------------------------
Date: Fri, 13 Oct 2000 09:45:19 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Need Urgent help on File reading
Message-Id: <39E73C1F.E2A7B8A0@vpservices.com>
Murugesu Sivaparan wrote:
>
> The following code works on DOS command.
> However, when I try to use it using Netscape 4.5, it doesn't
> work.
"Doesn't work" is not a good problem description and with a bad problem
description there is no way to find a solution.
> open(BOOKREAD, "<NE1.txt"); #
This line is why you have no better problem description: you did not
ask Perl to check to see if the file opening was successful and to tell
you what went wrong if it was not successful. Change it to this and
Perl will politely tell you what "doesn't work" means:
open( BOOKREAD, '<NE1.txt') or die "Can't open 'NE1.txt': $!";
The "$!" is the important part, it will show the actual error message.
Since it worked on the command line and not in the browser, the chances
are high that the script could not find the file, perhaps because the
server's directory structure is different from the physcial directory
structure. (which, by the way, is mentioned prominently in the Perl/CGI
FAQ).
> while(read(BOOKREAD, $line, 1024)) {
> ...
> I also tried with different read methods("<>") and it doesn't work.
Go back to the "<>" method, the read() method is for binary files, not
text files.
> print "<html><head>";
> print "<title> Schedule Table</title>";
> print "</head>";
> print "<body>";
> ..
All those print statements are confusing. Look up "here documents" in
the documentation to see a better method of printing large blocks of
HTML.
--
Jeff
------------------------------
Date: Fri, 13 Oct 2000 14:50:22 GMT
From: Alan B. smonella@netscape.net
Subject: Newbie first time post. looking for the FAQ to this grouo
Message-Id: <39e71fea.91886@news.ivwnet.com>
could some please, post the faq or direct by a link to It's location
------------------------------
Date: Fri, 13 Oct 2000 17:48:08 +0200
From: "Werner, Wolfgang" <zakazan@gmx.de>
Subject: Re: Newbie first time post. looking for the FAQ to this grouo
Message-Id: <39E72EB8.477FA8D8@gmx.de>
http://www.cpan.org
Alan, B., smonella@netscape.net wrote:
> could some please, post the faq or direct by a link to It's location
------------------------------
Date: 13 Oct 2000 15:52:14 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: Newbie first time post. looking for the FAQ to this grouo
Message-Id: <slrn8uebte.n4j.clay@panix3.panix.com>
On Fri, 13 Oct 2000 14:50:22 GMT, Alan B. smonella@netscape.net
<AlanB.smonella@netscape.net> wrote:
>could some please, post the faq or direct by a link to It's location
http://www.perl.com is a *real* good starting point.
--
Clay Irving <clay@panix.com>
Today I dialed a wrong number...The other person said, "Hello?" and I said,
"Hello, could I speak to Joey?"...They said, "Uh...I don't think so...he's only
2 months old." I said, "I'll wait."
- Steven Wright
------------------------------
Date: Fri, 13 Oct 2000 10:10:01 -0500
From: kelli norman <kellikellin@netscape.net>
Subject: Re: Newbie needs advice
Message-Id: <39E725C9.85ED595D@netscape.net>
Anders Lund wrote:
>
> Peter Fritz wrote:
>
> > I have been looking into putting a snowplow catalog online for a customer,
> > and had been thinking of databasing the info. Through another newsgroup,
> > it was suggested that I look into a Perl script that reads .csv files.
> > Here's my problem....I have no experience with Perl, and need advice as to
> > how to go about doing this type of thing , or even just learning enough
> > about Perl to get a start.
> >
> > I appreciate any help you can give,
> > Pete Fritz
> > pfritz@almoninc.com
>
> Download and install perl
>
> open a terminal (known as "DOS prompt" in M$ OS'es) and type "perldoc perl"
> and start reading
>
> -anders
> --
> [ the word wall - and the trailing dot - in my email address
> is my _fire_wall - protecting me from the criminals abusing usenet]
not everyone here is a smartass.
i'm currently putting agricultural research data into a MySQL database
on a Linux machine, and accessing/displaying the information to the web
using Perl. do a web search on 'Perl CGI' and 'Perl DBI' - that should
help you understand CGI scripting and database connectivity in Perl.
------------------------------
Date: Fri, 13 Oct 2000 09:59:03 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Newbie needs advice
Message-Id: <39E73F57.B56A31A8@vpservices.com>
kelli norman wrote:
>
> > Peter Fritz wrote:
> >
> > > it was suggested that I look into a Perl script that reads .csv files.
>
> i'm currently putting agricultural research data into a MySQL database
> on a Linux machine, and accessing/displaying the information to the web
> using Perl. do a web search on 'Perl CGI' and 'Perl DBI' - that should
> help you understand CGI scripting and database connectivity in Perl.
There are also all the files and docs about DBI at:
http://www.symbolstone.org/technology/perl/DBI/
The modules DBD::CSV and DBD::RAM and DBD::Sprite will all work to
access CSV files.
--
Jeff
------------------------------
Date: Fri, 13 Oct 2000 16:16:38 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Newbie Q: LWP $results split into an array?
Message-Id: <39e73565.4530$289@news.op.net>
Keywords: Laplace, annuli, mayst, morale
In article <39e71ca7.22815997@news.gssec.bt.co.uk>,
Gary O'Keefe <gokeefe@gssec.bt.co.uk> wrote:
>You could drop the regex too and
>just write it as
>
> @result = split( ',', $text );
That is very bad advice, because you cannot 'drop the regex'. Even if
you use ',' Perl will still treat the string like a regex, so you are
just fooling yourself. Even if you don't fool yourself, you are
likely to fool someone else who is reading your code.
People show up in this newsgroup all the time wondering why
split('|', $string);
did not work properly. And the answer is that it is the same as
split(/|/, $string);
and | is a special character in regexes.
The single exception is that
split(' ', $string);
is special and is not the same as split(/ /, $string);
------------------------------
Date: Fri, 13 Oct 2000 16:12:41 GMT
From: gokeefe@gssec.bt.co.uk (Gary O'Keefe)
Subject: Re: newbie questions
Message-Id: <39e73300.28536022@news.gssec.bt.co.uk>
On Fri, 13 Oct 2000 13:26:31 GMT, Dominique Lorre
<dlorre@caramail.com> wrote:
>The code works just fine (well... it seems so) but I would like to know
>if there are better ways to do it, and also since I used flex and bison
>in the past, if these tools have any equivalent for Perl (you put the
>rules and you have Perl output generated).
>TIA
You could try something like:
#!/usr/local/bin/perl -w
use strict;
# Grab all the file at once.
# $/ is also known as $INPUT_RECORD_SEPARATOR.
# See the perlvar docs for more info.
$/ = undef;
$_ = <DATA>;
# Using a multi-line match (the /s modifier on the regex
# treats the string as a single line allowing you to match
# newlines) pick of the text between the first set of
# TITLE tags. The regex match operator returns a list,
# so we choose the first element. Then all the newlines
# in the string are replaced with a space with a global
# multi-line (/gs) replace.
# See the perlre docs for more info.
my $title = ( /<TITLE>(.*?)<\/TITLE>/is )[0];
$title =~ s/\n/ /gs;
print "Title: $title\n";
__DATA__
<HTML>
<HEAD><TITLe>This is
a
test.</TITlE></HEAD>
<BODY>
Hello,
World!
</BODY>
<HTML>
Which returns
Title: This is a test.
Hope this helps
Gary
--
Gary O'Keefe
gary@onegoodidea.com
+44 (0) 7976 614 336
------------------------------
Date: Fri, 13 Oct 2000 16:28:30 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: newbie questions
Message-Id: <39e7382d.4575$6a@news.op.net>
Keywords: dervish, discretion, leap, pedantry
In article <39e73300.28536022@news.gssec.bt.co.uk>,
Gary O'Keefe <gokeefe@gssec.bt.co.uk> wrote:
>my $title = ( /<TITLE>(.*?)<\/TITLE>/is )[0];
I think it is much more normal to write this as:
my ($title) = ( /<TITLE>(.*?)<\/TITLE>/is );
------------------------------
Date: 13 Oct 2000 11:29:52 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: OOP- Abstract Derived Classes ?
Message-Id: <m3pul4ahe7.fsf@mumonkan.sunstarsys.com>
Bart Lateur <bart.lateur@skynet.be> writes:
[...]
> Now, if you want a general overriding class, for example for debugging,
> and you need different objects to derive from different subclasses, then
> then this trick won't help.
Yes, that's pretty much what I'd like to do.
[...]
> Something like (based upon your code, and again, untested):
>
> package My::Subclass;
>
> sub new {
> my ($type, $base_instance) = @_;
> my $class = ref($type) || $type;
> my $subclass = __PACKAGE__ . '::' . $class;
> no strict 'refs';
> @{$subclass . '::ISA'} = (__PACKAGE__, $class);
> bless $base_instance, $subclass;
> }
>
> The idea is that for HTML::Parser, a package
> "My::Subclass::HTML::Parser" gets generated, in which the objects will
> be blessed, and the variable @My::Subclass:HML::Parser::ISA is set to
> your package, for your custom method, and to the object's original
> class, for all other methods.
I don't think this will work, based on how @ISA works: @ISA belongs
to the package, so any object that changes a class's @ISA affects
the inheritance of all other the objects in the class.
What I'm looking for is probably not possible; but I'll keep my eyes
open for suggestions.
Thanks again for the help!
--
Joe Schaefer
------------------------------
Date: 13 Oct 2000 11:40:24 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: OOP- Abstract Derived Classes ?
Message-Id: <m3lmvsagwn.fsf@mumonkan.sunstarsys.com>
Per Kistler <kistler@gmx.net> writes:
> Like so:
It doesn't seem to work for me. With the -w flag,
your code outputs:
-------
Useless use of a variable in void context at /tmp/try.pl line 35.
$obj->myMethod
I'm in package: SubClass
$obj->myBaseMethod
Use of uninitialized value at (eval 2) line 1.
Use of uninitialized value at (eval 2) line 1.
$obj->mySubMethod
I'm in package: SubClass
Use of uninitialized value at /tmp/try.pl line 55.
$obj->myMethod
I'm in package: SubClass
$obj->myBaseMethod
Use of uninitialized value at (eval 5) line 1.
Use of uninitialized value at (eval 5) line 1.
Use of uninitialized value at (eval 5) line 1.
Use of uninitialized value at (eval 5) line 1.
$obj->mySubMethod
I'm in package: SubClass
Use of uninitialized value at /tmp/try.pl line 55.
Use of uninitialized value at /tmp/try.pl line 55.
--------
Nothing appears to be inherited: only the "subclass methods"
seem to work. Here's the code numbered for reference:
1 #!/usr/bin/perl -w
2
3 # Different base classes for same subclass test
4
5 package BaseA;
6
7 sub new {
8 my ($type) = shift;
9 }
10 sub myMethod {
11 my ($type) = shift;
12 print "I'm in package: " . __PACKAGE__ . "\n";
13 }
14 sub myBaseMethod {
15 my ($type) = shift;
16 print "I'm in package: " . __PACKAGE__ . "\n";
17 }
18
19package BaseB;
20
21 sub new {
22 my ($type) = shift;
23 }
24 sub myMethod {
25 my ($type) = shift;
26 print "I'm in package: " . __PACKAGE__ . "\n";
27 }
28 sub myBaseMethod {
29 my ($type) = shift;
30 print "I'm in package: " . __PACKAGE__ . "\n";
31 }
32
33package SubClass;
34
35 @ISA;
36
37 sub new {
38 my ($type,$baseClass) = shift;
39 push(@ISA,$baseClass);
40 bless {}, ref($type) || $type;
41 }
42 sub myMethod {
43 my ($type) = shift;
44 print "I'm in package: " . __PACKAGE__ . "\n";
45 }
46 sub mySubMethod {
47 my ($type) = shift;
48 print "I'm in package: " . __PACKAGE__ . "\n";
49 }
50
51package main;
52
53use strict;
54
55for my $base ( qw( BaseA BaseB ) ){
56 my $obj = SubClass->new($base);
57
58 for my $m ("\$obj->myMethod",
59 "\$obj->myBaseMethod",
60 "\$obj->mySubMethod"){
61 print $m,"\n\t";
62 eval $m;
63 }
64}
65
66
--
Joe Schaefer
------------------------------
Date: Fri, 13 Oct 2000 16:30:56 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: OOP- Abstract Derived Classes ?
Message-Id: <11eeuscpqdlt4mlfkk6h3vke5ut3ng8bsu@4ax.com>
Joe Schaefer wrote:
>I don't think this will work, based on how @ISA works: @ISA belongs
>to the package, so any object that changes a class's @ISA affects
>the inheritance of all other the objects in the class.
No, you misunderstood. If, for example, you derive from the class
HTML::Parser, the package you bless your new object in is
My::Subclass::HTML::Parser, a class that is entirely empty, except for
it's @ISA; but which inherits both from My::Subclass (for your method)
and from HTML::Parser (for all other methods).
@My::Subclass::HTML::Parser::ISA does not clash with
@My::Subclass::XML::Parser::ISA, to name just two examples classes.
--
Bart.
------------------------------
Date: 13 Oct 2000 12:37:29 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: OOP- Abstract Derived Classes ?
Message-Id: <m3hf6gae9i.fsf@mumonkan.sunstarsys.com>
Bart Lateur <bart.lateur@skynet.be> writes:
> Joe Schaefer wrote:
>
> >I don't think this will work, based on how @ISA works: @ISA belongs
> >to the package, so any object that changes a class's @ISA affects
> >the inheritance of all other the objects in the class.
>
> No, you misunderstood. If, for example, you derive from the class
> HTML::Parser, the package you bless your new object in is
> My::Subclass::HTML::Parser, a class that is entirely empty, except for
> it's @ISA; but which inherits both from My::Subclass (for your method)
> and from HTML::Parser (for all other methods).
> @My::Subclass::HTML::Parser::ISA does not clash with
> @My::Subclass::XML::Parser::ISA, to name just two examples classes.
>
> --
> Bart.
Cool- I understand now.
I'll give it a shot.
Thanks!
--
Joe Schaefer
------------------------------
Date: 13 Oct 2000 17:54:39 +0100
From: nobull@mail.com
Subject: Re: Parsing form parameters using $$
Message-Id: <u9hf6gznow.fsf@wcl-l.bham.ac.uk>
<arancj@yahoo.com> writes:
> I want to...
[...use symbolic refernces]
Stop wanting to do that.
[ but it doesn't work ]
You can't use a symbolic refernce to a variable delared using my().
Keep the my() and ditch the symbolic references.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 13 Oct 2000 09:23:38 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: passing and returning hashes
Message-Id: <m3zok8251x.fsf@dhcp11-177.support.tivoli.com>
Larry Rosler <lr@hpl.hp.com> writes:
> delete @$fb_ref{qw(foo bar)};
Thank you!
I don't know what kind of mental block I was having the other day.
Thinking back, I could have sworn that I had at least tried:
delete @{$fb_ref}{qw(foo bar)};
if not the shorter version above, but upon looking back through my
history I see that I never actually did (of course). I kept leaving
the arrow in there (stuff like: @$fb_ref->{qw(foo bar)} ).
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Fri, 13 Oct 2000 15:24:17 GMT
From: lkenny@fisheries.org (Liam)
Subject: Re: Perl conditional functions
Message-Id: <39e728b0.12517378@news.volocom.net>
Your method worked, but I am still having a slight problem. Is there
any reason why it won't read in my text once I do this.
It will only print the variables with numerci values not 0 or 0.oo,
but it neglects to print text variables.
Any ideas?
if ($FORM{$name} != 0 || $FORM{$name} != 0.00) {
$FORM{$name} =~ tr/A-Z/0-9/;
print "$FORM{$name}<br>\n";
}
On Fri, 13 Oct 2000 10:40:07 -0400, "Eric" <eric.kort@vai.org> wrote:
>"Liam" <lkenny@fisheries.org> wrote in message
>news:<39e71891.8389967@news.volocom.net>...
>
>> if ($FORM{$name} == 0) {
>
>> # what goes here to get those variables equal to 0
>
>>
>
>> out of the next step of my processing?
>
>> }
>
>How about:
>
>if ($FORM{$name} != 0) {
>
>
> # whatever you want to do with the values _not_ equal to zero
>
>}
>
>hth
>
>Eric
>
>
>
------------------------------
Date: Fri, 13 Oct 2000 11:54:37 -0400
From: "Eric" <eric.kort@vai.org>
Subject: Re: Perl conditional functions
Message-Id: <8s7b39$2dtc$1@msunews.cl.msu.edu>
"Liam" <lkenny@fisheries.org> wrote in message
news:39e728b0.12517378@news.volocom.net...
> Your method worked, but I am still having a slight problem. Is there
> any reason why it won't read in my text once I do this.
> It will only print the variables with numerci values not 0 or 0.oo,
> but it neglects to print text variables.
> Any ideas?
>
Ah yes. If the variable contains text, it evaluates to 0 in numerical
contexts. So you will need to test if it has letters as well using a regex:
if ( ($FORM{$name} != 0) || ($FORM{$name} =~ /[A-Za-z]/ ) ) {
# whatever you want to do with the values _not_ equal to zero AND not of
zero length
}
Now you can process any value that is not zero or contains letters.
------------------------------
Date: Fri, 13 Oct 2000 11:56:23 -0400
From: "Eric" <eric.kort@vai.org>
Subject: Re: Perl conditional functions
Message-Id: <8s7b6i$2du2$1@msunews.cl.msu.edu>
SORRY...the comment in the code in my previous post was erroneous...correct
below.
Eric
"Liam" <lkenny@fisheries.org> wrote in message
news:39e728b0.12517378@news.volocom.net...
> Your method worked, but I am still having a slight problem. Is there
> any reason why it won't read in my text once I do this.
> It will only print the variables with numerci values not 0 or 0.oo,
> but it neglects to print text variables.
> Any ideas?
>
Ah yes. If the variable contains text, it evaluates to 0 in numerical
contexts. So you will need to test if it has letters as well using a
regex:
if ( ($FORM{$name} != 0) || ($FORM{$name} =~ /[A-Za-z]/ ) ) {
# whatever you want to do with the values _not_ equal to zero OR
containing text
}
Now you can process any value that is not zero or contains letters.
------------------------------
Date: Fri, 13 Oct 2000 15:56:28 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Perl conditional functions
Message-Id: <39e730ab.4476$72@news.op.net>
Keywords: dragon, icosahedral, rufous, testimony
In article <39e71891.8389967@news.volocom.net>,
Liam <lkenny@fisheries.org> wrote:
>if ($FORM{$name} == 0) {
> # what goes here to get those variables equal to 0
>
> out of the next step of my processing?
> }
Do this:
my @zeroes;
for (keys %FORM) {
push(@zeroes, $_) if $FORM{$_} =~ /^0+$/;
}
delete @FORM{@zeroes};
This will remove all the zero-valued items from %FORM.
Note that the test is
$FORM{$_} =~ /^0+$/;
That checks to see if the form entry is "0" or "00" or "000" or some
other sequence of 0's. You should not use the obvious test:
$FORM{$_} == 0;
Why not? Because strings like "foo" and "red" will compare equal to
zero, and you don't want to remove those.
------------------------------
Date: Fri, 13 Oct 2000 15:59:48 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Perl conditional functions
Message-Id: <39e73173.448f$46@news.op.net>
Keywords: Charles, air, malign, parley
In article <39e728b0.12517378@news.volocom.net>,
Liam <lkenny@fisheries.org> wrote:
> if ($FORM{$name} != 0 || $FORM{$name} != 0.00) {
> $FORM{$name} =~ tr/A-Z/0-9/;
> print "$FORM{$name}<br>\n";
> }
When you compare a string with a number in Perl, for example
"red" != 0
Perl converts the string to a number. It does this by looking for a
number at the beginning of a string. For example, "123red" converts
to the number 123.
However, just "red" converts to 0, because there is no number at the
beginning of "red".
This means that when FORM{$name} is "red", the test
$FORM{$name} != 0
is *false*, and $FORM{$name} == 0 is *true*.
See my other post in the thread for what you should do instead.
Also note that 0 and 0.00 are identical, so
if ($FORM{$name} != 0 || $FORM{$name} != 0.00) {
does the exact same test twice.
------------------------------
Date: Fri, 13 Oct 2000 16:34:08 GMT
From: lkenny@fisheries.org (Liam)
Subject: Re: Perl conditional functions
Message-Id: <39e7396e.16804061@news.volocom.net>
Thanks very much for all your help.
I think I can get it to work now.
LK
On Fri, 13 Oct 2000 14:28:48 GMT, lkenny@fisheries.org (Liam) wrote:
>I have having a little trouble with a form I am writing. I know that
>is also a CGI issue, but I think the problem I have is with Perl.
>
>In my conditional statement I want any of the variables with the value
>of '0' to be disregarded from the rest of the program.
>But I am not sure how to do this. Is it possible to find out which
>have the value of zero and remove them?
>
>Any and all help offered is greatly appreciated.
>
>
>if ($FORM{$name} == 0) {
> # what goes here to get those variables equal to 0
>
> out of the next step of my processing?
> }
>
>LK
>
>
------------------------------
Date: 13 Oct 2000 18:19:42 +0100
From: nobull@mail.com
Subject: Re: Perl conditional functions
Message-Id: <u9bswozmj5.fsf@wcl-l.bham.ac.uk>
Anders Lund <anders@wall.alweb.dk> writes:
> for (keys %FORM) {
> undef $FORM{$_} if ($FORM{$_} == 0);
> }
I think you meant delete, not undef.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 13 Oct 2000 17:40:17 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Perl conditional functions
Message-Id: <suei815va7k97e@corp.supernews.com>
Liam (lkenny@fisheries.org) wrote:
: In my conditional statement I want any of the variables
Not 'variables' but rather hash values, if I'm understanding your example
below correctly.
: with the value
: of '0' to be disregarded from the rest of the program.
: But I am not sure how to do this. Is it possible to find out which
: have the value of zero and remove them?
:
: if ($FORM{$name} == 0) {
: # what goes here to get those variables equal to 0
: out of the next step of my processing?
: }
Here's how I'd do it:
delete @FORM{ grep { $FORM{$_} == 0 } keys %FORM};
That single statement will remove any key-value pair whose value is 0 from
%FORM.
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "Quidquid latine dictum sit, altum viditur."
|
------------------------------
Date: Fri, 13 Oct 2000 17:42:44 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Perl conditional functions
Message-Id: <sueickahr9jq92@corp.supernews.com>
Eric (eric.kort@vai.org) wrote:
: "Liam" <lkenny@fisheries.org> wrote in message
: news:39e728b0.12517378@news.volocom.net...
: > Your method worked, but I am still having a slight problem. Is there
: > any reason why it won't read in my text once I do this.
: > It will only print the variables with numerci values not 0 or 0.oo,
: > but it neglects to print text variables.
: > Any ideas?
:
: Ah yes. If the variable contains text, it evaluates to 0 in numerical
: contexts. So you will need to test if it has letters as well using a regex:
:
: if ( ($FORM{$name} != 0) || ($FORM{$name} =~ /[A-Za-z]/ ) ) {
Either that, or simply test for truth, which will be satisfied by any
nonzero number or any nonempty string other than '0':
if ($FORM{$name}) {
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "Quidquid latine dictum sit, altum viditur."
|
------------------------------
Date: 13 Oct 2000 17:42:15 GMT
From: hudson@swcp.com (Tramm Hudson)
Subject: Re: Perl conditional functions
Message-Id: <8s7hhn$lhl$1@sloth.swcp.com>
Keywords: dodecahedral, troll, troll, troll
Mark-Jason Dominus <mjd@plover.com> wrote:
> my @zeroes;
> for (keys %FORM) {
> push(@zeroes, $_) if $FORM{$_} =~ /^0+$/;
> }
> delete @FORM{@zeroes};
The original poster asked for ones of the form 0.0* to be removed, too.
So that means that the RE should be /^0+\.0*$/, or something of that form.
I don't know if 00000.000000 counts as "0" or not.
Golf?
delete@FORM{grep$FORM{$_}=~/^0+\.?0*$/,keys%FORM}
Of course, it does become nine characters shorter if %F is used
in place of %FORM. And what joys come from a no-whitespace line.
Also, I didn't see anything about regular polyhedra in your post.
I feel as if you have misled us all.
Tramm
--
o hudson@swcp.com hudson@turbolabs.com O___|
/|\ http://www.swcp.com/~hudson/ H 505.323.38.81 /\ \_
<< KC5RNF @ N5YYF.NM.AMPR.ORG W 505.986.60.75 \ \/\_\
0 U \_ |
------------------------------
Date: Fri, 13 Oct 2000 13:50:43 -0400
From: "Eric" <eric.kort@vai.org>
Subject: Re: Perl conditional functions
Message-Id: <8s7hsu$2te6$1@msunews.cl.msu.edu>
> : Ah yes. If the variable contains text, it evaluates to 0 in numerical
> : contexts. So you will need to test if it has letters as well using a
regex:
> :
> : if ( ($FORM{$name} != 0) || ($FORM{$name} =~ /[A-Za-z]/ ) ) {
>
> Either that, or simply test for truth, which will be satisfied by any
> nonzero number or any nonempty string other than '0':
>
> if ($FORM{$name}) {
>
Yes. Mr. Berry's solution is more elegant...dare I even say more correct?
Mine, however, provides a pleasant opportunity to meditate upon a couple
additional Perl topics, and asuages my guilt for receiving more than I give
on this list.
=)
Eric
------------------------------
Date: Fri, 13 Oct 2000 17:44:09 +0200
From: =?iso-8859-1?Q?K=E5re_Olai_Lindbach?= <barbr-en@online.no>
Subject: Re: Perl/Windows problem
Message-Id: <25GF5.5278$W31.79558@news1.online.no>
"Bart Lateur" <bart.lateur@skynet.be> skrev i melding
news:5qjdusklg9sfpb6su7gk9frgsqgsbiaq1k@4ax.com...
> John Clifford Williams wrote:
>
> >but Windows doesn't seem to like it when I try to
> >associate the .ATT file type with my script.
>
> You probably need to save it as a BAT file, and associate the
extension
> with that. Oh, with Activestate's Perl, there's a utility called
PL2BAT
> (in Perl's "bin" dir) which can do the conversion for you.
>
> A major problem is that BAT fiels get their arguments in 8.3 AKA
"short
> filename" format. The really annoying part is that there is no API
call
> to get the associated long filename. Not that I know of.
No need to save it as a bat-file.
Here is an example of a association I have on a win98,
regarding file-extension F2F. Ordinary Perl-script name "f2zf.pl",
taking the filename clicked-on as an argument ("%1"):
d:\perl\bin\perl.exe D:\fics\ibis\f2f_sign\f2zf.pl "%1"
Adapt path to perl-exe and perl-script on your machine.
Regard Kåre
------------------------------
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 4608
**************************************