[8446] in Perl-Users-Digest
Perl-Users Digest, Issue: 2063 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 10 11:14:40 1998
Date: Tue, 10 Mar 98 08:00:27 -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 Tue, 10 Mar 1998 Volume: 8 Number: 2063
Today's topics:
Re: Are There Any Snazzy Perl Editors for Windows? scott@softbase.com
Extra fun with RE (Ilya Zakharevich)
Re: Extract URL from search query (Joergen W. Lang)
Re: Finding perl version with script <quentin@jihad.amd.com>
Re: Help with embedding Perl in C <quentin@jihad.amd.com>
Help...Perl-Win32 and recursion keydet89@yahoo.com
Re: Help...Perl-Win32 and recursion <$_=qq!fearless\@NOSPAMio.com!;y/A-Z//d;print>
looking for a singaporean perl mentor <xiaoyu@singnet.com.sg>
Need help with programming project <kwaddell@gate.net>
Re: NOT matching a string, part ii <jdf@pobox.com>
nslookup? <lingjen@ra.isis.unc.edu>
Re: Perl file mode? <quentin@jihad.amd.com>
Re: Perl Hash question <jdf@pobox.com>
Re: Perl Hash question <jdporter@min.net>
Re: Prototype (like push) <jdf@pobox.com>
Re: Prototype (like push) (Paul Bardo)
Random number between 1 and 1000 (AGAIN...) (Bjorn Malmberg)
Re: Random number between 1 and 1000 (AGAIN...) <Tony.Curtis+usenet@vcpc.univie.ac.at>
Re: Random number between 1 and 1000 (AGAIN...) (Bjorn Malmberg)
Re: Random number between 1 and 1000 (AGAIN...) (Vincent Fatica)
Random number between 1 to 1000??? (Bjorn Malmberg)
Re: Random number between 1 to 1000??? <Tony.Curtis+usenet@vcpc.univie.ac.at>
Re: Random number between 1 to 1000??? (Bjorn Malmberg)
redirecting input AND output of a called program in per <ameyec@sebb.bel.alcatel.be>
Re: redirecting input AND output of a called program in <tchrist@mox.perl.com>
replacing/removing a escape secquence <shankeyp@charlestoncounty.org>
Re: rsh hanging... <dballing@speedchoice.com>
Re: Trouble With DBM / DBMX Functionality (Mike Heins)
Re: use Module vs. no Module ??? <jdporter@min.net>
why waitpid(-1, &WNOHANG) sometimes returns 0? <astromas@us.oracle.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 10 Mar 1998 14:16:59 GMT
From: scott@softbase.com
Subject: Re: Are There Any Snazzy Perl Editors for Windows?
Message-Id: <6e3i0r$bv6$4@scully.new-era.net>
Keith Turner (rkturner@us.ibm.com) wrote:
> Are there any text editors for windows that can recognize perl syntax and
> color code and such?
Well, there's GNU Emacs. It's the best thing going for Perl on Windows.
Multi-Edit is a great commercial editor that supports Perl syntax
highlighting. It has a very Windows look and feel, if you're not
used to Emacs. It also does really great printing, something
Emacs doesn't.
For more on Windows editors, check out www.skwc.com/essent/cyberreviews.html
and look for the text editor review.
Scott
--
Look at Softbase Systems' client/server tools, www.softbase.com
Check out the Essential 97 package for Windows 95 www.skwc.com/essent
All my other cool web pages are available from that site too!
My demo tape, artwork, poetry, The Windows 95 Book FAQ, and more.
------------------------------
Date: 10 Mar 1998 12:03:53 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Extra fun with RE
Message-Id: <6e3a79$ecq$1@mathserv.mps.ohio-state.edu>
This is a *quite* quick prime number lister via a RE. Note that it
requires 5.004_55 or better. It is possible to code it in pre-55 form
too, but the semantic of \2 was different between _55 and _59 due to a
bug/feature, and I do not know a RE which would work with all the
Perls.
(Note: for older Perls the effect of
((?(1)\1..|.))+
can be achieved with
(\1..|(?!\2)(.))+
- but it has different number of parens, so you need to change the ordinals.)
Enjoy,
Ilya
#! perl
# Print primes of the form 4n+1
use 5.00455;
$\ = "\n";
$_ = 'x';
m{^
(?= # a^2 + b^2, a > b
( # 1: a^2
((?(2)\2..|.))+
)
(?! \1 ) # Ensure a > b
( # 3: b^2
((?(4)\4..|.))+
)
$
)
(?! # not c^2 + d^2, c > d, d != b
( # 5: c^2
((?(6)\6..|.))+
)
(?! \5 ) # Ensure c > d
(?! \3 $ ) # Ensure d != b
((?(7)\7..|.))+
$
)
}sx and print length while $_ .= 'xx';
__END__
------------------------------
Date: Tue, 10 Mar 1998 16:04:23 +0100
From: joergen.lang@schwaben.de (Joergen W. Lang)
Subject: Re: Extract URL from search query
Message-Id: <1d5oinn.gljbn811sg9hcN@host022-206.seicom.net>
Mark Worsdall <scriptabuser@127.0.0.1> wrote:
> In article <8CRc6xDxc0$0EwXE@worsdall.demon.co.uk>, Mark Worsdall
> <scriptabuser@127.0.0.1> writes
> >Hi,
> >
> >I am trying to work out how to get url address to splitt. Note it could
> >be an address without subdirectorys or one with, i.e.:-
<snip>
> >$referer = "http://www.altavista.digital.com/cgi-bin/query?pg=q&stq=50&w
> >hat=web&kl=XX&q=building+the+core+muscles+of+the+athalete&navig60.x=7&na
> >vig60.y=11";
> >
>
> Has no one any ideas on this?
Hi Mark, the following might get you on the way:
Regular Expressions are your friends :-)
Information/Documentation is in the perlfaq6 and the perlre -pages which
should be part of your perl documentation which came with your perl.
Otherwise check http://www.perl.com for the above documents.
(If anyone knows a better way, please straighten me out...)
#!/usr/bin/perl -w
use strict;
my $referer =
"http://www.altavista.digital.com/cgi-bin/query?pg=q&stq=50&what=web&kl=
XX&q=building+the+core+muscles+of+the+athalete&navig60.x=7&navig60.y=11;
my $ref_without_query = $referer; # copy $referer.
$referer =~ s/^(.+\?).*/$1/; # Find out what this does...
print "$referer\n";
# prints: http://www.altavista.digital.com/cgi-bin/query?
$ref_without_query =~ s/^(.+)query?.*/$1/;
print "$ref_without_query\n";
# prints: http://www.altavista.digital.com/cgi-bin/
Hope this helps...
Joergen :-)
------------------------------
Date: 10 Mar 1998 09:16:16 -0600
From: Quentin Fennessy <quentin@jihad.amd.com>
Subject: Re: Finding perl version with script
Message-Id: <ximwwe2mv9b.fsf@jihad.amd.com>
>>>>> "MMJ" == Menno M Jansz <menno@cyberdude.com> writes:
MMJ> Please could someone tell me how I can retrieve the perl
MMJ> version using a script.
Assuming Perl 5, check out perlvar(1), in particular the section
with the string $PERL_VERSION.
$ perldoc perlvar
--
Quentin Fennessy AMD, Austin Texas
------------------------------
Date: 10 Mar 1998 08:13:15 -0600
From: Quentin Fennessy <quentin@jihad.amd.com>
Subject: Re: Help with embedding Perl in C
Message-Id: <xim1zwaocqs.fsf@jihad.amd.com>
>>>>> "SG" == Sudhir Gowda <gowda@slip.net> writes:
SG> I am trying to write a C program, which require to call some
SG> perl script inside it. What is the best way to do it. I did
SG> some reading on embedding perl interpreter in C article in
SG> perl faq. the reason for this is to pass the C variables to
SG> perl and get the results of the perl into C.
Check out perlembed(1).
perldoc perlembed
Here is a simple example that Mike Stok posted a while back.
I recall that it worked for me.
From: mike@stok.co.uk (Mike Stok)
Subject: Re: embeded perl inc
Newsgroups: comp.lang.perl.misc
Date: 26 Sep 1997 20:17:37 GMT
Do you need a space before the -I so that the compiler driver sees it?
I use something like
cc -o try try.c `perl -MExtUtils::Embed -e ccopts -e ldopts`
e.g.
[mike@stok tmp]$ more try.c
#include <EXTERN.h>
#include <perl.h>
static PerlInterpreter *my_perl;
int
main (int argc, char **argv, char **env) {
my_perl = perl_alloc ();
perl_construct (my_perl);
perl_parse (my_perl, NULL, argc, argv, env);
perl_run (my_perl);
perl_destruct (my_perl);
perl_free (my_perl);
}
[mike@stok tmp]$ cc -o try try.c `perl -MExtUtils::Embed -e ccopts -e ldopts`
[mike@stok tmp]$ ./try -e 'print "Hello\n"'
Hello
--
Quentin Fennessy AMD, Austin Texas
------------------------------
Date: Tue, 10 Mar 1998 06:57:40 -0600
From: keydet89@yahoo.com
Subject: Help...Perl-Win32 and recursion
Message-Id: <6e3da2$dm7$1@nnrp1.dejanews.com>
I'm having a little trouble w/ a script I am writing...
I have a list of IP addresses that are Win95 systems I monitor. I monitor
them to make sure that the users haven't enabled file sharing. The basics
of my script are:
open(MACHINE,"machines.txt");
while(<MACHINE>) {
$host = $_;
print $host;
open(NBT,"nbtstat -A $host |");
while(<NBT>) {
if(grep(/<20>/,$_)) {
print "Host $host has file sharing enabled";
}
}
close(NBT);
}
Now, the problem is that this works fine for a single IP address,
and the file is read fine, but when I try to run the script against
a file containing target IP addresses, it hangs after the first IP.
If I hit ctrl-C, the next IP appears, and I get a prompt back.
What I am doing wrong? I know there's a better way to do this,
but this little problem has me stumped.
Thanks
H. Carvey
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Tue, 10 Mar 1998 06:58:18 -0800
From: "Creede Lambard" <$_=qq!fearless\@NOSPAMio.com!;y/A-Z//d;print>
Subject: Re: Help...Perl-Win32 and recursion
Message-Id: <6e3kab$i7e@bgtnsc02.worldnet.att.net>
You might want to try this a slightly different way, just to see what
happens:
open(MACHINE,"machines.txt") or die "$!";
@machine = <MACHINE>;
close MACHINE;
foreach (@machine) {
$host = $_;
chomp($host);
print $host;
$info = `nbtstat -A $host`;
$flag = '<20>';
if (grep(/$flag/,$info) {
print "-- file sharing enabled!";
}
print "\n";
}
I haven't checked this code, but if it won't work, some kind guru will come
by and explain to me why. :D I think the problem you're experiencing may be
in one of two spots: either when you're reading from machines.txt, there's a
trailing newline that's effectively making your address something like
"127.0.0.1\n", or opening nbtstat as a filehandle is doing it. At any rate,
I hope this helps.
--- Creede Lambard
Minister of Irregular Expressions
Programming Republic of Perl
keydet89@yahoo.com wrote in message <6e3da2$dm7$1@nnrp1.dejanews.com>...
>I'm having a little trouble w/ a script I am writing...
>
>I have a list of IP addresses that are Win95 systems I monitor. I monitor
>them to make sure that the users haven't enabled file sharing. The basics
>of my script are:
>
>open(MACHINE,"machines.txt");
>
>while(<MACHINE>) {
> $host = $_;
> print $host;
> open(NBT,"nbtstat -A $host |");
>
> while(<NBT>) {
> if(grep(/<20>/,$_)) {
> print "Host $host has file sharing enabled";
> }
> }
>
> close(NBT);
>}
>
>
>Now, the problem is that this works fine for a single IP address,
>and the file is read fine, but when I try to run the script against
>a file containing target IP addresses, it hangs after the first IP.
>If I hit ctrl-C, the next IP appears, and I get a prompt back.
>
>What I am doing wrong? I know there's a better way to do this,
>but this little problem has me stumped.
>
>Thanks
>
>H. Carvey
>
>-----== Posted via Deja News, The Leader in Internet Discussion ==-----
>http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: 10 Mar 1998 14:55:46 GMT
From: "LauRenCe WonG" <xiaoyu@singnet.com.sg>
Subject: looking for a singaporean perl mentor
Message-Id: <01bd4c34$dfb78a80$a83a15a5@singnet.singnet.com.sg>
hi i am looking for a perl programmer who is able to help me with my
learning of perl. i live in singapore n have encountered lotsa problem
with perl (esp. pattern matching and using of associative lists.) i would
be really happy if i could get a mentor to help me.
please email me at beefie@post1.com.
San Yee
------------------------------
Date: Tue, 10 Mar 1998 09:00:16 -0500
From: Karl Waddell <kwaddell@gate.net>
Subject: Need help with programming project
Message-Id: <35054770.2781E494@gate.net>
To all concerned:
I know this is a discussion group, but I run a small IT Center and I am
in need of perl programmers. This seemed like a good spot to post the
message. Please excuse me if anyone is offended, but I need developers.
We are a Boca Raton based site with the marjority of our application
written in Perl. I am looking for full and part-time developers with Web
and DBI experiance in the UNIX environment. Informix knowledge is a
plus. I am not looking for consultants. In the past there have been to
many hands in the pot, which has caused the problem I am in now. If you
are in the West Palm Beach/Ft. Lauderdale area please fax your resume to
the attention of:
Karl Waddell
Director if IT Operations
(561)226-3630
Once again, I am in need of developers and I apologize if I have
offended anyone for my posting but it seem like the right spot to get to
the right people.
Thanks
------------------------------
Date: 10 Mar 1998 10:06:04 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: NOT matching a string, part ii
Message-Id: <u396lh5v.fsf@news.concentric.net>
miko@idocs.com writes:
> In response to an early, uh, response, I thought I'd head off one line of
> thought about this question. /(X.*)test/ is not what I'm looking for.
> This expression is too greedy. I need something would work for these
> examples:
>
> For the string "X whatever test test" it would find "X whatever "
> For the string "X hi there temp test" it would find "X hi there temp "
> For the string "Xtest" it would find "X"
Read the perlre doc and look for the non-greedy quantifier modifier
spelled "?". Here's a random, hypothetical example:
print "$1\n" if /(X.*?)test/; #but still RTFM, please
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
------------------------------
Date: Tue, 10 Mar 1998 09:48:56 -0500
From: Jim Murrell <lingjen@ra.isis.unc.edu>
Subject: nslookup?
Message-Id: <Pine.SOL.3.96.980310094407.25647A-100000@ra.isis.unc.edu>
I have been trying to write a short perl script
that takes an IP number and essentially does
an "nslookup". I would prefer not using the
system call to do but tried gethostbyaddr
without too much success. Does anyone have
an example of some perl code that does this?
Thanks,
Ling Jen
------------------------------
Date: 10 Mar 1998 09:10:50 -0600
From: Quentin Fennessy <quentin@jihad.amd.com>
Subject: Re: Perl file mode?
Message-Id: <ximyayimvid.fsf@jihad.amd.com>
>>>>> "DV" == Doug Vermes <dvermes@emerald.tufts.edu> writes:
DV> When you use the stat command to get information on a file,
DV> one of the values it returns is the file mode ($mode). I'm
DV> having a hard time making sense of this number. It certainly
DV> isn't the normal UNIX permissions. For example, a file with
DV> UNIX permission 600 comes back as 33152. How do I translate
DV> from one to the other? Thanks, Doug
Unix permission modes are traditionally represented in octal. Be
careful how you print it out. There are useful arguments to printf()
that can help you.
>From chmod(1) (FSF):
A numeric mode is from one to four octal digits (0-7),
derived by adding up the bits with values 4, 2, and 1. Any
omitted digits are assumed to be leading zeros. The first
digit selects the set user ID (4) and set group ID (2) and
save text image (1) attributes. The second digit selects
permissions for the user who owns the file: read (4), write
(2), and execute (1); the third selects permissions for
other users in the file's group, with the same values; and
the fourth for other users not in the file's group, with the
same values.
--
Quentin Fennessy AMD, Austin Texas
------------------------------
Date: 10 Mar 1998 09:48:30 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: Perl Hash question
Message-Id: <vhtmlhz5.fsf@news.concentric.net>
Gregory Propf <gregp@home.com> writes:
> Alright here it is - forget about what it does. It doesn't do anything,
> it's a pure experiment to see what a hash looks like after being passed
> to a subroutine. The idea was to get a local copy of the hash that the
> sub could play with while not perturbing the original (similar to C,C++
> argument passing).
> sub hashtest {
> shift(@_);
>
> foreach $arg (@_) {
> push(@hasharr,$arg);
> $i++;
> print "Arg $i :$arg\n";
> }
You're trying to run without having learned to walk. You need to
understand a bunch of fundamentals: the various Perl data types; the
way parameters are passed; what the "shift" builtin does; why you
might want to use references, etc. I think that you really ought to
buy a copy of _Learning Perl_ and spend a week with it and find out
these things from someone who's a much better writer than me (and much
more authoritative). To whet your appetite, I will demonstrate two
ways of passing a hash to a subroutine.
sub display_hash { | sub display_hash_from_ref {
my %h = @_; | my $href = shift;
foreach my $key (keys %h) { | foreach my $key (keys %$href) {
print "$key => $h{$key}\n"; | etc.
}
}
my %foo = (
hava => 'nagila',
vey => 'nismacha',
);
display_hash(%foo); | display_hash_from_ref(\%foo);
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
------------------------------
Date: Tue, 10 Mar 1998 10:14:36 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Perl Hash question
Message-Id: <350558DC.3165@min.net>
Gregory Propf wrote:
>
> The idea was to get a local copy of the hash that the
> sub could play with while not perturbing the original (similar to C,C++
> argument passing).
O.k. You have noticed that passing a hash as an argument
actually seems to pass a listified form of the hash,
consisting of ( key, val, key, val, ... ).
This is how perl passes hashes: it listifies them.
Fortunately, perl also provides the opposite transformation:
assigning a list to a hash interprets the list to consist
of ( key, val, key, val, ... ). That means you can do this:
sub hashtest {
my %hash = @_; # turn list of args into a hash.
for ( keys %hash ) {
print "key=$_, val=$hash{$_}\n";
}
}
Conversion between list and hash is transparent.
Later on, you'll run into the problem of mixing several
list and hash arguments in one sub call. To keep all
the arguments distinct, rather than listified into one
big list, you need to pass them by reference, like so:
my( %hashFoo, %hashBar, @array );
argstest( \%hashFoo, \@array, \%hashBar );
sub argstest {
my( $foo_ref, $a_ref, $bar_ref ) = @_; # they're all refs
my %foo = %{ $foo_ref }; # dereference to get your own copy
my @a = @{ $a_ref };
my %bar = %{ $bar_ref };
}
Since %foo, %bar, and @a are lexical ('my') variables in the
subroutine, changes to them do not affect the originals.
You can affect the originals if you want; that's a different
topic.
Hope This Helps.
John Porter
------------------------------
Date: 10 Mar 1998 09:27:34 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: net0018@edwardjones.com (Paul Bardo)
Subject: Re: Prototype (like push)
Message-Id: <yayiliy1.fsf@news.concentric.net>
[cited author cc'd]
net0018@edwardjones.com (Paul Bardo) writes:
> I am having difficulty getting a prototyped subroutine
> to work the way I want/expect.
I've been waiting for an answer to your post, myself. I am
mystified. I noticed that if you do the call as
try2 @x, (@y);
it works fine. But if you send the naked @y, then you can't even
refer to try2's @_ in the *debugger* without triggering the same
error. Very strange.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
------------------------------
Date: 10 Mar 1998 08:56:43 -0600
From: net0018@edwardjones.com (Paul Bardo)
Subject: Re: Prototype (like push)
Message-Id: <6e3kbb$len@ncsnews.edwardjones.com>
[cc to author]
In article <yayiliy1.fsf@news.concentric.net>,
Jonathan Feinberg <jdf@pobox.com> wrote:
>I've been waiting for an answer to your post, myself. I am
>mystified. I noticed that if you do the call as
>
> try2 @x, (@y);
>
>it works fine. But if you send the naked @y, then you can't even
>refer to try2's @_ in the *debugger* without triggering the same
>error. Very strange.
Given this fact and the fact that "Bizarre copy ..." is a panic
message which by definition (on p557 Camel) we should never see,
I would have to assume this is a bug. I guess I will send this
to the perlbug list.
--
Paul J. Bardo - Network Services
paul.bardo@edwardjones.com
Edward Jones
201 Progress Parkway St. Louis, MO 63043
------------------------------
Date: Tue, 10 Mar 1998 14:38:32 GMT
From: news@NOSPAMgb-design.com (Bjorn Malmberg)
Subject: Random number between 1 and 1000 (AGAIN...)
Message-Id: <35054fb0.39037526@news.algonet.se>
Thanks for your help Tony.... but it seems like I can't fix this
really... I read the perlfunc man pages and got no wizer about that :(
(rand Returns a random fractional number between 0 and the value of
EXPR. (EXPR should be positive.) If EXPR is omitted,
returns a value between 0 and 1. This function produces
repeatable sequences unless srand() is invoked. See also srand() . )
I've tried to change the EXPR to 1000 but nothing happens... still
same number all the time coming up..... I won't give up, never do...
but if you or someone else had an example that would make it a lot
easier for me !! Thanks for any help on this!
Bjorn
____________________________________________________
Take away the word NOSPAM to make an email reply! :)
------------------------------
Date: 10 Mar 1998 15:48:39 +0100
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
To: news@gb-design.com
Subject: Re: Random number between 1 and 1000 (AGAIN...)
Message-Id: <7xn2eyeh4o.fsf@beavis.vcpc.univie.ac.at>
Re: Random number between 1 and 1000 (AGAIN...), Bjorn
<news@NOSPAMgb-design.com> said:
Bjorn> Thanks for your help Tony.... but it seems like I
Bjorn> can't fix this really... I read the perlfunc man
Bjorn> pages and got no wizer about that :(
You *are* running perl5 aren't you (must be, you've got the
split manpages)? Maybe your perl installation is broken
(wrong # of bits for rand in config.sh?)
This works for me (on a variety of UNIX boxen and 2 perl5
versions):
use integer;
srand;
for (1..10) {
print 1+rand(1000), "\n";
}
tony
------------------------------
Date: Tue, 10 Mar 1998 15:08:46 GMT
From: news@NOSPAMgb-design.com (Bjorn Malmberg)
Subject: Re: Random number between 1 and 1000 (AGAIN...)
Message-Id: <350554da.40360611@news.algonet.se>
On 10 Mar 1998 15:48:39 +0100, Tony Curtis
<Tony.Curtis+usenet@vcpc.univie.ac.at> wrote:
>You *are* running perl5 aren't you (must be, you've got the
>split manpages)? Maybe your perl installation is broken
>(wrong # of bits for rand in config.sh?)
Yup, using perl5.003 .... The installation wasn't broken ... I just
didn't really understand the man pages :)
<snip>
> use integer;
> srand;
> for (1..10) {
> print 1+rand(1000), "\n";
> }
Thanks a lot for this peace of code, and for all your help! This
helped me over the edge....
This is what I was doing wrong:
use integer;
srand;
print srand(1000);
(put that little s infront of rand..... which produced the number 1
all the time, not good ..) Then I did this:
use integer;
srand;
print rand(1000);
Which made it random... but with all those other numbers I didn't
want...
Didn't put that little 1+ there .... ohh well.... works great now
thanks to you!!
Hmm, maybe I should post a snip of my code next time... would perhaps
be easier for any helpers to see my problem directly.....
(hehe, if there will be any more problems, hope not!)
Hmm, well, thanks a lot for your help, appreciate it!!
Bjorn
____________________________________________________
Take away the word NOSPAM to make an email reply! :)
------------------------------
Date: Tue, 10 Mar 1998 15:36:23 GMT
From: vefatica@syr.edu (Vincent Fatica)
Subject: Re: Random number between 1 and 1000 (AGAIN...)
Message-Id: <35085cee.63812267@news.ican.net>
On Tue, 10 Mar 1998 14:38:32 GMT, news@NOSPAMgb-design.com (Bjorn Malmberg)
wrote:
>Thanks for your help Tony.... but it seems like I can't fix this
>really... I read the perlfunc man pages and got no wizer about that :(
>
>(rand Returns a random fractional number between 0 and the value of
>EXPR. (EXPR should be positive.) If EXPR is omitted,
> returns a value between 0 and 1. This function produces
>repeatable sequences unless srand() is invoked. See also srand() . )
Each time I run this (perl 5.001) I get a different set of ten integers in the
range 1 - 1000, inclusive. It seems to be what you want.
srand;
for ($i=1; $i <= 10; $i++) {
$num = 1 + int(rand(1000));
print "$num\n";
}
- Vince
___
Vincent Fatica
Syracuse University Mathematics
vefatica@syr.edu
http://barnyard.syr.edu/~vefatica/
------------------------------
Date: Tue, 10 Mar 1998 12:33:55 GMT
From: news@NOSPAMgb-design.com (Bjorn Malmberg)
Subject: Random number between 1 to 1000???
Message-Id: <3505321a.31462842@news.algonet.se>
Hi folks!!
This might sound really stoopid... but I'm a newbie on perl.... I need
a random number between 1 to 1000 and I can't figure out how to do
this.... anyone know how to do this? There has to be!!
Please email me since I can't look at this list so often! Thanks for
any help on this !
Take away the word NOSPAM to make a reply! :)
------------------------------
Date: 10 Mar 1998 13:52:14 +0100
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
To: news@gb-design.com
Subject: Re: Random number between 1 to 1000???
Message-Id: <7xsooqn1xd.fsf@beavis.vcpc.univie.ac.at>
Re: Random number between 1 to 1000???, Bjorn
<news@NOSPAMgb-design.com> said:
Bjorn> Hi folks!! This might sound really stoopid... but
Bjorn> I'm a newbie on perl.... I need a random number
Bjorn> between 1 to 1000 and I can't figure out how to do
Bjorn> this....
man perlfunc -> "rand"
I presume you mean "a pseudo-random integer between 1 and
1000 inclusive"
use integer;
gives you integer arithmetic (perldoc integer)
Then
$n = rand 1000;
gives you a pseudo-random integer between 0 and 999. How to
get from there to what you want should hopefully be obvious :-)
You may also want to initialise with srand() and a suitable
seed value.
There's also a Math::TrulyRandom module.
hth
tony
--
Tony Curtis, Systems Manager, VCPC, | Tel +43 1 310 93 96 - 12; Fax - 13
Liechtensteinstrasse 22, A-1090 Wien, AT | http://www.vcpc.univie.ac.at/
"Everything I am, I learned on the back of cereal boxes" ~ RJ, "Over the Hedge"
------------------------------
Date: Tue, 10 Mar 1998 13:27:16 GMT
From: news@NOSPAMgb-design.com (Bjorn Malmberg)
Subject: Re: Random number between 1 to 1000???
Message-Id: <35053ebd.34698211@news.algonet.se>
Hi there!!
thanks for that very fast response on my question!!!!
However... I tried the thing you said, and got rid of the 1.324533465
and got only one number (1) But that wasn't so random .......
hmmm, I'm not so really familliar with rand() and srand() but I'm
learning ! :)
So, now I just have to get it random..... I tried to get the
Math::TrulyRandom package but found out that the package was older
than my perl package :(
Better try again, with another one ! :)
Anyway, thanks for tha fast help, and don't hesitate if you know what
I'm doing wrong, since I don't get a random number between 0-999 ...
hmmm, better work on my perl!
Thanks
Bjorn
On 10 Mar 1998 13:52:14 +0100, Tony Curtis
<Tony.Curtis+usenet@vcpc.univie.ac.at> wrote:
<snip>
>
> use integer;
>
>gives you integer arithmetic (perldoc integer)
>
>Then
>
> $n = rand 1000;
<snip>
____________________________________________________
Take away the word NOSPAM to make an email reply! :)
------------------------------
Date: Tue, 10 Mar 1998 15:04:24 +0100
From: Christof Ameye <ameyec@sebb.bel.alcatel.be>
Subject: redirecting input AND output of a called program in perl
Message-Id: <35054868.6C5F@sebb.bel.alcatel.be>
In perl you can easily redirect input OR output
open(FILEO,"command |"); #for getting output
open(FILEI,"| command"); #for giving input
but you can't do :
open(FILEIO,"| command |"); #for in AND output
But that's just what I need ...
Any idea how to do this easily ?
(with pipes ?? how do you do that ? maybe give me link with more info ?)
Christof
------------------------------
Date: 10 Mar 1998 15:02:01 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: redirecting input AND output of a called program in perl
Message-Id: <6e3kl9$sur$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Christof Ameye <ameyec@sebb.bel.alcatel.be> writes:
:In perl you can easily redirect input OR output
:open(FILEO,"command |"); #for getting output
:open(FILEI,"| command"); #for giving input
:but you can't do :
:open(FILEIO,"| command |"); #for in AND output
:
:But that's just what I need ...
:Any idea how to do this easily ?
% man perlfaq8
[....]
How can I open a pipe both to and from a command?
Or see the perlipc manpage.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
Actually, you'll know we're nearing the end when I make |$foo| mean
"absolute value"... :-) Larry Wall in <1994Feb25.192042.17196@netlabs.com>
------------------------------
Date: Tue, 10 Mar 1998 10:37:40 -0500
From: Peter Shankey <shankeyp@charlestoncounty.org>
Subject: replacing/removing a escape secquence
Message-Id: <35055E44.A6ABAF3F@charlestoncounty.org>
I have a file which has been moved to a unix system from a dos system.
The file contains a ^M or I should say a "ESC M". I know it a escape
sequence because I see it in vi but not with a cat command.
to get rid of it I have tried the follow with no success:
stuff
while (<CU>) {
s/^[M//;
print CUtemp $_;
}
stuff
I have tried a few variations of the regular expression with no success.
any idea would be helpful
thanks
pete
------------------------------
Date: Tue, 10 Mar 1998 07:56:50 -0600
From: Derek Balling <dballing@speedchoice.com>
Subject: Re: rsh hanging...
Message-Id: <A411599A4C3F04D1.65F69949D5C4AAA9.CE7C7A9A2976DF54@library-proxy.airnews.net>
Kim Kiat Tan wrote:
>
> In article <slrn6g37kl.ngv.Tom.Grydeland@mitra.phys.uit.no>, Tom.Grydeland@phys.uit.no (Tom Grydeland) wrote:
> >On Fri, 06 Mar 1998 23:40:23 GMT,
> >Kim Kiat Tan <kktan@concentric.net> wrote:
> >> I have the following code :
> >
> >> $out = `rsh rmthost .\test`;
> >
> >Are you absolutely sure you have a program named .<tab>test ?
> >
>
> well, it is typo, it is supposed to by $out=`rsh rmthost ./test`, and yes, the
> program does run.
SIGALARM is your friend.
------------------------------
Date: 10 Mar 98 13:27:27 GMT
From: mikeh@minivend.com (Mike Heins)
Subject: Re: Trouble With DBM / DBMX Functionality
Message-Id: <35053fbf.0@news.one.net>
Johan Nielsen <johan@nielsencorp.com> wrote:
> I have a slight problem successfully using the database functionality built
> into Perl5. The book that I'm using really only discusses using DB_File
> and that appears to be the old implementation of DBM functionality.
No, DB_File is newer and better than NDBM or ODBM.
> What I have installed on my Sun (Solaris 2.5) is the NDBM or ODBM
> implementation. In an attempt to use either of these implementation to
> create a DBM file, I come up against the following error when I execute the
> script.
> -------
> $ convert.pl -f convert.dat
> Identifier "main::opt_f" used only once: possible typo at convert.pl line
> 10.
> Argument "O_SVWST" isn't numeric in null at convert.pl line 19.
> $
> -------
Though I didn't look at the script itself, I suspect all you need is
"use Fcntl;" in there somewhere.
Regards,
Mike Heins http://www.minivend.com/ ___
Internet Robotics |_ _|____
There ain't nothin' in this world 131 Willow Lane, Floor 2 | || _ \
that's worth being a snot over. Oxford, OH 45056 | || |_) |
--Larry Wall <mikeh@minivend.com> |___| _ <
513.523.7621 FAX 7501 |_| \_\
------------------------------
Date: Tue, 10 Mar 1998 10:34:17 -0500
From: John Porter <jdporter@min.net>
Subject: Re: use Module vs. no Module ???
Message-Id: <35055D79.6BAE@min.net>
Martin Vorlaender wrote:
>
> John Porter (jdporter@min.net) wrote:
> : I know that use Module LIST causes a require of Module,
> : and calls Module::import( LIST );
> : my question is, if I say "no Module", does it result in a
> : call to a sub in Module? If so, what's it called?
>
> Looking into strict.pm, integer.pm and lib.pm gives me the impression
> that it's unimport() that gets called.
Yes, indeed, that is exactly the case.
I thought the documentation was vague on this point.
Nowhere did I see a statement, "use Module LIST causes a call to
Module->unimport(LIST)."
Thanks.
John Porter
------------------------------
Date: Tue, 10 Mar 1998 12:06:37 +0000
From: Aaron Stromas <astromas@us.oracle.com>
Subject: why waitpid(-1, &WNOHANG) sometimes returns 0?
Message-Id: <35052CCD.14562EA2@us.oracle.com>
hi,
i distilled the following test from the script i was working on when i
noticed this behavour. if i comment out the "sleep 2" everything happens
as expected:
bash-2.00$ ./test
s: 500500
s: 500500
PIDs: 18584 18585
Child process 18585 finished with status 0.
Child process 18584 finished with status 0.
if i put the sleep back in, i get this:
bash-2.00$ ./test
s: 500500
s: 500500
PIDs: 18576 18577
Child process 0 finished with status -1.
Child process 0 finished with status -1.
this is the code. can anybody offer an advice as to why this happens? tia,
#!/u01/home/ams/bin/perl -w
use FileHandle;
use IO::Socket;
use POSIX ":sys_wait_h";
my @pid;
for (0..1) {
my $pid = run();
push @pid, $pid if $pid > 0;
}
print "PIDs: ", join(' ', @pid), "\n";
for (0..$#pid) {
my $pid = waitpid(-1, &WNOHANG);
print "Child process $pid finished with status $?.\n";
}
sub run {
my $pid = fork;
return $pid if $pid;
for(0..1000) {
$s += $_;
}
print "s: $s\n";
#sleep 2;
exit 0;
}
--
Aaron Stromas astromas@us.oracle.com Oracle Corp.
Tel. 703 917 4872
"Tick-tick-tick.... ja, Pantani is weg." - BRTN commentator, L'Alpe d'Huez
Tour de France, 1995
------------------------------
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 2063
**************************************