[19741] in Perl-Users-Digest
Perl-Users Digest, Issue: 1936 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 16 00:05:44 2001
Date: Mon, 15 Oct 2001 21:05:07 -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: <1003205107-v10-i1936@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 15 Oct 2001 Volume: 10 Number: 1936
Today's topics:
Re: #!/usr/bin/perl not being parsed properly <jllachan@interlink.net>
Re: $x ||= $y; <aneely@softouch.on.ca>
Re: about special chars when split() (Clinton A. Pierce)
Re: backgrounding a system call <cherbst@hotpop.com>
Re: Difference between .pl, .cgi, and .pm File Extensio (Trewth Seeker)
Re: filehandle : localized typeglob - local $_ (F. Xavier Noria)
Re: How do you get paid for Perl work over the Internet <matthew.garrish@sympatico.ca>
Re: How do you get paid for Perl work over the Internet <aperlprogrammer@yahoo.com>
Re: How do you get paid for Perl work over the Internet <matthew.garrish@sympatico.ca>
how to retreive milliseconds (jimmyJIMMYyaya)
Re: how to retreive milliseconds <bart.lateur@skynet.be>
Re: how to retreive milliseconds (Martien Verbruggen)
I didn't do a very good job asking this... (David Filmer)
Re: I didn't do a very good job asking this... <tsee@gmx.net>
Re: I didn't do a very good job asking this... (Malcolm Dew-Jones)
Re: I didn't do a very good job asking this... (Martien Verbruggen)
Re: I didn't do a very good job asking this... (Randal L. Schwartz)
loading up modules <min_c_lee@yahoo.com>
Re: loading up modules (Clinton A. Pierce)
Need cgi script jh123@nc.rr.com
Re: Need cgi script <joe+usenet@sunstarsys.com>
newbie - initializing hash from a file doesn't work (Taku Tokuyasu)
Re: newbie question <mragsdal@utk.edu>
Re: Problems with ActiveState and MCPAN <peterm@zeta.org.au>
REDHATE 7 <silverrouge@hotmail.com>
Re: String To List <jay@utils.net.nospam>
Undefined variable in concatenation inconsistent (Martien Verbruggen)
Re: Undefined variable in concatenation inconsistent (Martien Verbruggen)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 15 Oct 2001 21:07:25 -0400
From: Jean-Luc Lachance <jllachan@interlink.net>
Subject: Re: #!/usr/bin/perl not being parsed properly
Message-Id: <3BCB884D.5A7F647F@interlink.net>
Well, turns out that there was a <CR> in my script - not this one but the=
one I
wrote.
for some reason, VI had :set ff=3Ddos !!!
many thanks
Thomas B=E4tzler wrote:
> =
> On Mon, 15 Oct 2001, Jean-Luc Lachance <jllachan@interlink.net> wrote:
> >I did all that without success.
> >I am begining to think that bash is at fault here.
> =
> Try uploading the following code. It'll tell you what line terminators
> you're using.
> =
> #!/usr/bin/perl -w
> =
> use strict;
> =
> print"Content-type: text/plain\n\n";
> =
> open( SELF, $0 ) or die "Can't open self: $!\n";
> =
> binmode( SELF );
> =
> if( defined( my $line =3D <SELF> ) ){
> print "Bang line as hex: ", join( ", ",
> map { $_ =3D sprintf "%02x", ord }
> split //, $line ), "\n";
> =
> if( $line =3D~ m/\015\012$/ ){
> print "Lines terminated with CRLF!\n";
> } elsif( $line =3D~ m/\012$/ ){
> print "Lines terminated with LF!\n";
> } else {
> print "Line terminated with something else!\n";
> }
> =
> }
> =
> close( SELF );
> =
> __END__
> =
> HTH,
> --
> use strict;my($i,$t,@r)=3D(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{or=
d}
> split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.=
> '"`P<!`````0$`'));$t=3D~s/(\d)(.)/$2x$1/eg;map{$t.=3Dsubstr$t,$i,1,''wh=
ile
> $_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl=
------------------------------
Date: Mon, 15 Oct 2001 18:20:16 -0700
From: Amer Neely <aneely@softouch.on.ca>
Subject: Re: $x ||= $y;
Message-Id: <3BCB8B50.79B53201@softouch.on.ca>
Bernard El-Hagin wrote:
>
> On Mon, 15 Oct 2001 16:18:10 +0200, Wolfgang Zilgens <wzilgens@consem.de>
> wrote:
> > can anybody tell me what this statement does?
>
> It sets $x to $y unless $x has a true values.
>
> It's equivalent to:
>
> $x = $x || $y;
>
> To learn more read:
>
> perldoc perlop
>
> Cheers,
> Bernard
It's used when you want a scalar variable to have a default value, but
only if it doesn't already have one.
See "Perl Cookbook" recipe 1.2 and "Effective Perl Programming" Item 14
for examples of usage.
--
Amer Neely aneely@softouch.on.ca
Softouch Information Services: www.softouch.on.ca/
Perl / CGI programming for shopping carts, data entry forms.
"We make web sites work!"
------------------------------
Date: Tue, 16 Oct 2001 01:53:35 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: about special chars when split()
Message-Id: <zqMy7.177896$K6.84077452@news2>
[Posted and mailed]
In article <MPG.163115f7a7240a3989683@news.cuhk.edu.hk>,
Cliver Yang <divetolife@yahoo.com> writes:
> I am doing a log analyzer on Winroute log. But I donot know how to
> process special characters when split().Such as the following line:
> "192.168.1.25 - muwei [03/Sep/2001:14:23:45 +0800] "GET
> http://www.microsoft.com/isapi/redir.dll?Prd=ie&Pver=5.0&Ar=ie5update&O1
> =b1 HTTP/1.0" 302 296"
>
> @test=split(/\s+/,$_);
This takes a line and splits it into fields, if they're separated
by whitespace. Looks good to me.
> Many chars need to be escaped. Is there any method to substitute?
"escaped"? What do you mean? Splitting the line and "escaping"
characters are two different operations. What kind of "escaping" are
you talking about? For the shell? For the web? HTML? URL?
I think you're mixing up to completely different operations.
--
Clinton A. Pierce Teach Yourself Perl in 24 Hours *and*
clintp@geeksalad.org Perl Developer's Dictionary
"If you rush a Miracle Man, for details, see http://geeksalad.org
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: Tue, 16 Oct 2001 00:06:26 GMT
From: "chris" <cherbst@hotpop.com>
Subject: Re: backgrounding a system call
Message-Id: <pan.2001.10.15.20.03.33.963.4695@hotpop.com>
This worked great, thanks.
------------------------------
Date: 15 Oct 2001 18:04:13 -0700
From: trewth_seeker@yahoo.com (Trewth Seeker)
Subject: Re: Difference between .pl, .cgi, and .pm File Extensions.
Message-Id: <d690a633.0110151704.396db3dc@posting.google.com>
damian@qimr.edu.au (Damian James) wrote in message news:<slrn9sjslm.cm5.damian@puma.qimr.edu.au>...
> On 13 Oct 2001 06:25:24 -0700, Trewth Seeker said:
> >damian@qimr.edu.au (Damian James) wrote in message news:<slrn9qabkt.i3r.damian@puma.qimr.edu.au>...
> >> Trewth Seeker chose 14 Sep 2001 17:29:47 -0700 to say this:
>
> >> >I'd point you to the
> >> >philosophical literature of ontology to help clarify your thinking
> >> >about what "is", if I thought it would do any good -- "dude".
> >>
> >> BTDTGTTS. Ontology is seldom any good at making things clearer.
> >
> >As I suggested, it won't do *you* any good.
>
> Are you still here?
>
> *plonk*
>
> HAND, etc
As if anyone cares.
------------------------------
Date: 15 Oct 2001 21:46:13 GMT
From: fxn@retemail.es (F. Xavier Noria)
Subject: Re: filehandle : localized typeglob - local $_
Message-Id: <9qflf5$5q563@news1s.iddeo2.es>
On Mon, 15 Oct 2001 11:34:00 +0200, peter pilsl <pilsl_@goldfisch.at> wrote:
:>>
:>>Do I need the line and if - why ?
:>
:> It has nothing to do with localized filehandles.
:
: This was exactely my problem. I was not sure if this line is needed for the
: localized typeglob *FH.
: In my script I dont need the line then cause $_ is processed before and the
: result stored in different local variables then.
I don't fully understand that last paragraph... it looks from your
words as if the script was doing something like this:
sub foo {
#...
while (<FH>) {
my $line = $_;
#...
}
}
If $_ is not localised and its value is modified in any way (as is
being modified in the code above), the caller will see the (probably
unexpected) modification in his own $_.
I surely misunderstood the phrase, just wanted to make sure there was
no confusion.
-- fxn
------------------------------
Date: Mon, 15 Oct 2001 21:56:18 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: How do you get paid for Perl work over the Internet??
Message-Id: <YoMy7.6834$7Y4.1143713@news20.bellglobal.com>
"Carlos C. Gonzalez" <aperlprogrammer@yahoo.com> wrote in message
news:MPG.1634ce581cf1b02b9897b5@news.edmonton.telusplanet.net...
>
> This time difference was between experienced programmers and not between
> experienced ones and beginners Joe. As an example of what I was talking
> about, it seems to me that the difference between an experienced
> programmer using the CGI module to write a CGI script to process form
> input would not even be double that of a beginning programmer who had
> learned to do the same thing. And to do it well.
>
The point that people keep trying to hammer home to you is that you are
*not* providing people with a service by providing them with inexperienced
programmers. You quote the CGI module as though it were some great equalizer
in the world of Perl. I'm sorry to have to break the news to you, but this
module only speeds up some processes; it does not a good programmer make.
You perhaps need to learn more about Perl yourself in order to see all the
pitfalls that can befall amateur programmers.
And, as I mentioned in a previous message, what offends people on this list
is that you come here, to a newsgroup of professionals, touting your service
to provide amateur-level scripting to clients. Did you not think that this
would upset people? Whether you think beginners can script is not important;
the knowledge of the people here that they are error-prone is. Think of the
blackeye you will give to professional programmers and the language itself
by your intended actions. The last thing Perl needs is to gain a reputation
as a hack language practised by web amateurs because of the misguided
intentions of people like yourself.
Matt
------------------------------
Date: Tue, 16 Oct 2001 03:15:31 GMT
From: Carlos C. Gonzalez <aperlprogrammer@yahoo.com>
Subject: Re: How do you get paid for Perl work over the Internet??
Message-Id: <MPG.163554c82c5f86449897b6@news.edmonton.telusplanet.net>
Matt Garrish at matthew.garrish@sympatico.ca said...
Hi Matt,
Thanks for your input. However what you say is so full of
misrepresentations, insults, and attacks on me I won't even bother to
respond. I give up. It seems no matter what I say you are set on
misrepresenting what I say anyway. Oh well.
May I at least encourage you to take this to email if you have any
further comments to add to what you have said? Not for my sake mind you.
But rather for the sake of this newsgroup. In some respects I would love
to blast away with both barrels but I restrain myself lest I fall into
the same insulting tone you are using on me.
I would encourage you to reconsider the tone you are using in your posts
to me Matt. It doesn't accomplish anything but rile people up. And for
what?
Thanks.
---
Carlos
www.internetsuccess.ca (not operational yet)
------------------------------
Date: Mon, 15 Oct 2001 23:41:49 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: How do you get paid for Perl work over the Internet??
Message-Id: <SXNy7.7641$7Y4.1220512@news20.bellglobal.com>
Come out with guns blazing. Defend yourself! So far you've written nothing
to persuade anyone, or have you not noticed that all the post have had the
same tone toward your proposed project? If I've insulted you personally I
apologize, but professionally I abhor what you claim to stand for. And with
that said, I bid you farewell.
Matt
------------------------------
Date: 15 Oct 2001 15:36:26 -0700
From: herbertmark@home.com (jimmyJIMMYyaya)
Subject: how to retreive milliseconds
Message-Id: <d76973eb.0110151436.4d70c88b@posting.google.com>
hi
im trying to get milliseconds with perl
i have a search script and i want to inform how long the search took
and its always less than a second.
this is the script subs:
1) initialize
2) process
3) terminate
in initialize and terminate i call this
system( "cmd.exe /c time < bl.txt > time.txt" );
it works fine in initialize but in terminate i get this error:
[Sun Oct 14 19:19:06 2001] [error] [client 24.42.128.214] The system
cannot find the file specified.
the /c closes the cmd.exe
can anyone shed some light on this for me
Thanks in advance
------------------------------
Date: Mon, 15 Oct 2001 23:55:33 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: how to retreive milliseconds
Message-Id: <ertmstonfpf0d0e2clb7p2h8lcqg7b5a6j@4ax.com>
jimmyJIMMYyaya wrote:
>im trying to get milliseconds with perl
use Time::HiRes;
--
Bart.
------------------------------
Date: Tue, 16 Oct 2001 00:18:22 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: how to retreive milliseconds
Message-Id: <slrn9smv6e.l88.mgjv@verbruggen.comdyn.com.au>
On 15 Oct 2001 15:36:26 -0700,
jimmyJIMMYyaya <herbertmark@home.com> wrote:
> hi
>
> im trying to get milliseconds with perl
This is a frequently asked question:
Perl FAQ, section 8
How can I measure time under a second?
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | "Mr Kaplan. Paging Mr Kaplan..."
NSW, Australia |
------------------------------
Date: 15 Oct 2001 15:25:42 -0700
From: iNeverReadAnythingSentToMe@hotmail.com (David Filmer)
Subject: I didn't do a very good job asking this...
Message-Id: <9a223a9d.0110151425.715d9b82@posting.google.com>
I oversimplified my original question because I listed only scalars.
I want a method to undefine multiple variables at once yet be
independent of the variable type (scalar, list, hash, etc) or order.
So what I really want to do is:
undef $a @B %C;
If I do something like
$a = @B = undef;
then @B becomes undefined, but $a is always set to "1" (??? -
regardless of the scalar value of @B, btw) whereas if I reverse it and
do
@B = $a = undef;
it (apparently) works.
Is there a syntax to undef a list of variables that doesn't care what
type they are or what order they are presented in?
------------------------------
Date: Tue, 16 Oct 2001 00:43:39 +0200
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: I didn't do a very good job asking this...
Message-Id: <9qfood$ntu$00$1@news.t-online.com>
"David Filmer" <iNeverReadAnythingSentToMe@hotmail.com> schrieb im
Newsbeitrag news:9a223a9d.0110151425.715d9b82@posting.google.com...
| I oversimplified my original question because I listed only scalars.
| I want a method to undefine multiple variables at once yet be
| independent of the variable type (scalar, list, hash, etc) or order.
| So what I really want to do is:
|
| undef $a @B %C;
|
| If I do something like
|
| $a = @B = undef;
|
| then @B becomes undefined, but $a is always set to "1" (??? -
| regardless of the scalar value of @B, btw) whereas if I reverse it and
| do
|
| @B = $a = undef;
|
| it (apparently) works.
|
| Is there a syntax to undef a list of variables that doesn't care what
| type they are or what order they are presented in?
(@var, $var) = undef;
should work because @var and $var are treated as elements of a list
(right?).
--
$_=q;33352987319029872958319011313364356732192639127636833335345138283712
3712336415083973397340602842912;;s;\n;;;print"\n";$o=$_;push@o,substr($o,
$_*4,4)for(0..24);pop@o;for(@o){$i++;print' 'x(26-$i).(chr$_/29-$i)."\n"}
------------------------------
Date: 15 Oct 2001 16:06:18 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: I didn't do a very good job asking this...
Message-Id: <3bcb6bea@news.victoria.tc.ca>
David Filmer (iNeverReadAnythingSentToMe@hotmail.com) wrote:
: I oversimplified my original question because I listed only scalars.
: I want a method to undefine multiple variables at once yet be
: independent of the variable type (scalar, list, hash, etc) or order.
: So what I really want to do is:
: undef $a @B %C;
eval "undef $_" foreach ( qw( $a @B %C ) ) ;
------------------------------
Date: Tue, 16 Oct 2001 00:37:05 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: I didn't do a very good job asking this...
Message-Id: <slrn9sn09g.l88.mgjv@verbruggen.comdyn.com.au>
On 15 Oct 2001 15:25:42 -0700,
David Filmer <iNeverReadAnythingSentToMe@hotmail.com> wrote:
> I oversimplified my original question because I listed only scalars.
> I want a method to undefine multiple variables at once yet be
> independent of the variable type (scalar, list, hash, etc) or order.
> So what I really want to do is:
>
> undef $a @B %C;
Are you really sure you want to undefine the aggregates @B and %C? Or
do you just want to empty them? There is a difference, but it hardly
ever matters.
Have you tried:
($a, @B, %C) = ();
> If I do something like
>
> $a = @B = undef;
This makes @B a one-element array, with the single element havign the
value undef, and it makes $a equal to 1, which is the number of
elements in @B (arrays in scalar context return the number of elements
they contain).
Not what you want, at all.
> then @B becomes undefined, but $a is always set to "1" (??? -
> regardless of the scalar value of @B, btw) whereas if I reverse it and
> do
What do you mean by 'the scalar value of @B'? The scalar value of an
array is the number of elements it contains.
> @B = $a = undef;
$a is now undef, and @B a one-element array with a single undef value.
> it (apparently) works.
No, it doesn't.
An 'e\undefined' array is something totally different from an array
with a single undefined element.
> Is there a syntax to undef a list of variables that doesn't care what
> type they are or what order they are presented in?
First of all, you need to work out whether you really need to undefine
aggregates, or whether you just want to empty them. undefining
aggregates is hardly ever needed, and somewhat meaningless (IMO).
Unless you know _why_ you want to undefine arrays and hashes, I
suspect that all you really need to do is empty them, and in that
case, the method above should work fine.
Martien
--
Martien Verbruggen |
Interactive Media Division | 42.6% of statistics is made up on the
Commercial Dynamics Pty. Ltd. | spot.
NSW, Australia |
------------------------------
Date: 15 Oct 2001 18:27:16 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: I didn't do a very good job asking this...
Message-Id: <m1g08kfk7f.fsf@halfdome.holdit.com>
>>>>> "Steffen" == Steffen Müller <tsee@gmx.net> writes:
Steffen> (@var, $var) = undef;
Steffen> should work because @var and $var are treated as elements of a list
Steffen> (right?).
No. That sets $var to undef, but @var to (undef), not an empty list.
Common beginner mistake. I hope the beginners reading your post
also read mine. :(
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Tue, 16 Oct 2001 01:14:40 GMT
From: "Michael" <min_c_lee@yahoo.com>
Subject: loading up modules
Message-Id: <4SLy7.1849$Le.49132@sea-read.news.verio.net>
I do not have my own server, I'm currently
using an ISP (Unix/Apache).
Are there any references where can I see examples of
applying modules (from http://search.cpan.org) onto the server?
Many of the modules there are not loaded in the ISP server
as standard ones, I think I will need to place them under my
account; so I unzipped the .gz file, I uploaded files into my
account space while keeping the original directory structure.
I grabbed specific modules into the directory I'm woring on,
and made sure "use" or "require" references the right path,
I believe there are still something missing in that evnironment
- I'm not able to get those modules functional.
It will be great if I can get to see some typical examples how to
make modules functional in an ISP environment.
BTW, I'm able to create custom modules working just fine in my account.
Michael
------------------------------
Date: Tue, 16 Oct 2001 01:44:53 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: loading up modules
Message-Id: <piMy7.177894$K6.84064945@news2>
[Posted and mailed]
In article <4SLy7.1849$Le.49132@sea-read.news.verio.net>,
"Michael" <min_c_lee@yahoo.com> writes:
> I do not have my own server, I'm currently
> using an ISP (Unix/Apache).
> Are there any references where can I see examples of
> applying modules (from http://search.cpan.org) onto the server?
If you don't have compile (shell) access to the web server then the
easiest way to do this is to get a machine of the same architecture
as the web server and install the modules there. Make sure you've got
the same versions of Perl in both places.
Then, transpant the site_perl/5.x.x directory structure onto the web server
using FTP (or whatever) into your private area as "lib". Use the "use lib"
pragma to point to that directory tree like this:
use lib '/home/webuser/lib';
Before you try to "use" any of those modules. This should work.
If the modules don't have any C components (XS) then you should be able to
do this trick even with mildly dissimilar versions of Perl or different
machine architectures.
--
Clinton A. Pierce Teach Yourself Perl in 24 Hours *and*
clintp@geeksalad.org Perl Developer's Dictionary
"If you rush a Miracle Man, for details, see http://geeksalad.org
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: Tue, 16 Oct 2001 01:53:42 GMT
From: jh123@nc.rr.com
Subject: Need cgi script
Message-Id: <3bcb92a5.15246056@news-server>
I need a cgi script to do the following:
The visitor to a web page ("firstpage.html") clicks on a link to a
text or html file (from a list of such links). The contents of that
text or html file is then displayed within a template web page
("secondpage.shtml").
Could anyone refer me to such a script (or, very kindly, to write such
a script for me)?
Thanks,
Jay
------------------------------
Date: 15 Oct 2001 23:20:58 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Need cgi script
Message-Id: <m3u1x0clt1.fsf@mumonkan.sunstarsys.com>
jh123@nc.rr.com writes:
> I need a cgi script to do the following:
Your post is off-topic for this newsgroup.
--
Joe Schaefer "When the gods choose to punish us, they merely answer our
prayers."
-- Oscar Wilde
------------------------------
Date: 15 Oct 2001 17:12:00 -0700
From: tokuyasu@cc.ucsf.edu (Taku Tokuyasu)
Subject: newbie - initializing hash from a file doesn't work
Message-Id: <a1dadec6.0110151612.6bb19732@posting.google.com>
I'm trying to reproduce the example in Chapter 1 of Randal Schwartz's
book,
http://www.oreilly.com/catalog/lperl2/chapter/ch01.html,
but the version that initializes the 'secret word list' from a file
doesn't work for me. The basic issue seems to be that keys coming
from a file are not equivalent to keys initialized within the code or
coming from <STDIN>. By the way, I'm using Win2k and cygwin
(libperl5_6_1.dll). Here is the code I'm using (copied straight from
the above website):
#!/usr/bin/perl
init_words();
print "What is your name? ";
$name = <STDIN>;
chomp $name;
if ($name =~ /^randal\b/i) { # back to the other way :-)
print "Hello, Randal! How good of you to be here!\n";
} else {
print "Hello, $name!\n"; # ordinary greeting
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);
}
}
## subroutines from here down
sub init_words {
open (WORDSLIST, "wordslist") ||
die "can't open wordlist: $!";
while ( defined ($name = <WORDSLIST>)) {
chomp ($name);
$word = <WORDSLIST>;
chomp $word;
$words{$name} = $word;
}
close (WORDSLIST) || die "couldn't close wordlist: $!";
}
sub good_word {
my($somename,$someguess) = @_; # name the parameters
$somename =~ s/\W.*//; # delete everything after
# first word
$somename =~ tr/A-Z/a-z/; # lowercase everything
if ($somename eq "randal") { # should not need to guess
return 1; # return value is true
} elsif (($words{$somename} || "groucho") eq $someguess) {
return 1; # return value is true
} else {
return 0; # return value is false
}
}
####################
The 'wordslist' file is:
fred
camel
barney
llama
betty
alpaca
wilma
alpaca
Here is a run in cygwin:
$ randals.pl
What is your name? barney
Hello, barney!
What is the secret word? llama
Wrong, try again. What is the secret word? camel
Wrong, try again. What is the secret word? alpaca
Wrong, try again. What is the secret word? fred
Wrong, try again. What is the secret word? barney
Wrong, try again. What is the secret word? betty
Wrong, try again. What is the secret word? wilma
Wrong, try again. What is the secret word?
Wrong, try again. What is the secret word?
The first answer should have been correct. I got a little desperate
and tried everything in sight, as you can see. To try to isolate the
problem, I used the following smaller script:
#!/usr/bin/perl
## Three different ways to initialize %words:
init_words();
# %words = ("fred", "camel", "barney", "llama", "betty", "oyster");
# %words = qw(
# fred camel
# barney llama
# betty oyster);
foreach $key (keys %words) {
print "$key\n";
print "$words{$key}\n";
}
$key1 = "fred";
print "The key fred is associated with value \n";
print "$words{$key1}\n";
sub init_words {
open (WORDSLIST, "wordslist") ||
die "can't open wordlist: $!";
while ( defined ($name = <WORDSLIST>)) {
chomp ($name);
$word = <WORDSLIST>;
chomp $word;
$words{$name} = $word;
}
close (WORDSLIST) || die "couldn't close wordlist: $!";
}
#############
This version shows that "fred" does NOT exist as a key when I use
init_words to initialize the words hash, but it DOES exist using
either of the other two methods.
So, what is the difference between a "fred" input from a file, and a
"fred" within the code (or from <STDIN> for that matter)? Is chomp
doing something unexpected? Is this a DOS file type problem (I
installed cygwin using DOS file types as a default)? Has anyone seen
behavior like this before?
Thanks alot,
_Taku
------------------------------
Date: Mon, 15 Oct 2001 22:19:13 -0400
From: Mike Ragsdale <mragsdal@utk.edu>
To: Alexander Bjelke <bjelkea@online.no>
Subject: Re: newbie question
Message-Id: <3BCB9921.4D155023@utk.edu>
Alexander Bjelke wrote:
>
> Hi, take a look at his:
>
> $d1 = "somewhere"
> $d2 = "somewhereelse"
>
> my @dir_array = qw($d1 $d2);
>
> when I print out the contest of @dir_array I get $d1 and $d2 instead of the
> filepath. Why? (and how can I fix it)
>
> Thanks alot! :-)
> Alexander
qw() does not interpolate. See "perldoc -f push" and try this:
push(@dir_array, $da, $d2);
-Mike
------------------------------
Date: Tue, 16 Oct 2001 02:37:05 GMT
From: "Peter G. Martin" <peterm@zeta.org.au>
Subject: Re: Problems with ActiveState and MCPAN
Message-Id: <3BCB9D50.3060302@zeta.org.au>
The problem is common enough. Many of us would like some of those
modules not in AS.
In your case, a quick suggestion is that you don't appear to
have a needed executable file available on your PATH.
Looks like you need gunzip . Check out www.cygwin.com for
this and a few others you'll need -- including tar, which
is the next command usually needed after gunzip. These are
standard (UNIX-like) commands needed for unpacking the archive
you download using the CPAN module.
You'll need these even to do it by hand.
Usyk, Walter [SKY:1P67:EXCH] wrote:
> The problem is that the modules that I need are not in the ActiveState archive. That is why
> I attempted to use CPAN
>
> Any ideas???
>
> Walter
>
> Dan Sugalski wrote:
>
>
>>In comp.lang.perl.modules Usyk, Walter [SKY:1P67:EXCH] <wusyk@americasm01.nt.com> wrote:
>>
>>>I compiled and installed the ActiveState perl 5.6.1. I'm trying to
>>>install packages using MCPAN but I get the error below. Does anyone have
>>>an idea why this is happening. I'm running Windows NT and compiled using
>>>VC++ 6.
>>>
>>Try using PPM instead, if the module you want is in ActiveState's archive.
>>
>> Dan
>>
>
> --
> Walter Usyk - Tools Developer
> Software Development Environment Tools (1P67)
> email: wusyk@nortelnetworks.com
> ESN: 398-4603
> Tel: (613) 768-4603
>
>
>
------------------------------
Date: Tue, 16 Oct 2001 01:42:04 GMT
From: "The Waltons" <silverrouge@hotmail.com>
Subject: REDHATE 7
Message-Id: <MfMy7.5197$bE1.23936@news1.rdc1.nsw.optushome.com.au>
Hello all,
I have spent DAYS attempting to get perl 5.6.1 installed on a redhate 7.1
system.
It would appear that redhat Berkley DB rpm setup is badly broken, and I have
erased all
I can, and installed manually (3.3.11). However, I cannot for the life of me
get LWP to build properly - failing on NDBM or elsewhere (depnding on what I
get up to)
-3 friggin versions.... on the machine for no good reason.
Can anyone recommend a failsafe method to get perl 5.6.1 to install
correctly on rehat 7.1
including the LWP (and all the other standard modules). Of course its no
trouble to get
a half arsed installed. I want one that is 'without' errors.
I am surprised that redhat hasnt upgraded to 5.6.1 , its not like its new.
Jed
------------------------------
Date: Mon, 15 Oct 2001 16:17:39 -0700
From: Jay <jay@utils.net.nospam>
Subject: Re: String To List
Message-Id: <3BCB6E92.DCF3C5F9@utils.net.nospam>
Thanks Jeff.
Unfortunately, I spent almost an hour to figure out the proper queries
for SQL and develop code for that. You explained the same in few
lines :-)
The need in my case is to get multiple inputs from user, including patterns.
Eg. (field1 dr* p*) ( field2 a*n ^pu )
and optionally from field 3 and field 4 .
So far, I am not able to get these multiple queries in one single string. I
was
hoping something like CGI scripts, where the contents sent by the browser
are escaped to properly pass, even the special characters.
Worst case scenario is to limit the queries to fixed values:
"-f1 alpha beta charlie, -f2 orange mango ...., -f3 ...."
I would like to split this string on the 'comma' and then call SQL query.
Regards.
-jay
Jeff Zucker wrote:
> Jay wrote:
> >
> > Any suggestions on what will be the simplest form of getting in query
> > data from user. So that I can construct SQL query in my code. It's a
> > pre-built interface and all the space I could get on the front-end is a
> > string field.
>
> # assuming $user_input is a string something like
> # "field2=drawing"
> #
> my($fieldname,$fieldvalue) = split /=/, $user_input;
> my $sql = "SELECT * FROM $table";
> if( defined $fieldname and defined $fieldvalue ) {
> $sql .= " WHERE $fieldname = " . $dbh->quote($fieldvalue);
> }
> my $sth=$dbh->prepare($sql);
> ...
>
> --
> Jeff
------------------------------
Date: Tue, 16 Oct 2001 00:43:41 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Undefined variable in concatenation inconsistent
Message-Id: <slrn9sn0lt.l88.mgjv@verbruggen.comdyn.com.au>
I was answering some other question here, when I saw something
odd-ish:
$ perl -w -Mstrict
my $foo;
print "\$foo = $foo\n";
print "$foo\n";
print $foo, "\n";
__END__
Use of uninitialized value in concatenation (.) or string at - line 2.
$foo =
Use of uninitialized value in print at - line 4.
Note that there is no warning for the second print statement.
This happens only in perl 5.6.1, not in 5.6.0, or in 5.5.3. The same
happens when concatenating in an assignment.
$ perl -w -Mstrict
my $foo;
$_ = $foo . "\n";
$_ = "$foo\n";
__END__
$ perl -v
This is perl, v5.6.1 built for i586-linux
Is this intended? I can't easily find anything in the change
documentation..
Was this unintended, and has it been fixed? I don't have easy access
to a development version of Perl.
Martien
--
Martien Verbruggen |
Interactive Media Division | 42.6% of statistics is made up on the
Commercial Dynamics Pty. Ltd. | spot.
NSW, Australia |
------------------------------
Date: Tue, 16 Oct 2001 03:37:33 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Undefined variable in concatenation inconsistent
Message-Id: <slrn9snart.l88.mgjv@verbruggen.comdyn.com.au>
On Tue, 16 Oct 2001 00:43:41 GMT,
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
> I was answering some other question here, when I saw something
> odd-ish:
>
> $ perl -w -Mstrict
> my $foo;
> print "\$foo = $foo\n";
> print "$foo\n";
> print $foo, "\n";
> __END__
> Use of uninitialized value in concatenation (.) or string at - line 2.
> $foo =
>
> Use of uninitialized value in print at - line 4.
>
> Note that there is no warning for the second print statement.
>
> This happens only in perl 5.6.1, not in 5.6.0, or in 5.5.3.
Just had a chance to check 5.7.1 and perl@12443. The same behaviour
still exists in 5.7.1, but it seems to have been fixed in the latest
development tree.
Must have been a bug :)
Martien
--
Martien Verbruggen |
Interactive Media Division | Unix is user friendly. It's just
Commercial Dynamics Pty. Ltd. | selective about its friends.
NSW, Australia |
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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 V10 Issue 1936
***************************************