[16901] in Perl-Users-Digest
Perl-Users Digest, Issue: 4313 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 13 14:10:32 2000
Date: Wed, 13 Sep 2000 11:10:18 -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: <968868618-v9-i4313@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 13 Sep 2000 Volume: 9 Number: 4313
Today's topics:
Re: help in writing a card game <kelley.a.kent@intel.com>
Re: help in writing a card game <yanick@babyl.sympatico.ca>
Re: help in writing a card game (Michael Houghton)
Re: help in writing a card game <godzilla@stomp.stomp.tokyo>
Hidding ActivePerl CGI Error <jjroman@jazzfree.com>
Re: how to remove unprintable chars with Perl script tebrusca@my-deja.com
I really need help !!!! <peterp100@hotmail.com>
Re: Inserting into arrays tasher1234@my-deja.com
main process should not wait for externally started exe but86@my-deja.com
Re: min function <bmb@ginger.libs.uga.edu>
Re: min function <mischief@motion.net>
Re: min function (Craig Berry)
Newbie question: Is Perl a good choice for this? <davesisk@ipass.net>
Re: Newbie question: Is Perl a good choice for this? <christopher_j@uswest.net>
Re: Newbie question: Is Perl a good choice for this? <yanick@babyl.sympatico.ca>
Re: Newbie to CGI (David H. Adler)
Re: OFF TOPIC IGNORE Re: killfiles? scores? I wish I <russ_jones@rac.ray.com>
Re: OFF TOPIC IGNORE Re: killfiles? scores? I wish I <iltzu@sci.invalid>
Re: Passing hashes to a function <ren.maddox@tivoli.com>
Re: Perl script printing to MAIL header <eirik@netmaking.com>
re: Problem running script from within a script <19wlr@globalnet.co.uk>
Re: Qualifications for new Perl programmer????? <christopher_j@uswest.net>
Re: Qualifications for new Perl programmer????? <ralawrence@my-deja.com>
Re: Qualifications for new Perl programmer????? <godzilla@stomp.stomp.tokyo>
reading packet from C++ code <robert@purdy.com>
Re: Silly grep tricks <anmcguire@ce.mediaone.net>
slick way to look at array? <crossbach@atgi.net>
Re: slick way to look at array? <sariq@texas.net>
Re: slick way to look at array? (Gary E. Ansok)
Re: String compression <christopher_j@uswest.net>
Re: Unix Info tebrusca@my-deja.com
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 13 Sep 2000 08:42:31 -0700
From: "Kelley Kent" <kelley.a.kent@intel.com>
Subject: Re: help in writing a card game
Message-Id: <8po76u$24h@news.or.intel.com>
Thanx for all the input so far. Appears the consensus
was that I was over-complicating things, as ever.
Anywho, being the glutton for punishment that I am,
thought I'd just share what I've come up with so far,
for feedback purposes, as well as a way to continue
the thread. It's really a sad day when your own thread
dies. :p
My code, and heck even my logic, are probably la crappy
as the French might say. But again, this is just a sideline
"project" that's purely for fun and in the interest of learning.
See code below. There are still a couple of debug features,
like the $wait = <STDIN>. And the play_a_hand subroutine
is not fully defined as such. Nor is the play_best_card. Work
in progress.
Comments, suggestions, and possibly even flames are welcome.
Have a good one.
-- Kelley
use POSIX;
# =-~=-~=-~=-~=-~=-~=-~=-~=-~=-~ GLOBALS ~-=~-=~-=~-=~-=~-=~-=~-=~-=~-=
@deck, @player1, @player2, @player3, @player4;
@next = (\@player4, \@player3, \@player2, \@player1);
@hand; # cards played during one hand of the game
%played;
# =-~=-~=-~=-~=-~=-~=-~=-~=-~=-~ MAIN LOOP ~-=~-=~-=~-=~-=~-=~-=~-=~-=~-=
init_deck();
deal();
show_hands();
for($hands=0; $hands<13; $hands++) {
play_a_hand();
$wait = <STDIN>;
}
# =-~=-~=-~=-~=-~=-~=-~=-~=-~=-~ SUBROUTINES ~-=~-=~-=~-=~-=~-=~-=~-=~-=~-=
sub deal {
while($#deck >= 0) {
# Get a random index
$rand = rand($#deck+1);
$rand = POSIX::floor($rand);
# print "\nDeck now has $#deck cards";
# print "\nDealing element $rand, which is $deck[$rand]";
# Get the player who gets dealt the selected card
$player = pop(@next);
push(@$player, $deck[$rand]);
# Put player back into dealing queue
unshift(@next, $player);
# Delete the dealt card from the deck
if($rand == 0) {
@deck = @deck[$rand+1 .. $#deck];
}
elsif($rand == $#deck) {
@deck = @deck[0 .. $rand-1];
}
else {
@deck = @deck[0 .. $rand-1, $rand+1 .. $#deck];
}
# print "\nDeck now has $#deck cards\n";
# $wait = <STDIN>;
}
print "I have dealt $cards_dealt\n";
}
sub get_best_card {
my($cards, $player) = @_;
if(! $cards) { # If leading off ...
$card = pop(@$player);
push(@hand, $card);
print "I'm playing the $card\n";
}
else {
($suit, $value) = (substr($hand[0], 0, 1), substr($hand[0], 1));
print "I need to play a $suit!\n";
}
}
sub init_deck {
@deck = ('s2', 's3', 's4', 's5', 's6', 's7', 's8', 's9', 'sT', 'sJ', 'sQ',
'sK', 'sA',
'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9', 'dT', 'dJ', 'dQ',
'dK', 'dA',
'c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8', 'c9', 'cT', 'cJ', 'cQ', 'cK',
'cA',
'h2', 'h3', 'h4', 'h5', 'h6', 'h7', 'h8', 'h9', 'hT', 'hJ', 'hQ', 'hK',
'hA');
}
sub play_a_hand {
@hand = ();
# Get the player who leads
$player = pop(@next);
# Put player back into dealing queue
unshift(@next, $player);
$card = get_best_card(0, $player);
push(@hand, $card);
# --------------
# Get the next player
$player = pop(@next);
# Put player back into dealing queue
unshift(@next, $player);
$card = get_best_card(1, $player);
push(@hand, $card);
# --------------
# Get the next player
$player = pop(@next);
# Put player back into dealing queue
unshift(@next, $player);
$hand = get_best_card(2, $player);
push(@hand, $card);
# --------------
# Get the next player
$player = pop(@next);
# Put player back into dealing queue
unshift(@next, $player);
$card = get_best_card(3, $player);
push(@hand, $card);
# @hand now corresponds to @next, as in $hand[0] is what $next[0] played
# This helps us determine how to queue the playing order of the next hand
}
sub show_hands {
foreach $player (@next) {
print "\n\nPLAYER $player -----------------\n "; # yeah, i know it
displayes the array address
foreach $card (sort @$player) {
print "$card-";
}
}
------------------------------
Date: Wed, 13 Sep 2000 16:47:07 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: help in writing a card game
Message-Id: <fcOv5.258524$1h3.5068947@news20.bellglobal.com>
I just wanted to point out that there is a nifty module
called Games::Cards available on CPAN that does all the
boring stuff like shuffling cards, giving hands, shooting
the pesky cheaters with three aces in their sleeves.
Kelley Kent <kelley.a.kent@intel.com> wrote:
: My code, and heck even my logic, are probably la crappy
: as the French might say.
Eh. I doubt we may say that. 'Amas improbable d'horribles
circonvolutions psychotropiques', on the other hand... ;)
Joy,
Yanick
--
eval" use 'that poor Yanick' ";
print map{ (sort keys %{{ map({$_=>1}split'',$@) }})[hex] }
qw/8 b 15 1 9 10 11 15 c b 13 1 12 b 13 f 1 c 9 a e b 13 0/;
------------------------------
Date: 13 Sep 2000 13:39:04 -0400
From: herveus@Radix.Net (Michael Houghton)
Subject: Re: help in writing a card game
Message-Id: <8poe3o$32c$1@saltmine.radix.net>
Howdy!
In article <8pjk6a$sre@news.or.intel.com>,
Kelley Kent <kelley.a.kent@intel.com> wrote:
>So I was bored last night and decided to write
>a card program in Perl. (Ah yes, writing code
>for fun.) Actually I was kinda forced into it cause
>I couldn't find a good Spades game on download.com.
>Anywho, I was having some difficulties in figuring
>out how to implement the deck and the players,
>structure-wise.
>
At the risk of actually making a helpful response, may I suggest
the Games::Cards module?
yours,
Michael
--
Michael and MJ Houghton | Herveus d'Ormonde and Megan O'Donnelly
herveus@radix.net | White Wolf and the Phoenix
Bowie, MD, USA | Tablet and Inkle bands, and other stuff
| http://www.radix.net/~herveus/
------------------------------
Date: Wed, 13 Sep 2000 10:51:33 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: help in writing a card game
Message-Id: <39BFBEA5.5D06CE58@stomp.stomp.tokyo>
Kelley Kent wrote:
> Thanx for all the input so far. Appears the consensus
> was that I was over-complicating things, as ever.
(snipped card game stuff)
> Comments, suggestions, and possibly even flames are welcome.
So upload this to www for testing. I will provide you with
a professional opinion, being the only Perl programmer
to ever successfully write a graphical card game and,
being the only person using this newsgroup qualified
to provide an opinion of expertise.
Godzilla!
--
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class
------------------------------
Date: Wed, 13 Sep 2000 19:29:14 +0200
From: "JJR" <jjroman@jazzfree.com>
Subject: Hidding ActivePerl CGI Error
Message-Id: <VROv5.1779$qf%1.15138983@news.jazztel.es>
When a CGI error is produced, or even when no .pl file exists in IIS &
ActivePerl a error page is shown in Explorer.
I need to hide this screen because it's show the full path of the script
(D:\web\cgi-bin\script.pl)
I need a permanent solution (via config file or command line parameter). The
eval { } solutions dosen't run for me
Any Idea?????
Tnks.
------------------------------
Date: Wed, 13 Sep 2000 16:22:33 GMT
From: tebrusca@my-deja.com
Subject: Re: how to remove unprintable chars with Perl script
Message-Id: <8po9jf$u4e$1@nnrp1.deja.com>
In article <8pm5ii$6k0$1@news.IAEhv.nl>,
"Durk Gardenier" <d.gardenier@iae.nl> wrote:
> This initially seemed easy , but it has taken
> me quite some time and I still have not found
> an answer.
>
> If a file contains unprintable characters, how can I
> remove them with a perl script?
>
> I hope you can help.
>
> Regards,
>
> Durk
>
Check Effective Perl book page 145
$string =~ tr/\0-\037\177-\377//d; # Remove unprintables
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 13 Sep 2000 14:24:11 -0400
From: peter <peterp100@hotmail.com>
Subject: I really need help !!!!
Message-Id: <ihhvrsk1bmgkpdo15m42sm7lnkr3fvufkq@4ax.com>
I'm having a hell of a time trying to get my perl cgi scripts to work.
I'm using Mandrake 7.1, and I'm working out of a book called: Perl,
CGI, and JavaScript, by Sybex.
Right now I'm working in chapter 12: Creating Real-World HTML Forms
with Perl and CGI.
I've got a few question about HTML and Perl code, what is happening
here is that a user will enter his data and then push the submit
button and then the data will be displayed in a new page.
THIS IS THE PERL [file name: geturl.pl]:
#!/usr/bin/perl
require "/pub/scripts/perl-cgi/html.pl";
[first, what is this?, the book doesn't say, and no such file or dir
exists on my system]
$Title = "Get Information From A URL";
$QueryString = $ENV{ 'QUERY_STRINGS'} ;
@NameValuePairs = split (/&/, $QueryString);
&HTML_Header ($Title);
print "\n";
print "<H1>$Title</H1>\n";
print "<HR>\n";
foreach $NameValue (@NameValuePairs)
{
($Name, $Value) = split (/=/, $NameValue);
print "Name = $Name, value = $Value<BR>\n";
}
$HTML_Ender;
AND HERE IS THE HTML:
<html>
<head>
<title>Visitor Information Form</title>
</head>
<body>
<h1 align="left">Visitor Information Form</h1>
<hr>
<form action="geturl.pl" METHOD="GET">
[I'm not sure which dir the form action should point to, in my config
files, apache says: protected-cgi-bin/ /home/httpd/protected-cgi-bin/]
<b>
Last name: <INPUT TYPE="text" NAME="LastName" SIZE=16>
First name: <INPUT TYPE="text" NAME="FirstName" SIZE=16>
<br><br>
Address: <INPUT TYPE="text" Name="Address" SIZE=32>
City: <INPUT TYPE="text" NAME="City" SIZE=32>
<br><br>
State: <INPUT TYPE="text" NAME="State" SIZE=2>
<br><br>
</b><center><b>
<INPUT TYPE="submit" VALUE="Send Information">
<INPUT TYPE="reset" VALUE="Clear Form Fields">
</b>
</center></form>
</body>
</html>
[Unfortunately this book does a poor job, I'll probably return it, can
anyone tell me a good book about cgi (perl-cgi) that's worth the paper
it's printed on ?]
------------------------------
Date: Wed, 13 Sep 2000 17:04:27 GMT
From: tasher1234@my-deja.com
Subject: Re: Inserting into arrays
Message-Id: <8poc2a$1g6$1@nnrp1.deja.com>
In article <uog1sny5p.fsf@demog.berkeley.edu>,
aperrin@demog.berkeley.edu (Andrew J. Perrin) wrote:
> tasher1234@my-deja.com writes:
>
> > Okay, I'm a newbie to Perlscript. What I need to do
> > is to insert an array element into any position in an array.
> > For example the array @items has this in it:
> > Bob Ted Alice
> > Between Bob and Ted I want to insert Uri.
> > So now the array should look like this:
> > Bob Uri Ted Alice
> > So would a splice command do it?
> > $i is the element counter
> > splice @items,$i,0
>
> What happened when you tried it?
>
> Check out perldoc -f splice for more.
>
That was just a guess. I tried it (splice) but it wrote over Ted
and left the array count to be the same when it should have got
incremented.
I do have the Programming Perl manual and have read the small part
about splice - no help.
Is your perldoc -f splice command given from the Dos command line?
If so, then I guess I have to be on the Server's directory where
Perl was installed. I'm on a NT workstation now.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 13 Sep 2000 15:27:26 GMT
From: but86@my-deja.com
Subject: main process should not wait for externally started executable
Message-Id: <8po6c1$ptm$1@nnrp1.deja.com>
Hello programmers!
I am building a daemon that calls other shell programmes.
When I use system() or backticks, it waits until the other programm is
done. It gets an bit problematic, if this hangs or runs too long (well,
two seconds is much too long in my context...).
Do you know a way to call a programm and not wait for it? Probably
something with fork()/ pipe() etc, right...?
Pleas give me help
thankyou
werner
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 13 Sep 2000 12:06:07 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: min function
Message-Id: <Pine.A41.4.21.0009131203420.4996-100000@ginger.libs.uga.edu>
On 13 Sep 2000, Damian Conway wrote:
> Shawn Ribordy <Ribordy_Shawn_C@cat.com> writes:
>
> > I have looked all over the place, and I cannot find a min function.
> > Can anyone help?
>
> use builtin 'min';
>
>
> Damian
Don't forget 'wimin'. It does the same as 'min' but gets paid less.
Brad
--
print sub{(sort{$a<=>$b}@_)[0]}->(3,2,1)
------------------------------
Date: Wed, 13 Sep 2000 11:57:49 -0500
From: "Chris Stith" <mischief@motion.net>
Subject: Re: min function
Message-Id: <srvcdg1dct626@corp.supernews.com>
"Tom Christiansen" <tchrist@perl.com> wrote in message
news:39be2cbd$1@cs.colorado.edu...
> In article <39BE2535.5BF72AF3@cat.com>,
> Shawn Ribordy <Ribordy_Shawn_C@cat.com> wrote:
> >I have looked all over the place, and I cannot find a min function. Can
> >anyone help?
>
> Are you saying you don't know how to write one?
>
> --tom
We have a modulus operator, so why not a min and a max?
Where's that wishlist for Perl6 again?
Chris Stith
---
Christopher E. Stith
mischief@(motion.net|pikenet.net)
print(stderr "SpamMaster found invalid email $address.\n")
------------------------------
Date: Wed, 13 Sep 2000 17:59:02 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: min function
Message-Id: <srvg36ect619@corp.supernews.com>
Chris Stith (mischief@motion.net) wrote:
: We have a modulus operator, so why not a min and a max?
: Where's that wishlist for Perl6 again?
I would propose making the syntax for min and max parallel that for sort.
That way you could specify your own comparison block, or take the default
cmp as the min/maximization criterion. Parsimony would argue for
implementing only min, and letting users get max by reversing the
comparsion logic, but since when is Perl parsimonious? :)
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "Every force evolves a form."
| - Shriekback
------------------------------
Date: Wed, 13 Sep 2000 15:56:31 GMT
From: "David Sisk" <davesisk@ipass.net>
Subject: Newbie question: Is Perl a good choice for this?
Message-Id: <PsNv5.2846$IV1.895748@typhoon.southeast.rr.com>
I want to create a CGI script (unix) that retrieves data from a second URL,
performs some calculations, then spits out the calculated values as HTML.
Obviously, Perl's good for #1 and #3, how well does it handle math calcs?
How advanced does it allow you to get (ie. does it have say, square root,
log, etc., functions above and beyond simply add/subtract/multiply/divide)?
Regards,
Dave
------------------------------
Date: Wed, 13 Sep 2000 09:09:05 -0700
From: "Christopher M. Jones" <christopher_j@uswest.net>
Subject: Re: Newbie question: Is Perl a good choice for this?
Message-Id: <uENv5.965$jd2.91518@news.uswest.net>
"David Sisk" <davesisk@ipass.net> wrote:
> I want to create a CGI script (unix) that retrieves data from a second
URL,
> performs some calculations, then spits out the calculated values as HTML.
> Obviously, Perl's good for #1 and #3, how well does it handle math calcs?
> How advanced does it allow you to get (ie. does it have say, square root,
> log, etc., functions above and beyond simply
add/subtract/multiply/divide)?
Yeah, perl would work great for that. Perl has the standard math
functions (or at least what I would consider standard), log, exp,
roots, trig, etc. Probably suitable for anything you need.
You can use abs, atan2, cos, exp, int, log, rand, sin, sqrt, and srand
without using any additional modules. If you want anything more
sophisticated you should probabably use the Math module.
------------------------------
Date: Wed, 13 Sep 2000 16:25:18 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: Newbie question: Is Perl a good choice for this?
Message-Id: <OTNv5.233861$Gh.5444204@news20.bellglobal.com>
David Sisk <davesisk@ipass.net> wrote:
: I want to create a CGI script (unix) that retrieves data from a second URL,
: performs some calculations, then spits out the calculated values as HTML.
: Obviously, Perl's good for #1 and #3, how well does it handle math calcs?
: How advanced does it allow you to get (ie. does it have say, square root,
: log, etc., functions above and beyond simply add/subtract/multiply/divide)?
'perldoc perlfunc' will give you all the builtin functions, of which
of course math functions are a subset.
This being said...
perl -e'print "Yup, we do math" if abs int exp log sqrt atan2 156, 10**2'
Joy,
Yanick
--
eval" use 'that poor Yanick' ";
print map{ (sort keys %{{ map({$_=>1}split'',$@) }})[hex] }
qw/8 b 15 1 9 10 11 15 c b 13 1 12 b 13 f 1 c 9 a e b 13 0/;
------------------------------
Date: 13 Sep 2000 18:01:51 GMT
From: dha@panix.com (David H. Adler)
Subject: Re: Newbie to CGI
Message-Id: <slrn8rvg8f.1ik.dha@panix2.panix.com>
On Tue, 12 Sep 2000 21:43:54 +0100, Tigz <tigz@ntlworld.com> wrote:
>Well I am sorry David!, I if you have read the subject line you will have
>reilized that it says "Newbie to CGI". Now that to me, seems a good enough
>explanation as to why it has been posted in the wrong newsgroup!!!
A) as others have pointed out, this is not considered a good
explanation for this.
B) Hey, it's not like I didn't suggest another place to ask... *shrug*
>You see i dont know all this stuff, like as it says in the subject, i am a
>newbe to cgi, all i know is that they are 2 programming languages.
If you "know" that, you're in trouble, as CGI is not, in fact, a
programming language...
best,
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
Trained Philosopher: Will Think For Food
- R. Dan Henry
------------------------------
Date: Wed, 13 Sep 2000 10:11:23 -0500
From: Russ Jones <russ_jones@rac.ray.com>
Subject: Re: OFF TOPIC IGNORE Re: killfiles? scores? I wish I had these luxuries
Message-Id: <39BF991B.65013CB6@rac.ray.com>
"Godzilla!" wrote:
>
> Use of killfiles is for
> weenies and bigots.
>
plonk and this time it's for good.
--
Russ Jones - HP OpenView IT/Operatons support
Raytheon Aircraft Company, Wichita KS
russ_jones@rac.ray.com 316-676-0747
Quae narravi, nullo modo negabo. - Catullus
------------------------------
Date: 13 Sep 2000 15:45:29 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: OFF TOPIC IGNORE Re: killfiles? scores? I wish I had these luxuries
Message-Id: <968859465.10053@itz.pp.sci.fi>
In article <39BEFD66.9C6CE7B9@stomp.stomp.tokyo>, Godzilla! wrote:
>
>Bigots for a good reason. If you have a person killfiled, which
>is usually done for the lamest of reasons, when you read a response
>to a killfiled person's article, you are only reading one side of
>a conversation and, most often, a hateful side of a conversation.
..and this, I'd like to say, is precisely why I love slrn scorefiles.
Not only are the troll's posts automatically marked as deleted, but so
are any replies to them as well. The signal/noise ratio went way up.
And I can still read them if the thread outline looks interesting.
[If you reply to this in the newsgroup, I probably won't notice it.]
--
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla | "By promoting postconditions to
and its pseudonyms - | preconditions, algorithms become
do not feed the troll. | remarkably simple." -- Abigail
------------------------------
Date: 12 Sep 2000 23:17:40 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Passing hashes to a function
Message-Id: <m38zsxdixn.fsf@dhcp11-177.support.tivoli.com>
Geoff Soper <g.soper@soundhouse.co.uk> writes:
> In article <39be76fe@news.victoria.tc.ca>,
> Malcolm Dew-Jones <yf110@vtn1.victoria.tc.ca> wrote:
> > recommended reading
>
> > perldoc perlsub (DESCRIPTION para. 2)
> > and
> > perldoc perlref
>
>
> > You need to use something like
> > print_edit_form("ammend",\%mod_users,\%old_users);
> > (note the \'s)
>
> > and then inside the function the hashes must use the $hash-> notation
> > (sometimes you might have to add braces as well as adding a -> )
>
> OK, I've read the relavent chapter in "Programming Perl" (there's little
> in "Learning Perl") but I feel don't really understand the concept of
> references. What do I do in my case to the hashes inside the function i.e.
> in the four different occurances of the %form_data hash as illustrated in
> the four extracts below?
>
> my ($action,%form_data,%hidden_form_data)= @_;
>
> foreach $user ( keys %form_data ) {
>
> if ($form_data{$user}{"status"} eq "live") {
>
> <input type="hidden" name="data:$user:user"
> value="$form_data{$user}{"user"}">$user</td>
>
> I hope this makes sense!
After reading it a couple of times, I think I understand your
question.
You want to know what changes to make inside the function to go along
with the changes that Malcolm recommended for the function call, yes?
OK, here you go (obviously, the rest of the function is missing, but
the biggest problem I had understanding your question was the missing
context of the code being inside the function):
sub print_edit_form {
# $form_data and $hidden_form_data are hashrefs
my ($action, $form_data, $hidden_form_data) = @_;
foreach my $user ( keys %$form_data ) {
if ($form_data->{$user}{status} eq "live") {
print <<EOD;
<input type="hidden" name="data:$user:user"
value="$form_data->{$user}{user}">$user</td>
EOD
}
}
}
HTH...
@ARGV=split/(.[A-Z])/=>qq$aJusthAnotherjPerlpHacker,$;shift;
$\=$/;$_{$_}=shift while$_=shift;$$_=$_{$_}for keys%_;
$_=join$,=>sort keys%_;s%.(.)%qq@$1$${&}$"@%geand print
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Wed, 13 Sep 2000 19:02:32 +0200
From: "Eirik Johansen [netmaking.com]" <eirik@netmaking.com>
Subject: Re: Perl script printing to MAIL header
Message-Id: <39BFB327.12AA29D0@netmaking.com>
Hi Gwyn,
> >I was wondering if it's possible to print to the MAIL header when
> >sending a MAIL through a Perl script. If it is, how do I access
> >the mail header? (I want to append a content-type and
> >mime-version line).
>
> Well there are many ways of sending mail with Perl. How are you doing
> it?
By using sendmail. Do you need any other information?
Best,
Eirik
------------------------------
Date: Wed, 13 Sep 2000 16:42:44 +0100
From: "John Plaxton" <19wlr@globalnet.co.uk>
Subject: re: Problem running script from within a script
Message-Id: <8po7dv$p86$1@gxsn.com>
Hi there, this newby needs help!
I'm trying to open a script i.e. 'test.cgi' from within another script. How
is it done.
I'm using cgi.pm
I've tried :
$foo->redirect('http://www.thisdontwork.com/cgi-bin/test.cgi'); which gives
a blank screen
I've tried :
open(FILE,"test.cgi");
@lines = <FILE>;
close FILE;
foreach $line (@lines) {print"<p>$line";} this sends a print out of the
code to the browser!
------------------------------
Date: Wed, 13 Sep 2000 09:03:20 -0700
From: "Christopher M. Jones" <christopher_j@uswest.net>
Subject: Re: Qualifications for new Perl programmer?????
Message-Id: <7zNv5.947$jd2.88549@news.uswest.net>
"Russ Jones" <russ_jones@rac.ray.com> wrote:
> "Christopher M. Jones" wrote:
> >
> > In most states a law
> > abiding citizen can fairly easily acquire and legally
> > own a machine gun.
>
> Can you get me a Silkworm surface to air missile?
I suppose I could if I had the money and I really wanted
one. It's not like the chinese are very picky about who
they sell those things too.
------------------------------
Date: Wed, 13 Sep 2000 15:57:30 GMT
From: Richard Lawrence <ralawrence@my-deja.com>
Subject: Re: Qualifications for new Perl programmer?????
Message-Id: <8po84t$s70$1@nnrp1.deja.com>
In article <39BF90A6.C7A2A51D@stomp.stomp.tokyo>,
"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:
>
> Nevertheless you continue to spew a rant with malice intent about
> who knows whatever anal retentive asinine techniques in making
> a complete arse of yourself.
If you could highlight the comments that convey malice then I would
appreciate it. Otherwise I'd suggest you refrain from making
accusations unless you have something substantial to back it up.
You are perfectly entitled to your opinions. I am also perfectly
entitled to tell you how the IT world works (given that you do not work
in that field). There is no need to degenerate a discussion into name
calling.
> Such ignorance is inexcusable. Have you considered seeking
> employment with a reputable firm such as K-Mart or Wally World?
I'm sorry. Obviously an English teacher knows more about development,
the qualifications for it and the IT world than an e-commerce project
manager for a FTSE 100 company.
Rich
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 13 Sep 2000 10:54:25 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Qualifications for new Perl programmer?????
Message-Id: <39BFBF51.6AF3E7DB@stomp.stomp.tokyo>
Richard Lawrence wrote:
> Godzilla! wrote:
(clearly snipped)
> Rich
Do you ever plan to improve your reading
comprehension skills, Frank?
Godzilla!
--
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class
------------------------------
Date: Wed, 13 Sep 2000 12:57:19 -0400
From: "Robert Jones" <robert@purdy.com>
Subject: reading packet from C++ code
Message-Id: <8poble$mma$1@news.chatlink.com>
I have a perl script reading a UDP packet sent from a C++ program. My perl
script can read most of the packet but not all of it. Below is section of
the C++ code that creates the packet.
-----------------------------------------
typedef unsigned int dword;
typedef unsigned short word;
struct ServerInfoPacket {
dword version,size;
char servname[32];
word port;
int phase;
bool thin;
struct {
int min,max;
} ping_limit;
char cfg[128];
};
--------------------------------------
I am trying to read the packet from Perl like this :
my @readpacket = unpack("I,I,A32,S,I,I,I,A128", $message);
version, size, servname, port, and cfg is all OK and readable.
phase, min, and max are not readable. What am I doing wrong ?
Thanks in advance for any help someone can give me, I'm about to go nuts
with this.
-Robert J.
------------------------------
Date: Wed, 13 Sep 2000 11:41:00 -0500
From: "Andrew N. McGuire " <anmcguire@ce.mediaone.net>
Subject: Re: Silly grep tricks
Message-Id: <Pine.LNX.4.21.0009131136551.23374-100000@hawk.ce.mediaone.net>
On 13 Sep 2000, Villy Kruse quoth:
VK> On Tue, 12 Sep 2000 22:07:10 -0500,
VK> Andrew N. McGuire <anmcguire@ce.mediaone.net> wrote:
VK>
VK>
VK> >On 12 Sep 2000, kj0 quoth:
VK> >
VK> >k> Is there a way to get grep to return only the first item (if any) in a
VK> >k> list for which the test is true?
VK> >
VK> >grep [options] PATTERN [FILE...] | head -1
VK> >
VK> >springs to mind..
VK> >
VK>
VK> Especialy if you are a shell programmer instead of a Perl programmer.
VK> In this NG it is rather more likely that the OP was asking about the Perl
VK> function grep, rather than the unix program with the same name.
My apologies, you are absolutely correct, I thought I was in
comp.os.linux.misc (the subject threw me off a little). In other
words, I fell asleep at the keyboard. I am a lover of Perl,
but also a UNIX admin, so I got a little mixed up. :-(
Best Wishes!
anm
--
print map y="= = && $_ => <"\bJust> =>
=> <"Another> =>
=> <"Perl> =>
=> <"Hacker\n> =>
------------------------------
Date: Wed, 13 Sep 2000 15:50:43 GMT
From: Cynthia Rossbach <crossbach@atgi.net>
Subject: slick way to look at array?
Message-Id: <39BF877C.EAEA3368@atgi.net>
Hi Folks,
What is a slick way to do the following (one liner perferred):
$answer = Is ("tt Admin" or "Admin" or "tt Assign") in @groups ?
Where $answer would be "true" or "false" and or "1" or "0" ?????
TIA, Cynthia
--
Cynthia Rossbach
Advanced TelCom Group, Inc.
crossbach@atgi.net
707.284.5242
------------------------------
Date: Wed, 13 Sep 2000 10:55:25 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: slick way to look at array?
Message-Id: <39BFA36D.9F4C26AD@texas.net>
Cynthia Rossbach wrote:
>
> Hi Folks,
>
> What is a slick way to do the following (one liner perferred):
>
> $answer = Is ("tt Admin" or "Admin" or "tt Assign") in @groups ?
perldoc -q element
- Tom
------------------------------
Date: 13 Sep 2000 17:04:49 GMT
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: slick way to look at array?
Message-Id: <8poc3h$m56@gap.cco.caltech.edu>
In article <39BF877C.EAEA3368@atgi.net>,
Cynthia Rossbach <crossbach@atgi.net> wrote:
>What is a slick way to do the following (one liner perferred):
>
>$answer = Is ("tt Admin" or "Admin" or "tt Assign") in @groups ?
>
>Where $answer would be "true" or "false" and or "1" or "0" ?????
See also perlfaq4, "How can I tell whether a list or array contains
a certain element?"
my %groups_hash;
@groups_hash{@groups} = ();
$answer = exists $groups_hash{"tt Admin"} ||
exists $groups_hash{"Admin"} ||
exists $groups_hash{"tt Assign"} || 0;
(The last || 0 is so that it returns 1 or 0 instead of 1 or "" --
you can remove it if "" as acceptable as a not-found value);
Depending on what else you use @groups for, you may be able to
replace it entirely with a hash.
-- Gary
golfing: $answer=!!grep/^((tt )?Admi|Assig)n$/,@groups;
------------------------------
Date: Wed, 13 Sep 2000 08:09:38 -0700
From: "Christopher M. Jones" <christopher_j@uswest.net>
Subject: Re: String compression
Message-Id: <JMMv5.783$jd2.72967@news.uswest.net>
"Jeff Pinyan" <jeffp@crusoe.net> wrote:
> sub num2chr {
> my $n = shift;
> my $c;
> while ($n) {
> $c .= chr($n % 256);
> $n >>= 8;
> }
> return $c;
> }
Are you serious?!
$foo = pack("L", $n);
bing bang boom, done
------------------------------
Date: Wed, 13 Sep 2000 16:13:34 GMT
From: tebrusca@my-deja.com
Subject: Re: Unix Info
Message-Id: <8po92o$tka$1@nnrp1.deja.com>
In article <8pno3b$8kt$1@nnrp1.deja.com>,
scarey_man@my-deja.com wrote:
> Is there an easy way to extract info on a unix box
> e.g. Number of CPU's, cpu types, installed memory etc?
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
This will be very dependant on the flavor of UNIX.
I have a similar need but I haven't found an elegant solution.
HPUX - kludgey things like this can get number of CPU's
ioscan -fkC processor | grep '^proc' | wc -l
IRIX - has sysinfo and sysconf and getconf
getconf NUM_PROCESSORS
Try checking other news groups too, thats where I got these,
if you're looking for a module ... I haven't found one.
Closest I've seen is POSIX.pm.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
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 4313
**************************************