[7804] in Perl-Users-Digest
Perl-Users Digest, Issue: 1429 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 6 14:17:13 1997
Date: Sat, 6 Dec 97 11:00:43 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 6 Dec 1997 Volume: 8 Number: 1429
Today's topics:
Re: Embarrassing Perl Code (was PERL Hourly Rates) <nospam@domain.com>
Re: formmail - IE works, netscape doesn't (Tushar Samant)
Re: formmail - IE works, netscape doesn't <schramm@one.net>
Re: How do I print all but the first variable in an arr (Bart Lateur)
Re: How to create reference to anonymous scalar variabl <tchrist@mox.perl.com>
Re: I need help with perl-cgi script <rootbeer@teleport.com>
Re: Inserting only the unique elements into an array .. <schramm@one.net>
installing win32 <jones-joe@usa.net>
Re: negative lookahead help in HTML entity substitution (Tad McClellan)
Re: newbie: installing cgi.pm <nospam@domain.com>
Re: PERL Backticks and Non-parsed Headers (NPH) <rootbeer@teleport.com>
Perl for Win32 and COM Ports (Colin Foster)
Re: PERL Frusterations (semi-newbie) <$_=qq!fearless\@NOSPAMio.com!;y/A-Z//d;print>
Re: perl packages question <rootbeer@teleport.com>
Perl script! <webmaster@nander.widexs.net>
Re: Perl4 is not Y2K (was Re: Forced to use brain-dead (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
Re: Problem with function call to ps() <rootbeer@teleport.com>
Re: Question about the =~ operator <nospam@domain.com>
random seeding (George Lewis)
Re: random seeding (Mike Stok)
Re: Recommended PERL-book? (Jonathan C. Willeke)
Thanks <christian.bjelle@sesig.mail.abb.com>
Re: trying to understand arrays of hashes <nospam@domain.com>
Re: variable <rootbeer@teleport.com>
Re: what's wrong with this? <nospam@domain.com>
Re: what's wrong with this? (Tad McClellan)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 06 Dec 1997 15:26:27 GMT
From: John Nolan <nospam@domain.com>
Subject: Re: Embarrassing Perl Code (was PERL Hourly Rates)
Message-Id: <34896F18.6598@domain.com>
Roy Brander wrote:
>
> : : /[Tt][Ee][Rr][Rr][Yy]/
> : : i ROTFL when i saw that i did that.... :-0
>
> Hey, a half-dozen threads up from here, they're having an argument that
> would appear to be "what's the most insanely inefficient way of finding
> if a number is odd or even?". Or they were before they started a flame
...How about a lookup table? :)
--John Nolan
------------------------------
Date: 6 Dec 1997 09:38:01 -0600
From: scribble@tekka.wwa.com (Tushar Samant)
Subject: Re: formmail - IE works, netscape doesn't
Message-Id: <66brgp$dot@tekka.wwa.com>
vinsong@olympus.not.spam writes:
>I am a newbie to CGI's. I wrote a page following my ISP's instructions to
>utilize their FormMail script.
>
>It works in Internet Explorer but not Netscape. Am I doing something
>really dumb or what? Any ideas will be appreciated. My ISP charges $90 an
>hour for support. Big mistake signing up with them but I am stuck for the
>time-being.
Can you even see their script? If you can't -- I think your ISP
is a loyal minion who detects the browser and crushes it if it's
the enemy's. You will soon be ordering people not to use Netscape
on your pages. This is one way in which evil propaGates itself.
If you can see the script -- make sure it's perl and post it here.
>Please reply via e-mail (fixing typos). Thanks in advance.
I can't figure out what's typo and what's not. Your obfuscation is
too clever.
------------------------------
Date: Sat, 6 Dec 1997 11:57:20 -0500
From: "R. Schramm" <schramm@one.net>
Subject: Re: formmail - IE works, netscape doesn't
Message-Id: <66bvul$al2$1@news.one.net>
I have seen something like this before. Netscape's HTML parser is much
stricter than IE's. More than likely, you don't have a </form> tag in your
page, it is in the wrong place, or there is some other problem with your
form HTML tags. I would look over your form and make sure the HTML is
correct. If you view source in a later edition of Netscape, it may show you
where it is wrong.
BTW, FormMail comes from Matt's Script Archives and you may get some info
from there if the above still doesn't help.
Greg Vinson wrote in message ...
>I wrote a page following my ISP's instructions to
>utilize their FormMail script.
>It works in Internet Explorer but not Netscape.
------------------------------
Date: Sat, 06 Dec 1997 17:00:33 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: How do I print all but the first variable in an array?
Message-Id: <348a8435.14819094@news.tornado.be>
"William B. Tansill, III" <wtansill@erols.com> wrote:
>Tom Christiansen wrote:
>> Simply use:
>>
>> print "@stuff[ 1 .. $#stuff ]\n";
>>
>> or some less-quoted variation thereon.
>But this does not print a newline after each element in the version of
>PERL (on a DOS/Win '95 system) that I use. Rather, it prints each
>element on a single line separated by one space. The newline prints
>after all of the elements. I'm using version 5.004_02.
Take a look at PERLVAR.POD: special variables. Especially $" should draw
your attention.
Alternative:
($\,$,)=("\n","\n");
print @stuff[ 1 .. $#stuff ];
HTH,
Bart.
------------------------------
Date: 6 Dec 1997 15:24:04 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: How to create reference to anonymous scalar variable ?
Message-Id: <66bqmk$82e$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, Margarit Nickolov <man@digsys.bg> writes:
:For example some elements of hash reference to one value of scalar
:variable, then value of scalar variable changes, and I want another
:elements of hash reference to 'new value' of the same scalar variable.
[Excerpt from the rough draft of the still-unpublished ``Perl Cookbook'',
by Tom Christiansen and Nate Torkington. All rights reserved.]
+-------------------+
| Anonymous Scalars |
+-------------------+
Problem: You want a reference to an unnamed scalar.
Solution: Dereference an undefined value in an assignment, or return
a reference to lexically scoped scalar.
Discussion
When you make an assignment in Perl, any previous values are freed
up and enough space is allocated to hold whatever you choose to
place there. No predeclaration is needed.
my $scalar; # currently undefined
$scalar = "some string"; # allocate and store
It turns out that references behave the same way. Much to the surprise
of C programmers everywhere, you don't have to preallocate space for
what a reference is going to hold, even when you're about to assign
through it.
my $sref; # currently undefined
$$sref = "some string"; # allocate and store
When Perl sees that you're trying to assign through a reference
that's undefined, rather than producing a core dump, it quickly
allocates an anonymous scalar and points $sref at that. This works
even when dereferencing through an array or hash element, as in:
my @array;
${ $array[5] } = 20;
print 7 + ${ $array[5] }; # says 27
The array variable @array is grown as needed; its fifth element is
created on the fly just by assigning to it. Furthermore, when that
element is used to dereference through, a new scalar is allocated and
a reference to that scalar stored in `$array[5]'. This is effectively
an anonymous scalar, because it has no name.
You are allowed to dereference an undefined value as an lvalue
(to make an assignment, for example); Perl allocates memory for
its referent automatically. But what about using `undef' as an
rvalue? Dereferencing the undefined value as an rvalue just produces
another undefined value--unless you're running under the `use strict'
directive. In that case, it instead raises an exception! This is one
reason why you may sometimes want to pre-allocate an anonymous data
type by reference.
Have you ever wanted to explicitly allocate an anonymous scalar,
or a whole bunch of them? You actually can do this, but it's not
entirely obvious to most beginners how to do so. The mechanism
relies upon Perl's garbage collection system: space is allocated as
needed, but not deallocated until it's no longer used. So you just
need to create a new lexically scoped scalar variable using my(),
then return a reference out of that scope. Here's code that does that:
sub anon_scalar {
my $scalar;
return \$scalar;
}
$sref = anon_scalar();
This example is short but subtle; once you understand it, you'll know
a good bit about Perl's memory allocation system. Each time you call
anon_scalar(), it produces a new and different scalar reference. It is
not going to be a pointer to the same bit of memory every time. Just
because the scope was exited doesn't mean that $scalar should be
deallocated. In fact, doing so would be totally wrong, because someone
($sref, in particular) still hold a reference to that space. Memory
is not returned to your process's free pool until all references to
it are gone. Isn't automatic memory management a wonderful thing?
You don't actually need a function call just to create a scope. Here's
how do so using a `do{}' block:
$sref = do {
my $scalar;
\$scalar;
};
$sref = \do { my $scalar }; # or on one line;
The single-line version works because the backslash applies to the
`do' block's return value, the private variable $scalar.
To create a list of these anonymous scalar references, make a function
for this purpose:
@scalar_refs = mk_scalar_ref_list(20);
sub mk_scalar_ref_list {
die "expected to be called in list context" unless wantarray();
my $count = shift;
my @reflist = ();
while ($count-- > 0) {
my $scalar;
push @reflist, \$scalar;
}
return @reflist;
}
This function takes an argument of the number of references desired
and returns that many anonymous scalar references. Each time through
the `while' loop, a new scalar is created whose reference is appended
to array to be returned. The function also makes sure it was called
properly: in list context, not scalar or void context.
Finally, let's combine a couple of the techniques shown so far.
@scalar_refs = \mk_list(20);
sub mk_list {
my $count = shift;
my @reflist = ();
$#reflist = $count - 1; # set max index on array
return @reflist;
}
This example is similar, but different in an interesting way. This
time the function creates an array of whatever length was passed
in. This is a simple array of (undefined) scalars; no references
are involved--so far. This array is then returned. To be perfectly
honest, it's not an array that's returned, but rather the list of
scalars comprising that array. The caller then applies the backslash
to the function's return list, which because of its distributive
property, is applied to each scalar in that return list. What you
end up with then is the same thing as in the previous example that
used a mk_scalar_ref_list() function.
--
Tom Christiansen tchrist@jhereg.perl.com
"That's okay. Anyone whose opinion he cares about already knows that
he doesn't care about their opinion."
--Larry Wall
------------------------------
Date: Sat, 6 Dec 1997 10:30:53 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Stephen Foley <foley.steve@ic.gc.ca>
Subject: Re: I need help with perl-cgi script
Message-Id: <Pine.GSO.3.96.971206102907.16254C-100000@usertest.teleport.com>
On Fri, 5 Dec 1997, Stephen Foley wrote:
> Upon submitting the form, I get the error:
>
> HTTP/1.0 501 Not Supported
That's not a Perl error. You should check the docs for the program which
give you that error message to find out why it's doing that. If it's a
server and you can't find the answer in the docs, you should get a server
with better docs, of course. :-) But you might find the answer in a
newsgroup about servers. Good luck!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Sat, 6 Dec 1997 12:16:24 -0500
From: "R. Schramm" <schramm@one.net>
Subject: Re: Inserting only the unique elements into an array ...
Message-Id: <66c128$bb3$1@news.one.net>
Just use an associative array.
foreach $element (@Values) {
$unique{$element}=$element;
}
Then get the keys back back out for your final array
foreach $key (sort keys %unique) {
print "$key \n";
# or push (@array, $key);
# to build an regular array of unique keys.
}
If the unique hash is really big, try this:
while (($key,$value) = each %unique) {
print "$key\n";
}
Anyhow, an associative array is the best bet. Seems alot less convuluted.
Narayan Moni wrote in message <66a5rb$qs7@bgtnsc01.worldnet.att.net>...
>Hi fellow PERLers
>
>Have a question for you. I am trying to insert an element into an array
>I want the element to be inserted ONLY if the element is not already
>in the list. I would prefer if I did not have to search the array
>element by element. The code I have looks somewhat like this ( I
>have deleted a bunch of code so as to focus on the questions I have ).
>
>@Values = ("abc", "def");
>
>&ReadValues (\@Values);
>
>sub ReadValues {
> my ($List) = @_;
> $Element = "abc";
> &InsertIntoList ($List, $Element);
>}
>
>sub InsertIntoList {
> my ($List) = @_;
> if ( grep ($List, $Element) ) {
> $List->[$#List] = $Element;
> }
>}
>
>Now my question to you is
>
>1/ there a better way to go about this? If there is then I would
> really like to know about it
>2/ In the debugger when I check the value of $#List in the function
> InsertIntoList, it is -1. It seems that if I pass an array by
> reference then it looses all these properties of aan array.
> Is that a valid conclusion?
>3/ Can grep be used like above?
>
>Thanks a lot for the info. You could either send me mail at
>anish@worldnet.att.net or post your responses to this newsgroup.
>
>Sincerely,
>Anish.
------------------------------
Date: Sat, 06 Dec 1997 10:04:11 -0700
From: JJ <jones-joe@usa.net>
Subject: installing win32
Message-Id: <3489858B.436B@usa.net>
it says to test the program by running scripts from perl\ntt well it
never made such a directory. did I do something wrong? I read every read
me they have. Please help
------------------------------
Date: Sat, 6 Dec 1997 08:29:09 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: negative lookahead help in HTML entity substitution
Message-Id: <lfnb66.3p.ln@localhost>
Eric Litman (elitman@viaduct.com) wrote:
: I have a document parser which needs to be able to look through a text
: document and find any ampersands which are not part of either an HTML entity
: or a double ampersand (&&).
: It seems to me that this should work:
: $match =~ s/&+?(?![^&][a-zA-Z0-9#]{2,5};)/\&\;/go;
^ ^ ^
^ ^ ^
Those three characters are not needed.
They just obfuscate things.
Ampersand and semicolon are not special in double quoteish strings
(which is what the replacement part of s/// is), so they do not
need to be escaped.
The 'o' modifier cannot have any effect because you do not have
any variable parts in your pattern.
: However, it doesn't. Any thoughts?
Maybe this one will help?
$match =~ s/&(&|[a-zA-Z0-9.-]+;)?/defined($1) ? "&$1" : '&'/ge;
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 06 Dec 1997 15:08:25 GMT
From: John Nolan <nospam@domain.com>
Subject: Re: newbie: installing cgi.pm
Message-Id: <34896ADE.5D8@domain.com>
Liz Castro wrote:
> Oh, yeah, and I read in some newsgroup archive that Randal Schwartz
> thinks that newbies should use CGI.pm and not cgi-bin.pl...any new
> thoughts on that? It sure is harder to install!!
CGI.pm comes with Perl, so you really don't need to install it.
The module CGI.pm does a lot more things than cgi-lib.pl,
including some very nifty error-reporting. It can send some
errors directly to the browser, just the generic Server Error
message.
However, there's nothing wrong with cgi-lib.pl.
If you like that better, you can use that too.
--John Nolan
------------------------------
Date: Sat, 6 Dec 1997 10:24:06 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Scriptman <scriptman@aol.com>
Subject: Re: PERL Backticks and Non-parsed Headers (NPH)
Message-Id: <Pine.GSO.3.96.971206101408.16254A-100000@usertest.teleport.com>
On 5 Dec 1997, Scriptman wrote:
> $|=1;
> print `/home/p_sattle/cgi-bin/nphcall.pl`;
What that does is, first, evaluate the backticks (that is, runs the named
program and collect its output, and second, prints the saved output. If
you want to get the output of the called program in "drips and drops",
you'll need to open it in a different way. For example, you could fork a
child process to exec it, then read a pipe from the child. Of course, you
won't want to use the line input operator ( <PIPE> ) to read, since you
want to get each byte of input as it's available. I'd recommend read()ing
one byte at a time, since I think you won't mind that blocking. Good luck!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Sat, 06 Dec 1997 17:08:11 GMT
From: cfoster@cfoster.demon.co.uk (Colin Foster)
Subject: Perl for Win32 and COM Ports
Message-Id: <34898638.84282@news.demon.co.uk>
I am trying to chat to a device connected to COM2:. I have tried
various scripts, starting with
open MODEM,"+>com2:";
print MODEM "AT\n";
$input = <MODEM>;
print $input;
close MODEM;
then later ..
use IO::Handle;
open MODEM,"+>com2:";
binmode MODEM;
MODEM->autoflush(1);
print MODEM "AT\n";
$input = <MODEM>;
print $input;
close MODEM;
Neither recieve anyting, though flashing lights on the modem would
indicate that the print to MODEM is sending something.
I can talk directly to the modem using Hyperterminal without any
problems, so I must be doing something wrong.
Any help would be appreciated.
Using Perl for Win32 build 313 on Windows 95 OSR2 if that is relevant,
but the scripts run no better on other machines with (subtly)
different versions of Perl and W95.
Colin F
------------------------------
Date: Sat, 6 Dec 1997 08:03:50 -0800
From: "Creede Lambard" <$_=qq!fearless\@NOSPAMio.com!;y/A-Z//d;print>
Subject: Re: PERL Frusterations (semi-newbie)
Message-Id: <66bt03$sl1@bgtnsc01.worldnet.att.net>
Creede Lambard <$_=qq!fearless@NOSPAMio.com!;y/A-Z//d;print> screwed up! The
code should look like this:
#!/usr/bin/perl -w
# print the <HTML> header, etc. up here
open(INFILE,"tab_delimited_file") or die "Can't open input file";
%genre = ();
%url = ();
while (<INFILE>) {
my($myGenre, $group, $myUrl) = split(/\t/);
$genre{$group} = $myGenre;
$url{$group} = $myUrl;
}
close INFILE;
open(OUTFILE,">outfile") or die "Can't write to outfile";
$index = "";
foreach $group (sort(keys(%genre))) { # or %url, they should be the same
$test = substr($group,0,1); # get first letter of group's name
unless ($test =~ /$index/i) {
$index = $test;
print OUTFILE qq!<A NAME="$index">\n!;
}
print OUTFILE qq!<I>$genre{$group}</I><B>$group</B><A
HREF="$url{$group}">$url{$group}</A>\n!;
}
>
>close OUTFILE;
>
If you use the code the way I first posted it you won't get any usable
hyperlinks. Duh.
--- Creede Lambard
Minister of Irregular Expressions
Programming Republic of Perl
------------------------------
Date: Sat, 6 Dec 1997 10:43:40 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Mark Rostron <mwrostron@imation.com>
Subject: Re: perl packages question
Message-Id: <Pine.GSO.3.96.971206104236.16254E-100000@usertest.teleport.com>
On Fri, 5 Dec 1997, Mark Rostron wrote:
> package main;
> print $junk::a,"\n";
> package junk;
> $a = "hello world\n";
>
> will not.
Of course it won't: The value was printed before it was set! :-)
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Sat, 6 Dec 1997 16:57:53 +0100
From: "Nander" <webmaster@nander.widexs.net>
Subject: Perl script!
Message-Id: <66bsdd$6rt$1@news.worldonline.nl>
Have enybody a perl script for my to send a form?
I have my own domain en i am 11 years old but as you have it mail me!
webmaster@nander.widexs.net
http://www.nander.widexs.net
------------------------------
Date: Sat, 06 Dec 97 10:48:48 -0500
From: bsa@void.apk.net (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
Subject: Re: Perl4 is not Y2K (was Re: Forced to use brain-dead perl 4 -- how do I accomplish task that is simple in perl 5 ?)
Message-Id: <34897404$4$ofn$mr2ice@speaker>
In <6686fn$arc$1@mahler.udel.edu>, on 12/05/97 at 01:20 AM,
biell @ udel . edu (Bill Totten) said:
+-----
| >Unfortunately it's the same people at the forefront of development of
| >Perl 5. Unfortunate for THEM, I mean. Can you imagine, having to live
| >with that reputation?
| I disagree completely. Perl4 is not crap; in fact, I would choose
+--->8
"It's a joke, son, it's a joke!" The entire thread is humor, if you haven't
noticed.
--
use 5.004;sub AUTOLOAD{print$_{$_.++$x{$_}}}sub new{my%x;%_=map{++$a%2?$_.++$x{
$_}:$_}split(//,pack('N*',unpack('w*',unpack('u*','M@H*HP\'2"@\C`88+SE/!EA(F!'.
"A'6\$LZV0+(3;C9QRA9NAPG2&D\\G(88:KL=A0\n4AN.5W\"\"&\\[W>;H>3S>0\@A\\N\@PB\$`")
)));bless{}}$b=(new main);map{$b->_}split(//,' Brandon S. Allbery KF8NH') # :-)
------------------------------
Date: Sat, 6 Dec 1997 10:41:37 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: jlee <jlee@mdsi.bc.ca>
Subject: Re: Problem with function call to ps()
Message-Id: <Pine.GSO.3.96.971206103531.16254D-100000@usertest.teleport.com>
On Fri, 5 Dec 1997, jlee wrote:
> I want to a process which keeps checking whether a process is running
> and find out the number of instances of that process.
On my system, the number of instances of any process is usually one,
unless it's zero. :-) But I think I know what you mean: You want to know
how many processes are running program foo.
> Most of the time, ps("x") would work correctly; however, sometimes
> ps("x") would not return anything lines containing qcom and I checked
> that qcom is still running.
What's ps("x")? Are you meaning that you're running your system's ps
command to see what processes are running? If that's not doing what you
want, that's probably because of a problem in your implementation of ps,
rather than in Perl. Have you tried running ps manually to see what it's
really returning?
Good luck!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Sat, 06 Dec 1997 16:05:27 GMT
From: John Nolan <nospam@domain.com>
Subject: Re: Question about the =~ operator
Message-Id: <3489783D.C3C@domain.com>
Richard C. Herselman wrote:
> I was wondering if it's possible to match one string with another
> without using the match operator (=~), because when I use the match
> operator, like this:
>
> if ($somestring =~ /abc/) { # or whatever
> something;
> something;
> something;
> }
>
> ... the value of $something gets changed to whatever was matched, and
> I don't wanna do that, I just wanna evaluate whether /abc/ is in
No, it doesn't. Your code is correct, at least the code that you
posted.
Check your code for syntax errors, or missing "~" characters.
If you had written this:
if ($somestring = /abc/)
...then you would end up munging the variable $something.
Your code above looks fine. You -do- want the =~ operator.
> ....but I was thinking something more in the general direction of:
>
> if ($something == /abc/) { # or eq instead of ==, maybe?
> something;
> something;
> something;
> }
No, this is not right. You need to use "eq", because these are strings,
but even if you use "eq", then you are still evaluating the wrong
thing.
The bare construct /abc/ implicitly means ($_ =~ /abc/), so if you say
if ($something == /abc/)
Then you will mean...
if ($something eq ($_ =~ /abc/))
Which will compare the string $something to the (numeric) return
value of the =~ operation. That's not at all what you wanted.
The operator =~ returns the number of successful matches.
You're original code was correct:
if ($somestring =~ /abc/)
This evaluates to true if the number of successful matches is
greater than 0. That's what you want.
--John Nolan
------------------------------
Date: 6 Dec 97 17:35:43 GMT
From: ragica@no-mail.org (George Lewis)
Subject: random seeding
Message-Id: <34898cef.0@news.cpol.com>
I find that the srand(time) or srand(time ^^ $$) trick really doesn't seed
the random number generator all that well. Can anyone share any other
better random seeding techniques?
------------------------------
Date: 6 Dec 1997 18:35:40 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: random seeding
Message-Id: <66c5ts$s10@news-central.tiac.net>
In article <34898cef.0@news.cpol.com>, George Lewis <xxx@NO-MAIL.com> wrote:
>I find that the srand(time) or srand(time ^^ $$) trick really doesn't seed
>the random number generator all that well. Can anyone share any other
>better random seeding techniques?
time ^ ($$ + ($$ << 15)) is mentioned in the current perlfunc man page,
5.004_04. If you have a random number generating device as part of your
system you might want to read a word from it as your random seed.
Recently perl has been changed so that rand checks to see whether srand
has been called or not. If it hasn't then srand is called using "... uses
a semi-random value based on the current time and process ID, among other
things." If your installation is complete you can check the srand section
of the perlfunc man page.
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@colltech.com | Collective Technologies (work)
------------------------------
Date: Sat, 06 Dec 1997 14:37:46 GMT
From: jwilleke@ix.netcom.com (Jonathan C. Willeke)
Subject: Re: Recommended PERL-book?
Message-Id: <34895cc3.1217516@nntp.ix.netcom.com>
Zenin <zenin@best.com> wrote:
>Christian Bjelle <christian.bjelle@sesig.mail.abb.com> wrote:
>: I suppose there is some book out there that is to PERL what 'The C
>: programming language' by K&R is to C.
>
> "The Blue Camel", or more officially, "Programming Perl".
>
> IMHO, it's not possible to program in Perl without it. :-)
>
_Programming Perl_ is a great book. I passed on _Learning Perl_, but
found I had to read the the Camel book twice before everything really
sunk in.
An alternative strategy would have been to pore over the Llama book
and use the man pages--of which the Camel book is a slightly improved
collection--as my reference. That's not a slight on the Camel book,
but a comment on the quality of the man pages.
You really need to understand a few things about Perl before anything
will make sense to you:
* the fact that variables aren't strongly typed and don't need to be
declared or initialized
* scalar vs. list context, along with variable prefixes: $, @, and %
(as the Camel book says, you'll be miserable until you grasp this)
* the difference between 'single-', "double-", and `back-tick` quotes,
a la Shell
* the seamless integration of regular expressions
* the fact that functions and operators will use a default variable,
$_, if you don't provide one
In this respect, _Learning Perl_ will probably get you there more
quickly (depending on your programming background), but _Programming
Perl_ and/or the man pages will satisfy you when you really get
hungry. I won't comment specifically on the other books on the
market: the ones I have looked at are either too shallow, or pale
beside the man pages as a reference.
Finally, I recommend that you check out
http://language.perl.com/critiques/index.html
if you haven't already. It's dated, but you can get a sense of what
to look for. Tom Christiansen points out, for example, that many
books don't make a good distinction between a single quote, ', and a
back-tick, `. Happy reading!
--Jon
Jon Willeke <jwilleke@ix.netcom.com>
------------------------------
Date: Sat, 06 Dec 1997 16:41:36 +0100
From: Christian Bjelle <christian.bjelle@sesig.mail.abb.com>
Subject: Thanks
Message-Id: <34897230.7D56@sesig.mail.abb.com>
Hi,
I'd like to thank all of you who helped me find a good book about PERL.
(and didn't flame me bc. it's in the FAQ :) I finally chose the Camel.
--
Christian Bjelle - Programmer
Disclaimer:
My views are my own, and usually doesn't coincide with my employer's.
----------------------------------------------------------------------
------------------------------
Date: Sat, 06 Dec 1997 15:31:15 GMT
From: John Nolan <nospam@domain.com>
Subject: Re: trying to understand arrays of hashes
Message-Id: <34897039.6BBF@domain.com>
John Dubchak wrote:
> On my current project I am trying to load a database table into an array of
> hashes, like so (please ignore the pseudo code):
[snip]
> But this only prints the last row of the results set. I am sure that the
> hashe is being stored correctly initially, it's just understanding the syntax
> above (created by a co-worker) that is making life difficult/interesting.
>
> I cannot seem to visualize this in order to fully understand it. Any
> assistance would be helpful.
You definitely need the new Camel book, Perl Programming by O'Reilly.
All this is exhautively documented there. There are lots of examples
of weird data structures: arrays of hashes, hashes of arrays, etc.
--John Nolan
------------------------------
Date: Sat, 6 Dec 1997 10:27:54 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Marcello Pediconi <i101038@spv.ing.uniroma1.it>
Subject: Re: variable
Message-Id: <Pine.GSO.3.96.971206102440.16254B-100000@usertest.teleport.com>
On Fri, 5 Dec 1997, Marcello Pediconi wrote:
> I tried to define a variable in this way
> $testa1 = '<html><head><meta
> http-equiv="Content-Type"content="text/html".....
> The interpreter gives me some errors. How do I have to do to define this
> variable?
Fix the problems that cause the error messages. :-) For example, if the
message tells you that Perl can't find the string terminator, that means
that you need to put a closing quote mark on the string. All of Perl's
error messages are explained in the perldiag manpage. Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Sat, 06 Dec 1997 15:37:27 GMT
From: John Nolan <nospam@domain.com>
Subject: Re: what's wrong with this?
Message-Id: <348971AD.47C4@domain.com>
ddrayton@aol.com wrote:
>
> open (FILE, "$sf_cfg") or die ("Can't open it");
> while (<FILE>) {
> $newfile=$_;
> $newfile=~ s/$old_prodlist/$new_prodlist/g;
> print $newfile;
> }
> close (FILE);
>
> print $newfile will just print $old_prodlist without the substitution.
I think you meant to say:
open (FILE, "<$sf_cfg") or die ("Can't open it");
^
Maybe this was just a typo in your post. :)
--John Nolan
------------------------------
Date: Sat, 6 Dec 1997 10:31:50 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: what's wrong with this?
Message-Id: <mlub66.h61.ln@localhost>
John Nolan (nospam@domain.com) wrote:
: ddrayton@aol.com wrote:
: >
: > open (FILE, "$sf_cfg") or die ("Can't open it");
[snip]
: I think you meant to say:
: open (FILE, "<$sf_cfg") or die ("Can't open it");
: ^
: Maybe this was just a typo in your post. :)
Or maybe it defaults to opening for input, making the '<' part optional ;-)
[ at least that's what 'perlfunc' says about open() ]
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 1429
**************************************