[16588] in Perl-Users-Digest
Perl-Users Digest, Issue: 4000 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 13 06:05:50 2000
Date: Sun, 13 Aug 2000 03:05:09 -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: <966161108-v9-i4000@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 13 Aug 2000 Volume: 9 Number: 4000
Today's topics:
Access using basic authorization and Sockets ak_perl@my-deja.com
Re: calculating with getting a formula out of a $string (Martien Verbruggen)
Re: Commenting portions of code (Abigail)
Re: convert a variable from 8/12/00 to 8-12-00 <vrillusions@mail.com>
Re: convert a variable from 8/12/00 to 8-12-00 <alesr@siol.net>
Re: convert a variable from 8/12/00 to 8-12-00 <christopher_j@uswest.net>
duplicating STDIN <dontspamme@awdang.com>
Javascript to Perl <andychu@hotmail.com>
Re: lamer problem of commiting a perl script (Abigail)
Re: lamer problem of commiting a perl script <christopher_j@uswest.net>
Re: London =?iso-8859-1?Q?=A330-35K?= Perl Programmers (David H. Adler)
Re: map | grep (Decklin Foster)
Need some debuging help <vrillusions@mail.com>
Re: Negativity in Newsgroup (David H. Adler)
Re: Sort data from text file <christopher_j@uswest.net>
Re: Trouble with example <studentfl@hotmail.com>
URGENT ---> How do keep a socket open while ..... ( Pl <superegoNOsuSPAM@execs.com.invalid>
Re: URGENT ---> How do keep a socket open while ..... <mcc1312@yahoo.com>
utime Function Not Working centelec@my-deja.com
Re: utime Function Not Working (Decklin Foster)
Re: utime Function Not Working <lr@hpl.hp.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 13 Aug 2000 09:24:23 GMT
From: ak_perl@my-deja.com
Subject: Access using basic authorization and Sockets
Message-Id: <8n5pg6$qts$1@nnrp1.deja.com>
Hi,
I have a script accessible from a browser via port 648, the directory uses
basic authorization. For direct access from the browser the URL would be
"username:password@domainname.com:648/directory/scriptname.cgi".
I want to be able to pass info, and read the resulting output, to this script
from another perl script running on a different machine. I have the following
code for the second script:
$server = "www.domainname.com"; $request1 = "/directory/scriptname.cgi";
socket(SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp')) ||
safedie("first");
$saddr = sockaddr_in(648, inet_aton($server));
connect(SOCK, $saddr) || safedie("second");
$offset = 0;
$buff = $request1."\r\n";
$len = length($buff);
while($len){
$written = syswrite(SOCK,$buff,$len,$offset);
$len -= $written;
$offset += $written;
}
@result = <SOCK>;
close(SOCK);
Ofcourse, doing this results in the message that I'm not authorized.
Can someone help me how I can pass the username and password to the remote
server? I can't find any info on this anywhere....
Thanx!
Adrian
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 13 Aug 2000 04:33:43 GMT
From: mgjv@martien.heliotrope.home (Martien Verbruggen)
Subject: Re: calculating with getting a formula out of a $string
Message-Id: <slrn8pc8p4.65c.mgjv@martien.heliotrope.home>
[repost. For some reason, the original from yesterday never made it
through]
On 11 Aug 2000 17:13:55 +0100,
nobull@mail.com <nobull@mail.com> wrote:
> mgjv@martien.heliotrope.home (Martien Verbruggen) writes:
>
> So that would be an argument for writing it as:
>
> $formula = sub { my ($thing) = @_; $thing * 1.16 };
No. That's taking it too far. In real code, with large subs, I would
probably do that, but my main objection was the use of $_ in a place
where one normally would see $_[0]. Fine for anyone who knows how to use
it, but didactically a dangerous thing to do. As I said before, Perl's
variable and array syntax, combined with the names of builtins can be
very confusing for the unsuspecting passer-by who happens to read that,
read it not deeply enough, and think, "Hey, I didn't know you could just
use $_ for that as well!". It can be useful, and it can be very fast,
but if you're writing example code that is going to be read by hyndreds
of inexperienced perl programmers, I'd say you need to take extra care
in explaining what's going on.
That last bit was what I was trying to do mainly :)
>
> > There hardly is any payoff in it, and a lot of possibilities for
> > error and/or misinterpreation.
>
> TMTOWTDT
>
> I understand Martien's reasoning but I still disagree. If you are
> going to object to "implicit argument" in this context then you must
> object to it completely.
>
> Martien, do you object to:
> s/x/y/ for @a;
Not at all. Use it all the time. Or I use for as a 'switch' wrapper. But
I'd probably hesitate presenting this code at the third lesson in a
beginner's course in perl :)
> If not then what is wrong with:
> my $mutator = sub { s/x/y/ };
> &$mutator for @a;
Nothing. But someone who doesn't know Perl iquite well will have a hard
time figuring out why that works.
> Once you have accepted that then you should accept:
> my $mutator = sub { $_ .= 'x' };
> &$mutator for @a;
My points wasn't that there is something wrong with the technique, but
more with the presentation. Using less well-understood bits of perl on a
public newsgroup warrants explanation. If someone else adds that
explanation, that should be fine :)
Martien
--
Martien Verbruggen |
Interactive Media Division | Never hire a poor lawyer. Never buy
Commercial Dynamics Pty. Ltd. | from a rich salesperson.
NSW, Australia |
------------------------------
Date: 13 Aug 2000 05:27:16 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Commenting portions of code
Message-Id: <slrn8pccck.tj3.abigail@alexandra.foad.org>
Javier Hijas (jhijas@yahoo.es) wrote on MMDXXXV September MCMXCIII in
<URL:news:39912DE2.BB722F81@yahoo.es>:
}} Is there any way to comment portion of code in perl in the way /*...*/
}} does in C, I mean not having to use # to comment every line?
FAQ
Abigail
--
perl -Mstrict -we '$_ = "goto G.print chop;\n=rekcaH lreP rehtona tsuJ";G1:eval'
------------------------------
Date: Sun, 13 Aug 2000 05:10:45 GMT
From: Todd Eddy <vrillusions@mail.com>
Subject: Re: convert a variable from 8/12/00 to 8-12-00
Message-Id: <39962DE1.A986FFDB@mail.com>
Thanks, worked perfectly
Mark-Jason Dominus wrote:
> $filename = '8/12/00';
> $filename =~ tr[/][-]; # replace /es with -es
> print $filename;
--
Todd Eddy
vrillusions@mail.com
http://www.vrillusions.com/
------------------------------
Date: Sun, 13 Aug 2000 08:41:58 +0200
From: marvin <alesr@siol.net>
Subject: Re: convert a variable from 8/12/00 to 8-12-00
Message-Id: <39964334.25F@siol.net>
Todd Eddy wrote:
>
> I want to create a filename that is based on the date, the person I am
> making this for insists that the date when displayed uses /s And I
> currently use a simple SSI page to insert the date everywhere, so it has
> to go to the cgi script as 8/12/00. The only way I can think of doing
> it is splitting it into 3 different variables, and then reinserting it
> as $mo."-".$day."-".$yr. But there has to be some sort of
> search-and-replace like function in cgi.
>
> --
> Todd Eddy
> vrillusions@mail.com
> http://www.vrillusions.com/
You can also use substr function to replace / with - but you must
first locate -'s
$date="8/12/00";
substr($date,1,1)="-";
substr($date,4,1)="-";
------------------------------
Date: Sun, 13 Aug 2000 01:39:30 -0700
From: "Christopher M. Jones" <christopher_j@uswest.net>
Subject: Re: convert a variable from 8/12/00 to 8-12-00
Message-Id: <_8tl5.1250$3C5.396019@news.uswest.net>
"marvin" <alesr@siol.net> wrote:
> You can also use substr function to replace / with - but you must
> first locate -'s
> $date="8/12/00";
> substr($date,1,1)="-";
> substr($date,4,1)="-";
Gark!
Perl has a character translation built in, use it.
$date =~ tr/\//-/;
or
$date =~ tr(/)(-);
if you think that's prettier.
------------------------------
Date: Sun, 13 Aug 2000 07:01:25 GMT
From: LimboStar <dontspamme@awdang.com>
Subject: duplicating STDIN
Message-Id: <8n5h45$l9f$1@nnrp1.deja.com>
I'm almost positive this is impossible, but I'm asking anway.
I'm working a very large CGI script that I began development on a long
time ago, before I knew about CGI.pm. I quickly developed my own
personal version, extremely dumbed down, which parses the input data
into things passed by GET and things passed by POST.
Now I've learned some, and I've become Impatient and Lazy. I'm adding
web-based email into what has become a suite of scripts based on my
very naive CGI handler. And that's the problem - the webmail script
I'm using (NeoMail) wisely was Lazy and Impatient and uses CGI.pm.
But because my scripts read the POST data into a hash, it isn't there
when NeoMail goes looking for it. I got away with this for a while by
saying:
foreach(keys %POSTFORM){param($_,$POSTFORM{$_});}
That worked like a charm and I thought I was very clever. But then
NeoMail had to go and try to read_multipart, which barfs since I done
screwed it up already by parsing it on my own.
So, now my options, as I see them, are:
1) rewrite my entire suite of scripts to use CGI.pm, which would take
approximately forever;
2) somehow read in the data, parse it, and then put it back so it's
there for NeoMail (not bloody likely)
3) overhaul my library to use CGI.pm and have it tell me what's
passed on what form.
The third is probably the best choice, and the only thing that's
stopping me from doing it right now is that my suite of scripts
differentiates between GET and POST, storing them in seperate hashes.
If CGI.pm can seperate them, that's great - I'll just have it do that
and be on my merry way.
So, how do I do that? Can I do that?
Or, I can rip out the parts I need just to get NeoMail running and
integrated, but that wouldn't be very pretty, and I'm looking for the
quick fix.
Thanks in advance.
--
Stephen.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Sun, 13 Aug 2000 14:18:07 +0800
From: Andy <andychu@hotmail.com>
Subject: Javascript to Perl
Message-Id: <39963D9F.DF58BBD9@hotmail.com>
Does anyone know how to pass the value from Javascript to Perl?
Example:
code segment in the javascript:
<script language="Javascript">
function add(value){
var myvalue = Math.abs(value) + 100;
}
</script>
------------------------------------------------------------------
code segment in the perl:
<a href="anyscript.cgi?thevalue=myvalue" onclick="add(10)">test</a>
after clicked the link - test, the value "10" was added to myvalue and
get the result "110", and i want to get this result and put it into the
perl code like above, but it doesn't work, does anyone know how to solve
it?
Thanks for any help!
Andy Chu
------------------------------
Date: 13 Aug 2000 06:27:00 GMT
From: abigail@foad.org (Abigail)
Subject: Re: lamer problem of commiting a perl script
Message-Id: <slrn8pcfsj.tj3.abigail@alexandra.foad.org>
HD (elbereth*nospam*@gmx.de) wrote on MMDXXXV September MCMXCIII in
<URL:news:8mrjg7$6pp$1@news01.khis.de>:
## I am starting in perl a few days ago
##
## #!/usr/bin/perl
Bug 1: There's no -w.
Bug 2: There's no -T.
Bug 3: There's no "use strict;"
Bug 4: There's no "use CGI;"
##
##
## if($ENV{'REQUEST_METHOD'} eq 'GET')
## {
## $Daten = $ENV{'QUERY_STRING'}
## }
## else
## {
## read(STDIN, $Daten, $ENV{'CONTENT_LENGTH'});
## }
##
## @Formularfelder = split(/&/, $Daten);
## foreach $Feld (@Formularfelder)
## {
## ($name, $value) = split(/=/, $Feld);
## $value =~ tr/+/ /;
## $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
## $value =~ s/<!--(.|\n)*-->//g;
Bug 5: That doesn't match HTML comments.
## $Formular[$i] = $name;
## $i = $i + 1;
## $Formular[$i] = $value;
## $i = $i + 1;
## }
Bug 6: Bad cargo cult programming.
##
## print "Content-type: text/html\n\n";
## print "<html>\n";
## print "<head>\n";
## print "<title>Danke!</title>\n";
## print "</head>\n";
## print "<body bgcolor=#FFFFFF text=#000000 link=#009900 vlink=006600
## alink=#0000FF>\n";
Bug 7: Invalid HTML syntax.
## print "<h1>Danke</h1>\n";
## print "Wir freuen uns, daß Sie unser Formular ausgefüllt \n";
## print "haben. Hier zur Kontrolle Ihre Angaben:<p>\n";
Bug 8: Use of multiple prints instead of here document.
## for($i=0;$i<=$max;$i=$i+2)
Bug 9: Use of C idiom.
Bug 10: No hash used.
## {
## print "<b>$Formular[$i]:</b> $Formular[$i+1]<br>\n";
## }
## print "<p><hr noshade size=1><p>";
## print "<i>Ihr Name, <a href=\"mailto:IhrName\@Provider.xx\">IhrName\@Provi>>>
## print "</body>\n";
## print "</html>\n";
##
##
## I checked the syntax of the script and everything went right. I uploaded t>>>
## But after running the script I got only the script, what did I wrong? Do I>>>
There are many problem with your program, but what you are complaining
about has nothing to do with the program, but with server configuration.
And that's not dealt with in this group.
And use lines less than 80 characters.
Abigail
--
sub A::TIESCALAR{bless\my$x=>'A'};package B;@q=qw/Hacker Perl
Another Just/;use overload'""',sub{pop @q};sub A::FETCH{bless
\my $y=>B};tie my$shoe=>'A';print"$shoe $shoe $shoe $shoe\n";
------------------------------
Date: Sun, 13 Aug 2000 01:31:16 -0700
From: "Christopher M. Jones" <christopher_j@uswest.net>
Subject: Re: lamer problem of commiting a perl script
Message-Id: <f1tl5.1241$3C5.393296@news.uswest.net>
"Abigail" <abigail@foad.org> wrote:
> HD (elbereth*nospam*@gmx.de) wrote on MMDXXXV September MCMXCIII in
> <URL:news:8mrjg7$6pp$1@news01.khis.de>:
> ## I am starting in perl a few days ago
> ##
> ## #!/usr/bin/perl
>
> Bug 1: There's no -w.
> Bug 2: There's no -T.
> Bug 3: There's no "use strict;"
> Bug 4: There's no "use CGI;"
Sheesh, take the stick out of your ass for at least a
few minutes a day. Not everyone needs to program like
you do.
>
> ##
> ##
> ## if($ENV{'REQUEST_METHOD'} eq 'GET')
> ## {
> ## $Daten = $ENV{'QUERY_STRING'}
> ## }
> ## else
> ## {
> ## read(STDIN, $Daten, $ENV{'CONTENT_LENGTH'});
> ## }
> ##
> ## @Formularfelder = split(/&/, $Daten);
> ## foreach $Feld (@Formularfelder)
> ## {
> ## ($name, $value) = split(/=/, $Feld);
> ## $value =~ tr/+/ /;
> ## $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> ## $value =~ s/<!--(.|\n)*-->//g;
>
> Bug 5: That doesn't match HTML comments.
Oh, not like you'd actually want to help the poor guy?
BTW, it should be something like
$value =~ s/<!--.*?-->//gs;
>
> ## $Formular[$i] = $name;
> ## $i = $i + 1;
> ## $Formular[$i] = $value;
> ## $i = $i + 1;
> ## }
>
> Bug 6: Bad cargo cult programming.
Agreed, but again, if you're here just to bitch at people,
perhaps you should get a real hobby.
BTW, something like
$Formular{$name} = $value;
is probably more useful.
>
> ##
> ## print "Content-type: text/html\n\n";
> ## print "<html>\n";
> ## print "<head>\n";
> ## print "<title>Danke!</title>\n";
> ## print "</head>\n";
> ## print "<body bgcolor=#FFFFFF text=#000000 link=#009900 vlink=006600
> ## alink=#0000FF>\n";
>
> Bug 7: Invalid HTML syntax.
Invalid? When did you become the W3C?
It'll work perfectly fine and that's all that really
matters.
>
> ## print "<h1>Danke</h1>\n";
> ## print "Wir freuen uns, daß Sie unser Formular ausgefüllt
\n";
> ## print "haben. Hier zur Kontrolle Ihre Angaben:<p>\n";
>
> Bug 8: Use of multiple prints instead of here document.
Again, not everyone has to program like the great
bitch-goddess from the sky.
------------------------------
Date: 13 Aug 2000 05:13:06 GMT
From: dha@panix.com (David H. Adler)
Subject: Re: London =?iso-8859-1?Q?=A330-35K?= Perl Programmers Required
Message-Id: <slrn8pcbj2.q02.dha@panix6.panix.com>
On Fri, 11 Aug 2000 15:17:31 -0700, Steve Leibel <stevel@bluetuna.com> wrote:
>In article <slrn8p8nbh.cu2.dha@panix2.panix.com>, dha@panix.com (David H.
>Adler) wrote:
>
>> Longstanding Usenet tradition dictates that such postings go into
>> groups with names that contain "jobs", like "misc.jobs.offered", not
>> technical discussion groups like the ones to which you posted.
>>
>
>
>Don't be silly. "Longstanding Usenet tradition" dictates that newsgroups
>are flooded with spam, trolls, job postings, all-encompassing theories
>of the universe put forth by lunatics and cranks, and of course live nude
>jpegs of Britney Spears.
I think you may be confusing Longstanding Disregard for Usenet
Tradition, with Longstanding Usenet Tradition. :-|
And where *are* them Britney pix, huh??? :-)
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"i don't play lead. it interferes with my drinking." - Malcolm Young
------------------------------
Date: Sun, 13 Aug 2000 04:44:56 GMT
From: decklin+usenet@red-bean.com (Decklin Foster)
Subject: Re: map | grep
Message-Id: <cJpl5.18974$f_5.85585@news1.rdc1.ct.home.com>
johnvert@my-deja.com <johnvert@my-deja.com> writes:
> I'm wondering what is the difference between:
>
> 1. my @list=qw(1 2 3 4);
> my %t=grep { $_ => "foo" } @list;
> for (keys %t) { print "$_ : $t{$_}\n"; }
(I assume you meant to replace grep with map in the second copy...)
What happened when you tried it?
[I will pause here so that you can try it]
OK, so your real question is 'why'. Read the documentation for grep
and map. It says that grep tests the expression in your BLOCK for
truth or falsity, and map evaluates the block. Note that different
things are pushed onto the returned list in each case.
So, consider the difference between testing
$_ => "foo" # equivalent to $_, "foo"
as a boolean expression, and merely evaluated. In the latter case, a
list is acceptable, so that's what gets returned. In the former, we
need to test a single scalar expression, so the comma is treated as a
comma operator -- throwing out $_ and returning "foo" which is always
true. This is why the single element gets pushed onto the return list
every time.
> also, I heard map / grep should not be used instead of a plain loop,
> so what are very simple examples where they might be used?
If you don't do anything with the return value of map, the current
implementation still has to create it, which can slow you down. Look
in the recent archives of this group for 'map in a void context'.
--
There is no TRUTH. There is no REALITY. There is no CONSISTENCY. There
are no ABSOLUTE STATEMENTS. I'm very probably wrong. -- BSD fortune(6)
------------------------------
Date: Sun, 13 Aug 2000 05:08:44 GMT
From: Todd Eddy <vrillusions@mail.com>
Subject: Need some debuging help
Message-Id: <39962D68.D29F04F1@mail.com>
I am working on making a script that will show the people that signed up
for a LAN party. I am trying to figure out why I can't get it display
the contents. You can test the script yourself at
http://www.vrillusions.com/cgi-bin/whoscoming/whoscoming.cgi?date=8/13/00
and here is the source of the HTML part of the script
print qq~
<HTML><HEAD>
<TITLE>Attendees for $date</TITLE>
</HEAD>
<BODY BGCOLOR="$html_bgcolor" TEXT="$html_text" LINK="$html_link"
VLINK="$html_vlink" ALINK="$html_alink">
<CENTER><H2>Here are the people registered for the $date LAN party</H2>
<P>
$datalocation
<TABLE WIDTH=500 BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TH ALIGN="left" WIDTH=100>Name</th>
<TH ALIGN="left" WIDTH=150>Call Sign</th>
<TH ALIGN="left" WIDTH=250>Location</th>
</TR>
~;
open (DATA, "$datalocation");
foreach (@lines) {
# Now split up the info:
showname|name|showemail|email|callsign|location
($df_showname, $df_name, $df_showemail, $df_email, $df_callsign,
$df_location) = split(/\|/, $_);
chomp $df_location;
if ($df_showname == 0) { $df_name = " "; }
if ($df_showemail == 1) { $df_name = "<A
HREF=\"mailto:".$df_email."\">".$df_name."<\/A>"; }
print "<TR>\n";
print " <TD VALIGN=\"middle\">$df_name</td>\n";
print " <TD VALIGN=\"middle\">$df_callsign</td>\n";
print " <TD VALIGN=\"middle\">$df_location</td>\n";
print "</TR>\n";
}
close DATA;
print qq~
</TABLE>
</P>
</CENTER>
</BODY></HTML>
~;
I checked it through perl and I had no errors, I checked all the
variables and they are what they're supposed to be.
--
Todd Eddy
vrillusions@mail.com
http://www.vrillusions.com/
------------------------------
Date: 13 Aug 2000 06:47:56 GMT
From: dha@panix.com (David H. Adler)
Subject: Re: Negativity in Newsgroup
Message-Id: <slrn8pch4s.q02.dha@panix6.panix.com>
On Sat, 12 Aug 2000 00:19:16 -0700, Steve Leibel <stevel@bluetuna.com> wrote:
>
>I've gotten and given tons of free advice from people on the Net for
>years. It's an amazing medium. When I get stuck, I "ask the Net," and
I think you've hit the nail on the head right there. The people who
get the type of answers you're talking about have *not* gotten stuck.
They've just stopped, and want someone to drag them along for a bit,
not get them out of a ditch. For reference, see Mr. Deeds Goes to Town.
dha, tortured metaphor and film reference be we.
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
In the silence that followed, Homer was heard to mutter,
"Mmmm... context- dependent semantics..."
- Darrin Edwards in c.l.p.m.
------------------------------
Date: Sun, 13 Aug 2000 01:10:01 -0700
From: "Christopher M. Jones" <christopher_j@uswest.net>
Subject: Re: Sort data from text file
Message-Id: <kJsl5.1238$3C5.385574@news.uswest.net>
bleh
What you *really* want is the Time::ParseDate module.
http://www.engelschall.com/ar/perldoc/pages/module/Time::ParseDate.html
This will parse the date into unix time (or, actually, into
just about any) format so you can easily sort it using a
hash and "sort keys ..." or whatever other type of sorting
you wish to do.
------------------------------
Date: Sun, 13 Aug 2000 09:14:34 GMT
From: "Robert Brooks" <studentfl@hotmail.com>
Subject: Re: Trouble with example
Message-Id: <_Ftl5.41488$eS6.745282@news1.rdc1.md.home.com>
Did you try to make a guess (say for fred), and make sure it works? Because
it does work for me. Anyone I put in there it makes the secret word
"groucho", which is the default if the hash lookup fails. This leads me to
believe that nothing is getting stored in the hash.
Here is my program:
-------------------------------------------------------------------
#!/usr/bin/perl -w
#print "Content-type: text/html\n\n";
init_words();
print "What is your name? : ";
$name = <STDIN>;
chomp ($name);
if ($name =~ /^randal\b/i) {
print "Hello, Randal! How good of you to be here!\n";
} else {
print "Hello, $name!\n";
print "What is the secret word? : ";
$guess = <STDIN>;
chomp ($guess);
while (! good_word($name,$guess)) {
print "Wrong, try again. What is the secret word? : ";
$guess = <STDIN>;
chomp ($guess);
}
} #end of if-else for name test (Randal)
sub init_words {
open (WORDSLIST, "wordslist")||
die "can't open file: $!";
while ($name = <WORDSLIST>) {
chomp ($name);
print "name is $name\n";
$word = <WORDSLIST>;
chomp ($word);
print "word is $word\n";
print "name is still $name\n";
$words{$name} = $word;
}
print "word fred : ";
print $words{fred};
print "\n";
close WORDSLIST;
}
sub good_word {
my($somename,$someguess) = @_;
$somename =~ s/\W.*//;
$somename =~ tr/A-Z/a-z/;
if ($somename eq "randal") {
return 1;
} elsif (($words{$somename} || "groucho") eq $someguess) {
return 1;
} else {
return 0;
}
}
-------------------------------------------------------------------
and here is the output:
-------------------------------------------------------------------
name is fred
word is camel
name is still fred
name is barney
word is llama
name is still barney
name is betty
word is alpaca
name is still betty
name is wilma
word is alpaca
name is still wilma
Use of uninitialized value at test.cgi line 41, <WORDSLIST> chunk 8.
word fred :
What is your name? : fred
Hello, fred!
What is the secret word? : camel
Wrong, try again. What is the secret word? : groucho
-------------------------------------------------------------------
Obviously, since
print $words{fred};
Does not print anything, there is nothing stored in the hash. I have gotten
some other feedback from the original post, but none of it has helped. It is
odd, because mine is right out of the book, and so is yours. But mine
doesn't work. Someone gave me the advice:
-------------------------------------------------------------------
No, $words is a scalar. You wanted to examine %words, not $words.
>1 #!/devl/perl/bin/perl -w
>2
>3==> my %words;
This has nothing to do with it. Try the script without it; you'll get
the same results, but examine %words, not $words at the end of the loop.
-------------------------------------------------------------------
But that didn't help.
If you can help, I would appreciate it. Like I said, my code above is
exactly out of the book, I have checked it many times. The only things I
added was the
-w and the print statements I inserted to see what was going on.
Thanks!
"goshawk" <goshawk@gnat.net> wrote in message
news:399594a3.10970455@news.gnat.net...
| I just happend ot have the 2nd addition of the learning perl book
|
| the sample you gave was actually a subroutine:
|
|
| sub init_words {
| open (WORDSLIST, "wordslist");
| while ($name = <WORDSLIST>) {
| chomp ($name);
| $word = <WORDSLIST>;
| chomp ($word);
| $words{$name} = $word;
| }
| }
|
| The file should be in the form:(first line in line pair is id, second
| line in line pair is password per sample)
|
| fred
| camel
| barney
| llama
| betty
| alpaca
| wilma
| alpaca
|
|
| The book did not use strict or -w
|
| the original code was:
| #!/usr/bin/perl
| %words = qw (
| fred camel
| barney llama
| betty alpaca
| wilma alpaca
| );
|
| to (new code)
|
| #!/usr/bin/perl
| init_words();
|
|
| I did not have any problems running from the command line, but when I
| used perl-d: ptkdb program.pl
| I had some some -w errors, but didn't spent much time on it as it was
| working fine from the command line.
|
| Pat
| http://www.gnat.net/~goshawk
| http://www.gypysfarm.com
|
------------------------------
Date: Sat, 12 Aug 2000 23:27:57 -0700
From: Savant_cubed <superegoNOsuSPAM@execs.com.invalid>
Subject: URGENT ---> How do keep a socket open while ..... ( Please read !!!)
Message-Id: <08199a04.ff938257@usw-ex0106-045.remarq.com>
If I wanted to keep a Socket open, send something to a webpage,
then after the user does something again get more information
from the socket and send more info to a webpage, How would I do
it ?
I think after I first send info from the socket to the
webpage the program will close the socket and end the program.
Is there any way to freeze the program until more input is
added, so that I may continually send and read to socket
depending on what happens from a webpage ? I know there has to
be a way to do this (or am I just a newbie ?)
-----------------------------------------------------------
Got questions? Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com
------------------------------
Date: Sun, 13 Aug 2000 08:34:16 GMT
From: "Camelot" <mcc1312@yahoo.com>
Subject: Re: URGENT ---> How do keep a socket open while ..... ( Please read !!!)
Message-Id: <c4tl5.155836$8u4.1481160@news1.rdc1.bc.home.com>
I don't know but in term of security sense, this is totally unacceptable.
Camelot.
"Savant_cubed" <superegoNOsuSPAM@execs.com.invalid> wrote in message
news:08199a04.ff938257@usw-ex0106-045.remarq.com...
> If I wanted to keep a Socket open, send something to a webpage,
> then after the user does something again get more information
> from the socket and send more info to a webpage, How would I do
> it ?
> I think after I first send info from the socket to the
> webpage the program will close the socket and end the program.
> Is there any way to freeze the program until more input is
> added, so that I may continually send and read to socket
> depending on what happens from a webpage ? I know there has to
> be a way to do this (or am I just a newbie ?)
>
>
> -----------------------------------------------------------
>
> Got questions? Get answers over the phone at Keen.com.
> Up to 100 minutes free!
> http://www.keen.com
>
------------------------------
Date: Sun, 13 Aug 2000 04:05:31 GMT
From: centelec@my-deja.com
Subject: utime Function Not Working
Message-Id: <8n56qa$etc$1@nnrp1.deja.com>
On a Windows NT server, I uploaded a file and tried to timestamp it.
After the script, I checked the modified date of the file with -M and
its zero's. The code follows:
open (OUTFILE, ">$basedir$fileName") || die "Can't open photo file!\n";
binmode(OUTFILE);
print "$basedir$fileName<br>";
while (read($file, my $buffer, 1024)) {
binmode($buffer);
print OUTFILE $buffer;
}
close (OUTFILE);
$path = "$basedir$fileName";
$ctime = time;
utime ($ctime,$ctime,'$path');
Any ideas why it won't timestamp the file??
Thanks,
Bob
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Sun, 13 Aug 2000 04:58:12 GMT
From: decklin+usenet@red-bean.com (Decklin Foster)
Subject: Re: utime Function Not Working
Message-Id: <EVpl5.18977$f_5.85652@news1.rdc1.ct.home.com>
centelec@my-deja.com <centelec@my-deja.com> writes:
> On a Windows NT server, I uploaded a file and tried to timestamp it.
> After the script, I checked the modified date of the file with -M and
> its zero's. The code follows:
Two questions...
1. How are you using -M? are you also checking with something besides
Perl?
2. Why are you updating the modification time on a file you just
modified?
> while (read($file, my $buffer, 1024)) {
> binmode($buffer);
Don't do that. Read the documentation for binmode and turn on -w.
--
There is no TRUTH. There is no REALITY. There is no CONSISTENCY. There
are no ABSOLUTE STATEMENTS. I'm very probably wrong. -- BSD fortune(6)
------------------------------
Date: Sat, 12 Aug 2000 23:41:01 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: utime Function Not Working
Message-Id: <MPG.13ffe2d4ee58c12898ac6f@nntp.hpl.hp.com>
In article <8n56qa$etc$1@nnrp1.deja.com>, centelec@my-deja.com says...
...
> $path = "$basedir$fileName";
> $ctime = time;
> utime ($ctime,$ctime,'$path');
>
> Any ideas why it won't timestamp the file??
Does the name of the file consist of the five characters
'$' 'p' 'a' 't' 'h'? I think not! Ditch the quotes.
Had you bothered to check the return value from utime, and printed $! if
utime failed, you ould have gotten a clearer view of the problem.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
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 4000
**************************************