[13064] in Perl-Users-Digest
Perl-Users Digest, Issue: 474 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 12 02:07:21 1999
Date: Wed, 11 Aug 1999 23:05:15 -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, 11 Aug 1999 Volume: 9 Number: 474
Today's topics:
Re: 'use strict' - what will I lose if I forgo the prag <wookie@star.net>
Re: <== Help with date sorting==> (Ronald J Kimball)
Re: alphabetical listing <rootbeer@redcat.com>
Re: Announcement: "CRAP" (Greg Andrews)
Re: Automatically update web page daily <rootbeer@redcat.com>
Re: CGI Error - CGI application misbehaved <USENET@questionexchange.com>
Re: CHMOD function <stirling@banet.net>
Re: Comma seperated numbers (Abigail)
Re: Dereferencing anon hash <USENET@questionexchange.com>
Re: Design by Contract Seminar Series (Ronald J Kimball)
Re: Getting perl to accept a flat table file <USENET@questionexchange.com>
Re: How to share constants across modules? <rootbeer@redcat.com>
Re: info on CGI client <USENET@questionexchange.com>
Re: is our reese the author of mysql book? (Decklin Foster)
Re: Japanese Girl Needs Help. <USENET@questionexchange.com>
Re: Menu Options <USENET@questionexchange.com>
Re: Menu Options <dan@purenud.com>
Re: Menu Options (Ronald J Kimball)
Re: Multi-Page Forms (Wayne)
My attempt at perl poetry <dan@purenud.com>
Re: My attempt at perl poetry <dan@purenud.com>
Re: Need Help Understanding a perl script (Ronald J Kimball)
Re: Need Help with regular expression <rootbeer@redcat.com>
Re: New to Perl <knewman@mcs.com>
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 11 Aug 1999 21:51:33 -0700
From: Joe Schmoe <wookie@star.net>
Subject: Re: 'use strict' - what will I lose if I forgo the pragma?
Message-Id: <37B252D5.CC591089@star.net>
Lee hit the nail on the head with his interpretation ( -- I'm just sorry
my posting required it). I had followed the Cookbook's recipe for
config files (Recipe 8.16 for those now joining us).
My goal was to have a .rc file contain %config. This %config would
overwrite the preexisting %config in the program proper. In order to
use strict, I had my'd the hash in the program. I was stymied when I
realized I could not my %config in the .rc file.
It appears that 'use vars' saves the day, since I can:
use strict;
use vars qw(%config);
%config = (
...
)
in the program and:
%config = (
...
)
in the .rc file without causing strict to fret.
Thank you, Lee & Tom. :)
To anyone else, I recommend `perldoc vars` and `perldoc strict`, both of
which were pretty helpful once I knew where to look.
Phil
------------------------------
Date: Thu, 12 Aug 1999 01:48:35 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: <== Help with date sorting==>
Message-Id: <1dwe8f3.sv6vze7en5hcN@p189.tc19a.metro.ma.tiac.com>
Matthew Bafford <*@dragons.duesouth.net> wrote:
> On Wed, 11 Aug 1999 10:39:44 GMT, Mike Bristow) held some poor sysadmin
> at gunpoint, and typed the following into comp.lang.perl.misc:
> : Matthew Bafford <*@dragons.duesouth.net> wrote:
> : >my %months = (
> :
> : Don't reinvent the wheel without good reason.
>
> Don't accuse without reading the original post.
>
> : Note that one of the good reasons to reinvent the wheel in this situation
> : is that Date::Manip is /slow/.
>
> Which is why I wrote what I did.
>
> : But if this isn't timecritical, why bother?
>
> As the original post said, this IS time critical. In his second post he
> elaborated, mailing me sample code (which I included in my post) using
> Date::Manip.
>
> His original question was 'is there any way to speed this up?'.
You must be thinking of a different thread. No requirements about
efficiency were ever mentioned, and the original poster never even
posted a second post.
His original question was not 'is there any way to speed this up?', but
rather 'is there any way to do this?'. Here is the original post:
I am looking to sort a set of dates with the following format in
most_recent-least_recent order.
August 10, 1999
September 20, 1999
December 13, 1999
Can anyone give me an example of how I might go about it?
Thanks
I think Date::Manip is a reasonable answer to this question.
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Wed, 11 Aug 1999 21:25:21 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: alphabetical listing
Message-Id: <Pine.GSO.4.10.9908112124400.7774-100000@user2.teleport.com>
On Thu, 12 Aug 1999, Noel Flanagan wrote:
> I'm relatively new to perl and am looking for advice on how to
> retrieve names in alphabetical order from some form of a database when
> a page first loads.
Is your problem with retrieving from a database or sorting in alphabetical
order?
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 11 Aug 1999 22:54:22 -0700
From: gerg@shell.ncal.verio.com (Greg Andrews)
Subject: Re: Announcement: "CRAP"
Message-Id: <7otnie$ov4$1@shell1.ncal.verio.com>
Greg Bacon <gbacon@cs.uah.edu> writes:
>In article <37b0303b.6458228@missy.shef.ac.uk>,
> tony@showroom.org.uk (Tony Kennick) writes:
>
>: The other problem with ~ is that some firewallls block it since, in
>: their mind a URL with it in has to be a set of personal pages rather
>: than anything that could possibly be work related.
>
>Ye gods, those must be fast networks! :-)
>
It's a web proxy, not a packet filter.
-Greg
--
::::::::::::::::::: Greg Andrews gerg@wco.com :::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
------------------------------
Date: Wed, 11 Aug 1999 21:23:20 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Automatically update web page daily
Message-Id: <Pine.GSO.4.10.9908112122240.7774-100000@user2.teleport.com>
On Thu, 12 Aug 1999 weicai@my-deja.com wrote:
> Is there anyone know how to write a perl script to check system clock
> and execute another perl script once or twice a day automatically in
> order to get daily updated web information.
Yes, but most such folks know that's it's kinder to use cron (or your
system's equivalent) instead. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 12 Aug 1999 5:27:18 GMT
From: QuestionExchange <USENET@questionexchange.com>
Subject: Re: CGI Error - CGI application misbehaved
Message-Id: <830qx@questionexchange.com>
> " The Specified CGI application misbehaved by not returning a
> complete
> set of HTTP Headers. The headers it returned are : "
> Here is the script
> #!/usr/bin/perl -w
> use CGI qw(:all);
> my $page = new CGI;
> print $page->header;
> print $page->start_html;
> print "Test Script:<BR>";
> print $page->end_html;
> When i execute from command line its is executing fine, but
> from IE4
> browser, I am getiing the above error. I am using Active Perl
> 5.005_02
> for winnt
> Thanks in advance
> sreedhar
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
print "Content-type: text/html\n\n";
if you not print it browser do not know, what type of document
it receive.
regards,
Olek
--
This answer is courtesy of QuestionExchange.com
http://www.questionexchange.com/servlet1/showUsenetGuest?ans_id=2682&cus_id=USENET&qtn_id=2092
------------------------------
Date: Thu, 12 Aug 1999 00:55:23 -0400
From: <stirling@banet.net>
Subject: Re: CHMOD function
Message-Id: <37b25220@news1.us.ibm.net>
--
Yours Sincerely,
Stirling Hughes
DesignMultimedia
stirling@designmultimedia.com
Martien Verbruggen wrote in message ...
>In article <37b22ce2@news1.us.ibm.net>,
> <stirling@banet.net> writes:
>
>> If you don't believe me try my testing methods as described in my last
>> follow up to Malcom Ray.
>
>The last response of you to Malcolm Ray is a reference to your
>response to Tom Briles. You're really into recursion, aren't you?
>
>Do you really believe that you would know better than people who
>actually read the source of perl? Why are you so stubborn? You could
>have tested this yourself, you know?
I did, and put the files in scripts. I then posted both versions of the
scripts, (copy and paste onto the newsgroups). Along with this I posted a
perl -V listing at the request of Malcom Ray. This is listed under his
response on 8/10/99 at 7:15pm.
stirling
|
------------------------------
Date: 11 Aug 1999 23:11:03 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Comma seperated numbers
Message-Id: <slrn7r4ia4.d88.abigail@alexandra.delanet.com>
Stone Cold (paulm@dirigo.com) wrote on MMCLXXI September MCMXCIII in
<URL:news:7osjve$nr4$1@nnrp1.deja.com>:
,, I have a CGI script outputting various numbers to a web page. The
,, numbers are coming out as follows: $1720600 (notice there are no
,, commas).
,,
,, I've read a little about how to use a commify subroutine, but I'm not
,, sure how to implement it. My values are a part of an outputted html
,, table and I'm not sure where to call the subroutine COMMIFY in my
,, script. Here is the subroutine...think it will work?
,,
,, sub commify {
,, my $text = reverse $_[0];
,, $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
,, return scalar reverse $text;
,, }
Eeck. That's very inefficient, as it's quadratic in the length of the
string.
This variation is linear, because it spends time figuring out whether
there's a dot in the string once, instead of over and over again (ah,
the wonders of loop-enlightment techniques):
#!/opt/perl/bin/perl -w
use strict;
sub commify ($) {
my $str = reverse shift;
substr ($str, 1 + index ($str, ".")) =~ s/(\d\d\d)(?=\d)/$1,/g;
scalar reverse $str;
}
foreach (<DATA>) {
chomp;
exit if $_ eq '__END__';
print commify $_, "\n";
}
__DATA__
123456
1234567
1234567.89012345
12345678910134113241411.1234124312
123
1.1234132421
1234124.
123.
0.13241
0.
0.0
__END__
123,456
1,234,567
1,234,567.89012345
12,345,678,910,134,113,241,411.1234124312
123
1.1234132421
1,234,124.
123.
0.13241
0.
0.0
,, So if I needed to seperate my larger numbers with commas for every 3
,, numbers from the right, I would call this routine. But where do I call
,, it? Is it before the print statement? Is it right next to the
,, variable I have setup to get me the output?
Well, that's up to you. It probably doesn't matter, and we'd need to see
your code for the rare case it does.
Abigail
--
perl -wlpe '}$_=$.;{' file # Count the number of lines.
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 12 Aug 1999 5:24:49 GMT
From: QuestionExchange <USENET@questionexchange.com>
Subject: Re: Dereferencing anon hash
Message-Id: <820qx@questionexchange.com>
> using. If I take the code that sets up the anon hash outside
> of the
> foreach loops I have no problems. But when it is setup as
> shown below
> I get an unitiliazed variable error at line 69 which is the
> final print
> statement. I have been working with this code for 2 days now
> and I am
> sure I am missing something quite simple. Can anyone help out
> with
> this?
> The program is supposed to read everyline in two files and
> then
> store the information from one column on every line. The
> database
> information is stored based on the file name used and then the
> line
> number.
> Thanks in advance,
> Josh
> #!/usr/local/bin/perl -w
> use strict;
> ########################
> # #
> #Initializing Variables #
> # #
> ########################
> my $root_dir = "/home/mutant2/jogoodma/PDB/";
> my @files = ("crd.9.m0","crd.19.m0");
> my $file_tail = ".rsa";
> my $temp;
> my $count = 0;
> my $avg_sasa = 55;
> my $abs_digits;
> my %database;
> my $i;
> my $result;
> ########################
> # #
> #Main Program #
> # #
> ########################
> foreach $_ (@files) {
> $i = 0;
> my $file = $root_dir . $_ . $file_tail;
> open (FILE,$file);
> my @input = <FILE>;
> chop(@input);
> close(FILE);
> foreach $temp (@input) {
> if ($temp =~ /RES/ && $temp !~ /REM/) {
> my ($label,$aa,$res,$abs,$rel,$remainder) = split('
> ',$temp,6);
> if ($abs < $avg_sasa) {
> $abs_digits = 0;
> }
> elsif ($abs >= $avg_sasa) {
> $abs_digits = 1;
> }
> #Creating anon hash
> $database{$_} = {
> $i => $abs_digits
> };
> $i++;
> }
> }
> }
> my $test;
> #Derefencing one specific database entry by hand for testing
> purposes.
> $test = %{$database{"crd.9.m0"}} ->{"1"};
> print "$test\n";
To answer your main question, "Why is $test uninitialized?", I
would have to fix a couple bugs I see and also know the
contents of the files "crd.9.m0.rsa" and "crd.19.m0.rsa". Or at
least, in your test example, the value of the "abs" col. on the
second line of "crd.9.m0". But assuming that your data files
have some valid numerical data in that col., there are two
problems:
In this part:
#Creating anon hash
$database{$_} = {
$i => $abs_digits
};
you are telling perl to create a _new_ anonymous hash with a
single key-value pair, where the key is $i (the current line
number) and the value is $abs_digits. You are replacing the
whole hash every time with a different single key-value pair in
it. I think what you meant to say was probably more like:
# adding key-val pair
$database{$_}{$i} = $abs_digits;
this will merely add a new value to the anon. hash each time,
leaving the old ones in place (and causing the hash to
automatically "spring into existence" the first time you store
something in it).
The second problem I see is this:
$test = %{$database{"crd.9.m0"}} ->{"1"};
Use % to refer to a hash as a whole. In this case, you are only
talking about a single element in the hash, "crd.9.m0" (which
is itself a hash, but counts as a single element as far as
this (%database) hash is concerned), so you have to use a $ to
refer to it. Also, the "->" is not necessary here, nor is the
%{} thing. I would write that as:
$test = $database{"crd.9.m0"}{1};
If that doesn't work, please send me some sample lines from the
data files, I can make them work together. Good luck.
- Paul Jacobs
--
This answer is courtesy of QuestionExchange.com
http://www.questionexchange.com/servlet1/showUsenetGuest?ans_id=2642&cus_id=USENET&qtn_id=1972
------------------------------
Date: Thu, 12 Aug 1999 01:48:37 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Design by Contract Seminar Series
Message-Id: <1dwe90c.14hmyvp1ju7cazN@p189.tc19a.metro.ma.tiac.com>
Interactive Software Engineering, Inc. <training@eiffel.com> wrote:
> ISE's EXCLUSIVE SEMINARS ON DESIGN BY CONTRACT AND THE COMPONENT REVOLUTION.
> A ONE-DAY COURSE BY BERTRAND MEYER.
ISE's EXCLUSE SEMINARS ON BUZZWORDS, SHOUTING, AND BUZZWORDS.
A ONE_DAY COURSE BY OSCAR MEYER.
> If you are involved in software development, either as a manager or as a
> developer, you know how crucial it is to improve software quality and
> productivity. In spite of the major advances of recent years, especially
> Object Technology, it is still much too hard to produce correct, reliable
> systems at a reasonable cost.
Actually, I know quite a few people involved in software development who
do not know how crucial it is to improve software quality and
productivity. :) Your logic is faulty.
Perhaps if, instead of Object Technology, we had OBJECT TECHNOLOGY, then
everything would be fine and dandy. Ah well.
> This state of the art seminar is a unique opportunity to hear about the
> approach that is revolutionizing the software industry - not from an outside
> observer, but from one of the key originators of the discipline, Dr.
> Bertrand Meyer, one of a handful of object- oriented movers and shakers
> whose work made modern object-oriented technology possible.
"state of the art"
"unique opportunity"
"revolutionizing"
"key originators"
"one of a handful"
"movers and shakers"
"gag me with a spoon"
> "Design by Contract" is the major technological breaktrough in software
> engineering in the past 15 years. This course introduces Design by Contract
> and shows why it can, like no other technique since the invention of classes
> and objects, dramatically affect the way we develop software, and why it is
> a required condition for achieving the promise of the Component Revolution.
Hey, don't break that trough, I need that to feed the pigs!
Clearly, the components are forming a revolution because they're tired
of being treated like objects by the higher classes.
> For more information about the seminar, as well as locations, please visit
> our Web site at http://www.designbycontract.com. You can also contact us by
> email: training@eiffel.com.
Of course, I'm only ridiculing you because there are no sessions in
Boston. :)
> Interactive Software Engineering, Inc
> ISE Building
> 270 Storke Road, 2nd Floor
> Goleta, CA 93117, USA
> t. 805 685-1006
> f. 805 685-6869
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: 12 Aug 1999 5:28:48 GMT
From: QuestionExchange <USENET@questionexchange.com>
Subject: Re: Getting perl to accept a flat table file
Message-Id: <836qx@questionexchange.com>
> Can somebody tell me how to get perl to accept a comma
> delimited txt
> file and parse it contents.
> paul.
You can parse file with your own code.
I have do it before an can say, that it is not trivial task.
It is better to install packages
DBI and DBD:CSV
which help you solve you problem.
regards,
Olek
--
This answer is courtesy of QuestionExchange.com
http://www.questionexchange.com/servlet1/showUsenetGuest?ans_id=2683&cus_id=USENET&qtn_id=2118
------------------------------
Date: Wed, 11 Aug 1999 21:07:39 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: How to share constants across modules?
Message-Id: <Pine.GSO.4.10.9908112058420.7774-100000@user2.teleport.com>
On Wed, 11 Aug 1999, David Coppit wrote:
> http://www.deja.com/=dnt_mn/getdoc.xp?AN=431075526&fmt=text
> They say that the Perl distributed with RedHat 5.2 was not an official
> release, and had several problems. I have some corroboration of this,
> because I found RedHat 5.2 users needed to install a newer version of
> the IO module to fix another problem. Is there a more official
> statement about problems with this version of Perl?
What, did you just use the words "official" and "Perl" in the same
sentence? That's a first. :-)
If someone is using an experimental, development version of Perl, there
will be bugs. (There are bugs in every other version of Perl, too, but we
_care_ about those. :-) Essentially, the purpose of those experimental
versions is to work the bugs out; the only people who should use them are
those who are willing to endure (and maybe fix) the bugs. If the RedHat
folks shipped that, their customers should complain, and probably already
have done so.
> I'm guessing that the only answer is to have RedHat 5.2 folks
> downgrade to Perl 5.004, which came with RedHat 5.1, or upgrade to
> Perl 5.00503, which came with RedHat 6.0. However, I'd rather be able
> to tell people to just install a newer module. Any advice?
They don't have to use the versions which come precompiled from RedHat
headquarters; they can install and compile their own in short order. Maybe
you can even make up your own .rpm file, if you want to make it easy for
them to use a different version than whatever RH makes available. Still,
any recent official version should work as documented. Else, we want a
proper bug report so we can stomp the bug.
It may be that fixing this one problem is as simple as installing a new
module, but these folks would probably be better served by replacing an
experimental, buggy Perl with something road-tested and robust.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 12 Aug 1999 5:26:37 GMT
From: QuestionExchange <USENET@questionexchange.com>
Subject: Re: info on CGI client
Message-Id: <827qx@questionexchange.com>
> Hello,
> do you know how to grab the ip of a client from the cgi
> runned?
> thank you
> gabriele
> gabriele@gallacci.com
> PS: can you suggest me a good cgi programming book?
print $ENV{REMOTE_ADDR};
I highly recommend using CGI.pm module for doing CGI
programming in perl. Getmore info at
http://stein.cshl.org/WWW/software/CGI
The author has also published the book on CGI programming with
CGI.pm. You can find it here
http://www.amazon.com/exec/obidos/ASIN/0471247448/qid%3D9344236
37/002-3094319-2820606
--
This answer is courtesy of QuestionExchange.com
http://www.questionexchange.com/servlet1/showUsenetGuest?ans_id=2645&cus_id=USENET&qtn_id=2064
------------------------------
Date: Thu, 12 Aug 1999 04:29:54 GMT
From: decklin@home.com (Decklin Foster)
Subject: Re: is our reese the author of mysql book?
Message-Id: <slrn7r4jco.6n.decklin@c26469-a.clnvl1.ct.home.com>
Scott Oglesby <sto@storm.com> writes:
> Perhaps you haven't visited http://www.mattwright.com ...
> (yes, it is _the_ Matt Wright)
<brings up page>
Wait a minute... is that *that* Matt Wright??!!? Shit. Where have I
*been*? I hereby repent for basing my own Perl scripts on some of his
stuff when I was 14 or 15. And mind you, that wasn't as long ago as I
wish it was.
Man, I really have to read this group more... ;-)
--
Debian GNU/Linux - http://www.debian.org/
The Web is to graphic design as the fax machine is to literature.
------------------------------
Date: 12 Aug 1999 5:26:7 GMT
From: QuestionExchange <USENET@questionexchange.com>
Subject: Re: Japanese Girl Needs Help.
Message-Id: <825qx@questionexchange.com>
> I am trying to make a PERL script that will
> allow me to access individual images by the user
> making one event (push button) and then have the
> PERL script roam the database and select the correct
> images.
> Can this be done? Yes? No?
> Please tell me.
> Sorry if my words is not correct.
> My native language is Japanese.
> Thank you,
> Kaori Ayn Honeywell
> kaori@japanesegirl.com
my native language is Ukrainian :)
sure you can do it.
You can store your images both in database or in directory tree
(this is simpler).
As a database you can use all you want:
Postgres, MySQL, Access, SQL-server ...
I have done work like this some time before, but sorry, this
was commercial project and I can not present you this programm
:)
regards,
Olek
--
This answer is courtesy of QuestionExchange.com
http://www.questionexchange.com/servlet1/showUsenetGuest?ans_id=2668&cus_id=USENET&qtn_id=2050
------------------------------
Date: 12 Aug 1999 5:28:2 GMT
From: QuestionExchange <USENET@questionexchange.com>
Subject: Re: Menu Options
Message-Id: <833qx@questionexchange.com>
> 1.a
> 2.b
> 3.c
> ...
> ...
> n.n
> Enter Option:
> To call any of the routines from the menu I have an equally
> large if else (or elsif) statement, ie
> if ($option == 1){
> do subroutine1();
> }else
> if ($option == 2){
> do subroutine2();
> }
> etc...etc
> is there an easy way of calling these routines, as at the
> moment
> the if else statements are more than 30 !!!!
> Thanks
> Dave
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
Sample:
$opt = 6;
if ( $opt<0 || $opt>30 )
{
# error handling
}
else
{
$fname="handler$opt();";
}
eval($fname);
sub handler1()
{}
....
sub handler6()
{
# handler body
}
....
--
This answer is courtesy of QuestionExchange.com
http://www.questionexchange.com/servlet1/showUsenetGuest?ans_id=2686&cus_id=USENET&qtn_id=2112
------------------------------
Date: Wed, 11 Aug 1999 23:38:16 -0600
From: "Dan" <dan@purenud.com>
Subject: Re: Menu Options
Message-Id: <T2ts3.2265$lL2.233382@typ12.nn.bcandid.com>
ok .. I just tossed this together so you can get an idea of how this works
...
** NOTICE THAT IT WILL NOT RUN WHILE USING STRICT REFERENCES **
#!/usr/bin/perl
use strict;
no strict 'refs';
use CGI qw(param);
my $var = param('sub') || 'blah';
&{$var};
sub yak() { print "yak yak yak\n" }
sub blah() { print "blah blah blah\n" }
hope this helps!
Regards,
Dan
QuestionExchange <USENET@questionexchange.com> wrote in message
news:833qx@questionexchange.com...
> > 1.a
> > 2.b
> > 3.c
> > ...
> > ...
> > n.n
> > Enter Option:
> > To call any of the routines from the menu I have an equally
> > large if else (or elsif) statement, ie
> > if ($option == 1){
> > do subroutine1();
> > }else
> > if ($option == 2){
> > do subroutine2();
> > }
> > etc...etc
> > is there an easy way of calling these routines, as at the
> > moment
> > the if else statements are more than 30 !!!!
> > Thanks
> > Dave
> > Sent via Deja.com http://www.deja.com/
> > Share what you know. Learn what you don't.
>
> Sample:
> $opt = 6;
> if ( $opt<0 || $opt>30 )
> {
> # error handling
> }
> else
> {
> $fname="handler$opt();";
> }
> eval($fname);
> sub handler1()
> {}
> ....
> sub handler6()
> {
> # handler body
> }
> ....
>
> --
> This answer is courtesy of QuestionExchange.com
>
http://www.questionexchange.com/servlet1/showUsenetGuest?ans_id=2686&cus_id=
USENET&qtn_id=2112
------------------------------
Date: Thu, 12 Aug 1999 01:48:57 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Menu Options
Message-Id: <1dwebmy.19oxxt1k180q3N@p189.tc19a.metro.ma.tiac.com>
Trond Michelsen <mike@crusaders.no> wrote:
> <dave4000@my-deja.com> wrote in message news:7ork99$6u$1@nnrp1.deja.com...
> > is there an easy way of calling these routines, as at the moment
> > the if else statements are more than 30 !!!!
>
> Yes. By using a hash of function references, you can do this very easily.
>
> Pretty much copied from page 697 in the "Perl Cookbook":
> -------------8<------------
> %subs = (1 => \&subroutine1,
> 2 => \&subroutine2,
> 3 => \&subroutine3,
> etc...
> );
>
> if ($subs{$option}) {$subs{$option}->()}
> else {&default_subroutine}
> -------------8<------------
>
This is just crying out for an _array_ of function references. :)
@subs = (
sub { die "Bad index\n" },
\&subroutine1,
\&subroutine2,
\&subroutine3,
# etc.
);
if ($option > 0 and $option < @subs) {
$subs[$option]->();
} else {
&default_subroutine;
}
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Thu, 12 Aug 1999 05:39:05 GMT
From: headdog<no spam>@usa.net (Wayne)
Subject: Re: Multi-Page Forms
Message-Id: <37b35a89.103724646@news.remarq.com>
Thanks for all the help people and pseudonyms. I guess I'm going to need to pick
up a copy of the Guide to Programming with CGI.pm. Man, I hate leg work :-)
Randal, I appreciate it. I got your script to work but I have no clue on how to
customize the output page. I was also hoping to use images for buttons, but can
come close to figuring it out. Hopefully this book will shed some light on this
for me.
If there are any other good resources a reluctant CGI/PERL newbie like me should
be checking out. Post it here, and I'll try to check it out.
As for posting to a CGI group... How, Where? I cross-posted the original msg to
comp.infosystems.www.authoring.cgi and I got an email telling me I had to
approve my post. So I did, but I still don't see my post. Are there any other
good CGI ng's?
Thanks Again.
Wayne.
------------------------------
Date: Wed, 11 Aug 1999 22:53:45 -0600
From: "Dan" <dan@purenud.com>
Subject: My attempt at perl poetry
Message-Id: <fpss3.2233$lL2.228527@typ12.nn.bcandid.com>
one thing I've learned is always have fun with your code --
SIT: foreach $hit (@toilet) {
if(exists(fork())) { chomp($hit) and die }
eval { sqrt($hit) };
if ( glob($hit) { do 'dump' }
else { unpack "c", $hit }
warn if log; split; sleep; wait; redo SIT;
}
not very useful but i was bored
Regards,
Dan
------------------------------
Date: Wed, 11 Aug 1999 23:10:17 -0600
From: "Dan" <dan@purenud.com>
Subject: Re: My attempt at perl poetry
Message-Id: <EEss3.2240$lL2.230768@typ12.nn.bcandid.com>
As if this is worth fixing ... but this one actually doesn't cough up errors
:
SIT: foreach $hit (@toilet) {
if(fork) { chomp($hit) and die }
eval { sqrt($hit) };
if( glob(*hit) ) { do 'dump' }
else { unpack "c", $hit }
warn if log; split; sleep; wait; redo SIT;
}
Dan <dan@purenud.com> wrote in message
news:fpss3.2233$lL2.228527@typ12.nn.bcandid.com...
> one thing I've learned is always have fun with your code --
>
>
> SIT: foreach $hit (@toilet) {
> if(exists(fork())) { chomp($hit) and die }
> eval { sqrt($hit) };
> if ( glob($hit) { do 'dump' }
> else { unpack "c", $hit }
> warn if log; split; sleep; wait; redo SIT;
> }
>
>
>
> not very useful but i was bored
>
> Regards,
>
> Dan
>
>
------------------------------
Date: Thu, 12 Aug 1999 01:49:08 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Need Help Understanding a perl script
Message-Id: <1dwecb1.rmlhsmbyexwjN@p189.tc19a.metro.ma.tiac.com>
Uri Guttman <uri@sysarch.com> wrote:
> >>>>> "MV" == Martien Verbruggen <mgjv@comdyn.com.au> writes:
>
> MV> In article <rqegvaoar4fcq6@corp.supernews.com>,
> MV> "Diane" <tech1@magicnet.net> writes:
>
> MV> # Don't skip the first argument, like your code does:
> MV> foreach my $i ( 0 .. $#ARGV ) { print "arg$i: $ARGV[$i]<BR>\n" }
>
> actually her code doesn't skip any @ARGV values. it just starts counting
> from 1 while yours is zero based. neither one used the number for
> indexing so it doesn't matter.
Of course, since CGI scripts don't take command line arguments in any
case, it _really_ doesn't matter.
[I'm catching up on threads from the past week and a half. :) ]
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Wed, 11 Aug 1999 21:58:41 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Need Help with regular expression
Message-Id: <Pine.GSO.4.10.9908112146330.7774-100000@user2.teleport.com>
On Thu, 12 Aug 1999 malharsire@cwix.com wrote:
> I have a pattern of the type
>
> $pattern = "(PE 19PE2PS1.2PIN0)VIH_0";
>
> I want to put back slashes before the parens to use it in a
> grep later....
Maybe you really want \Q - that would be simpler, and it wouldn't forget
that dot is also a pattern metacharacter.
my @new_list = grep /\Q$pattern/, @whatever;
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Thu, 12 Aug 1999 00:21:35 -0500
From: Kevin Newman <knewman@mcs.com>
Subject: Re: New to Perl
Message-Id: <37B259DF.551A702C@mcs.com>
Thank you, this is what I'm looking for!
kln
QuestionExchange wrote:
> > I'm very new to PERL and have a few questions on how to create
> > :
> > 1) an edited temprary file of an original file that is being
> > read in
> > 2) edit and save the original file in place
> > What I'm trying to do is open a file then extract a string.
> > After this
> > string has been stored to a variable, I want to remove the
> > additional
> > white space from the end of each line and use this edited text
> > to send
> > to a printer a number of times determined by the string value.
> > Sounds
> > simple enough? I am able to create the temporary file but I
> > get the
> > error message:
> > Use of uninitialized value at "filename" line nn, <> chunk nn.
> > Where "filename" = the perl filename and nn = a number.
> > What does this mean? How do I correct it? Below is an example
> > of what
> > I've done so far. Thanks in advance for your help
> > Kevin Newman
> > knewman@mcs.com
> > #!/usr/bin/perl -w
> > use Getopt::Std;
> > # Define the command line printer options
> > getopts("d:");
> > @ARGV == 1 or die "usage: label_printer -d<printer> \n";
> > if($opt_d or die){
> > print "Printer Destination: $opt_d \n";
> > }
> > $command_line = join ($",@ARGV);
> > print "Line Print Command $command_line \n";
> > $line_print = "lp";
> > # Assign the command line printer options list
> > $print_options = "-d$opt_d";
> > print "Print Options: $print_options \n";
> > # Initialize found_copies to 0
> > $found_copies = 0;
> > #Just a temp file. I would really like the
> > # filename to be the original filename.tmp
> > $new = "dummy2";
> > # Look for the Keyword ^FX COPIES = nnn ^FS (Case is not
> > important)
> > # if one occurance of the copies line is found the if statement
> > will
> > # not be entered again, but the file will continue to be
> > cleaned of
> > spaces
> > open (NEW, "> $new") or die "can't open $new: $!";
> > select (NEW);
> > while ($line = <> ) {
> > if ($line =~ m/^(\^FX\s*COPIES\s*\=\s*([0-9]+)\s*\^FS)/i
> > &&
> > $found_copies == 0)
> > {
> > #DEBUG CODE
> > print "inside of the if statement";
> > $nmbr_of_labels = $2;
> > $found_copies++;
> > #DEBUG CODE
> > print "FOUND COPIES = $found_copies \n";
> > }
> > $line =~ s/ *$/END/;
> > print NEW $_ or die "can't write $new: $!";
> > print $line;
> > }
> > close(NEW) or die "can't close $new: $!";
> > # Now print the labels
> > # for ($i = 0; $i < $nmbr_of_labels; $i++) {
> > # @args = ($line_print, $print_options, $command_line);
> > # print "@args \n";
> > # system(@args) == 0 or die "system @args failed: $?"
> > #}
> > #
>
> do
> print NEW $line
> and not
> print NEW $_
> Perl realized that you were using $_ that didn't have value
> inside it and printed to you the helpful message - all you need
> to do is to look in your program at that line number (nn) and
> see what is causing the message.
> BTW: you might want to look at the -i parameter, see perlrun
> manpage
>
> --
> This answer is courtesy of QuestionExchange.com
> http://www.questionexchange.com/servlet1/showUsenetGuest?ans_id=2619&cus_id=USENET&qtn_id=2100
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 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.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. Due to their sizes, neither the Meta-FAQ nor
the FAQ are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq" from
almanac@ruby.oce.orst.edu.
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 474
*************************************