[11716] in Perl-Users-Digest
Perl-Users Digest, Issue: 5316 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 7 01:27:24 1999
Date: Tue, 6 Apr 99 22:00:18 -0700
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, 6 Apr 1999 Volume: 8 Number: 5316
Today's topics:
Accessing a unix serial port (Neil Cherry)
Re: Accessing a unix serial port <aperrin@mcmahon.qal.berkeley.edu>
ActiveState PERL for Win32 -- How to. <jean_barry@my-dejanews.com>
Re: ActiveState PERL for Win32 -- How to. <ffchopin@worldnet.att.net>
Autoresponder ()
Re: Backslash: unclear on the concept (Ronald J Kimball)
Re: Can Perl script compile & call Perl source? (Larry Rosler)
Re: Can you stepthrough a Perl program? (Ronald J Kimball)
Re: Does anyone know how to do date/time functions in P <tavi367@ibm.net>
embedded Perl and Borland C++ Builder 4 <dchristensen@california.com>
Re: Help required urgently on CGI Perl (Ronald J Kimball)
Re: How to handle a ctrl-C interupt ? (Ran)
Re: Installed Perl 5.005_02, what are the paths? robbie55@my-dejanews.com
LWP Request Discrepancy <Dikheel@ResumeGuide.com>
mod_perl and apache installation problems <arranp@datamail.co.nz>
Re: Most elegant random string generator? (and => oddit (Tramm Hudson)
Re: Most elegant random string generator? (Larry Rosler)
Re: Perl as a first programming language - suitability, (Ronald J Kimball)
Problem Installing DBD:Pg <carl.roth@nospamhome.com>
Re: Q: array ref prototype in module (Ronald J Kimball)
random number northernnj@my-dejanews.com
Re: random number <ffchopin@worldnet.att.net>
Re: Seemingly Simple Regexp problem... (Ronald J Kimball)
Re: Very large regular expressions (Ronald J Kimball)
WANTED: Freelance PERL Developer <richard@sourceinternet.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 07 Apr 1999 03:40:22 GMT
From: njc@dmc.uucp (Neil Cherry)
Subject: Accessing a unix serial port
Message-Id: <slrn7gll1t.ucl.njc@dmc.uucp>
I checked the FAQ and found the section that tells you how to access
the serial port. So I wrote this code but I can't read anything from
the port. Any pointers on what I'm doing wrong? I did the following:
used minicom to check I had the right port (at 9600/8/N/1)
$ stty raw >/dev/ttyD3
$ stty </dev/ttyD3
speed 9600 baud; line = 0;
-brkint -imaxbel
$ perl hcs.pl
(0) 0x00 (0) 0x00 ...
Here is the code:
sysopen(dev, "/dev/ttyD3", 2) || die "Unable to open /dev/ttyD3 $!\n";
while(1) {
$a = sysread(<dev>, $buf, 1);
printf("(%d) 0x%02x ", $a, $buf); # a = bytes read, buf is the data
}
close(<dev>);
exit(0);
I may know how to program in other languages but I'm currently lost in
perl or I have somethign wrong with my system.
--
Linux Home Automation Neil Cherry ncherry@home.net
http://members.home.net/ncherry (Text only)
http://meltingpot.fortunecity.com/lightsey/52 (Graphics GB)
http://www2.cybercities.com/~linuxha/ (Graphics US)
------------------------------
Date: Tue, 06 Apr 1999 21:13:40 -0700
From: Andrew Perrin <aperrin@mcmahon.qal.berkeley.edu>
Subject: Re: Accessing a unix serial port
Message-Id: <370ADB74.85AA49A1@mcmahon.qal.berkeley.edu>
Lose the <> around the filehandle. Also, by convention (but not required),
handles are often written in all caps, so you might want to use DEV instead
of dev as your filehandle.
Hope this helps-
ap
Neil Cherry wrote:
> I checked the FAQ and found the section that tells you how to access
> the serial port. So I wrote this code but I can't read anything from
> the port. Any pointers on what I'm doing wrong? I did the following:
>
> used minicom to check I had the right port (at 9600/8/N/1)
> $ stty raw >/dev/ttyD3
> $ stty </dev/ttyD3
> speed 9600 baud; line = 0;
> -brkint -imaxbel
> $ perl hcs.pl
> (0) 0x00 (0) 0x00 ...
>
> Here is the code:
>
> sysopen(dev, "/dev/ttyD3", 2) || die "Unable to open /dev/ttyD3 $!\n";
>
> while(1) {
> $a = sysread(<dev>, $buf, 1);
> printf("(%d) 0x%02x ", $a, $buf); # a = bytes read, buf is the data
> }
>
> close(<dev>);
> exit(0);
>
> I may know how to program in other languages but I'm currently lost in
> perl or I have somethign wrong with my system.
> --
> Linux Home Automation Neil Cherry ncherry@home.net
> http://members.home.net/ncherry (Text only)
> http://meltingpot.fortunecity.com/lightsey/52 (Graphics GB)
> http://www2.cybercities.com/~linuxha/ (Graphics US)
--
-------------------------------------------------------------
Andrew J. Perrin - NT/Unix/Access Consulting - (650)938-4740
aperrin@mcmahon.qal.berkeley.edu (Remove the Junk Mail King)
http://www.geocities.com/SiliconValley/Grid/7544/
-------------------------------------------------------------
------------------------------
Date: Wed, 07 Apr 1999 03:51:30 GMT
From: jeanb <jean_barry@my-dejanews.com>
Subject: ActiveState PERL for Win32 -- How to.
Message-Id: <7eeko0$6pp$1@nnrp1.dejanews.com>
Can someone tell me where I can find instructions on using ActiveState PERL
for Win32?
It's the second time I install ActiveState PERL for Win32.
The first time it ran well, I could run my scripts and I was able to debug 'em
right inside my machine with messages like ERROR NEAR ... and so on.
Now I can run my scripts, but the window closes immediately after it finishes
running the script. There is no way to see anything, no output, no error
messages.
I tried someone's trick ( putting a <stdin> at the end) but it gives no error
messages.
Once it's installed, what do you do with it.
How to call the PERL interpreter and how to run scripts from the PERL window.
Using it like as command line does not work.
Jean Barry
Jean_barry@my-dejanews.com
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 7 Apr 1999 00:41:11 -0400
From: "Jason Simms" <ffchopin@worldnet.att.net>
Subject: Re: ActiveState PERL for Win32 -- How to.
Message-Id: <7eeoef$39p$1@bgtnsc01.worldnet.att.net>
> Can someone tell me where I can find instructions on using ActiveState
PERL
> for Win32?
Well, the included docs do a pretty good job... Or, try Learning Perl on
Win32 Systems.
> It's the second time I install ActiveState PERL for Win32.
>
> The first time it ran well, I could run my scripts and I was able to debug
'em
> right inside my machine with messages like ERROR NEAR ... and so on.
>
> Now I can run my scripts, but the window closes immediately after it
finishes
> running the script. There is no way to see anything, no output, no error
> messages.
You must be clicking on the script file to "execute" it. This will run the
program, true, but it will close the command window immediately upon exit.
Try this: Click on the MS DOS Prompt option from the Start Menu. Then, cd
to the directory where the script is. Type perl "program_name" where
"program_name" is the name of the script. I.E., perl myscript.pl. This
should execute more like you'd expect.
> I tried someone's trick ( putting a <stdin> at the end) but it gives no
error
> messages.
Forget this... Do it right, not with a cheesy hack...
> Once it's installed, what do you do with it.
Umm, you run Perl scripts with it...
> How to call the PERL interpreter and how to run scripts from the PERL
window.
> Using it like as command line does not work.
See above. Not sure what the last sentence means, but if it opens and then
closes a window, then the scripts are probably being associated correctly,
so I see no reason why it wouldn't work from the command prompt.
Jason Simms
------------------------------
Date: Wed, 07 Apr 1999 03:39:23 GMT
From: oscoord@visi.com ()
Subject: Autoresponder
Message-Id: <LrAO2.478$nb3.65940@ptah.visi.com>
Iam looking for an e-mail autoresponder script. I have been looking
everywhere without any luc. I see autoresponders everywhere on the
internet but I cannot seem to find a script anywhere. If you know of such
a script please let me know... it will be GREATLY appreciated!
Steve
------------------------------
Date: Tue, 6 Apr 1999 23:47:27 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Backslash: unclear on the concept
Message-Id: <1dpv32o.112s5d61wu0i4gN@p93.block2.tc4.state.ma.tiac.com>
Larry Rosler <lr@hpl.hp.com> wrote:
> In article <1dptb1k.1bjkko0rcj71wN@[207.60.170.55]> on Tue, 6 Apr 1999
> 01:25:25 -0400, Ronald J Kimball <rjk@linguist.dartmouth.edu >says...
> > Larry Rosler <lr@hpl.hp.com> wrote:
> >
> > > Within double quotes, \Q (and lots of other \-letter combinations) has a
> > > special meaning. Most of them create a single character. But the
> > > following don't (from perlsyn):
> >
> > s/perlsyn/perlop/;
> >
> > Under Quote and Quote-like Operators.
>
> How creative I am -- I invented a new type of off-by-one error! (Note
> the order of the files listed in `perldoc perl`.)
In that case, perlsyn++. :)
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Tue, 6 Apr 1999 19:51:54 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Can Perl script compile & call Perl source?
Message-Id: <MPG.1174681dbdad51b0989857@nntp.hpl.hp.com>
[Posted and a courtesy copy sent.]
In article <370AB910.53380918@jamstec.go.jp> on Wed, 07 Apr 1999
10:46:56 +0900, Phil Cummins <cummins@jamstec.go.jp >says...
> I wrote a Perl script which starts an external program
> that produces source code for a Perl subroutine. What I
> would like to do is capture that output (I think I can do
> that), and then compile and call the subroutine, all
> from within my Perl script. Can anyone please tell me
> if it is possible to do that, and, if so, how? Many thanks.
perldoc -f eval
The capability you need is provided by eval STRING.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 6 Apr 1999 23:47:29 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Can you stepthrough a Perl program?
Message-Id: <1dpv3gl.tnvhoq1hbe7pcN@p93.block2.tc4.state.ma.tiac.com>
Chris Newman <newman@dynamite.com.au> wrote:
> I am new to Perl programming but have some experience with using Borland
> C++. i am using MacPerl (MacOS) and have been look for the 'step
> through' and 'display register' buttons but to no avail. This is very
> useful features for debugging purposes. Anyone suggest how I can step
> through my Perl programs?
Short answer:
Read the perldebug manpage (at least the first part, anyway), and turn
on the Script : Perl Debugger menu command before you run your script.
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
perl -le 'print "Just another \u$^X hacker"'
------------------------------
Date: Tue, 6 Apr 1999 21:10:25 -0500
From: "tavi" <tavi367@ibm.net>
Subject: Re: Does anyone know how to do date/time functions in Perl
Message-Id: <370abe2e@news1.us.ibm.net>
smnayeem@my-dejanews.com wrote in message
<7ec4c5$4fk$1@nnrp1.dejanews.com>...
>In article <MPG.117118fc53da2ddc989707@206.184.139.132>,
>
>Maybe i am wrong but most of the modules i have to download (eg Date::Calc)
>comes in tar or gz format,
Nope, your not wrong. That's the way they ship.
> those are for unix rnt they?
They originated there, but they are by no means UNIX exclusive.
Get WinZIP (or the like) and un-tar them.
But you will have to modify the file name after you get it ftom CPAN...
module_tar.gz <-- original name
module.tar.gz <-- change it to this, WinZIP will work fine.
>and i know it might be very simple to find
>it using timelocal and localtime, but i need some
>examples to see how it works, everywhere i saw (FAQ, Camel book etc) the
>examples are given on present time using the time() function. Where can i
get
>a more detailed description. can someone provide some examples specific to
>this problem? thanks agniora
Cookbook is a great place to start.
Have you tried searching within deja news?
Also, if you have the Perl Resource Kit, it comes with a package installer
that pulls files off the net and installs them fo you, and the docs, in your
Perl directory.
I have found that alone is worth the proce of buying the CD/books.
Walter
------------------------------
Date: Tue, 6 Apr 1999 12:16:20 -0700
From: "David Christensen" <dchristensen@california.com>
Subject: embedded Perl and Borland C++ Builder 4
Message-Id: <370a5c91@news2.newsfeeds.com>
Hello, world!
I started a thread of discussion on
borland.public.cppbuilder.language:
>I am working on a medical analyzer UI/control application. My
idea
>is to use Perl scripts to specify the various test recipes. The
>scripts will be developed by myself and/or biochemistry people.
>
>Builder will need to provide a concurrent execution environment
(up
>to 60 tests, in any combination) and an API which includes things
>like:
>
> get_metadata(), set_metadata()
> get_machine_parm(), set_machine_parm()
> start_action(), sleep_until()
> get_data(), save_data()
> error_message()
> exit()
> etc.
>
>So, Builder will manage scripts, and the scripts will call Builder
>for services.
I received a detailed reply of how to do it with ActiveX:
>OK, then you'll need to do the following.
>
>a) Get hold of PerlScript (http://www.activestate.com/ActivePerl/)
>b) Install it on the machine in question
>c) In your code, create a COM object with the relevant GUID
>d) QueryInterface to get the IActiveScript and IActiveScriptParse
> interfaces
>e) Create an ActiveScriptSite object and attach the object to it.
>f) Call ParseScriptText
>g) Start the engine
>
>Yuck.
>
>Oh, and that's not done the callback hooking up. That requires
building
>an ITypeInfo object that describes all the methods/properties you
supply
>(because the engine will use IDispatch to call you back).
>
>It's about 2000 lines of code in my case. However, the users will,
if
>the wrost comes to the worst, be able to use VBScript instead if
they
>can't get their heads around Perl.
>
>Alan Bellingham
>alanb@episys.com
I am wondering if anybody else has ideas for embedding Perl in
Builder?
TIA,
David Christensen
dchristensen@california.com
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com/ The Largest Usenet Servers in the World!
---------== Over 72,000 Groups, Plus Dedicated Binaries Servers ==--------
------------------------------
Date: Tue, 6 Apr 1999 23:47:30 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Help required urgently on CGI Perl
Message-Id: <1dpv3u9.1bus33wjhwjtoN@p93.block2.tc4.state.ma.tiac.com>
Arnab Guin <arnab@india.ti.com> wrote:
> I have created a homepage which uses forms extensively .All my scripts
> are in Perl and they work from my directory .However , when I tried to
> upload all my files to Tripod[homepage builder] , I am facing grave
> problems because I do not know about the Perl location there .Can anyone
> advise me what to do about this ?
I would advise you to ask Tripod the location of Perl there.
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: 7 Apr 1999 04:56:26 GMT
From: ran@netgate.net (Ran)
Subject: Re: How to handle a ctrl-C interupt ?
Message-Id: <7eeohq$b1m$1@remarQ.com>
In <370A8EE0.F98AFBAC@mail.cor.epa.gov>, "David L. Cassell" <cassell@mail.cor.epa.gov> writes:
>At least he didn't write "morituri te salutamus". :-)
I sorta thought asking how to do that was part of his question...
------------------------------
Date: Wed, 07 Apr 1999 02:09:32 GMT
From: robbie55@my-dejanews.com
Subject: Re: Installed Perl 5.005_02, what are the paths?
Message-Id: <7eeeoo$20p$1@nnrp1.dejanews.com>
I have the same problem - except I am using Xitami as my server.
I have read tons of postings on the various newsgroups, but cannot
find the complete answer.
The Problem:
When evoking a perl script from an HTML document on my pc
(i.e. not connected to the Internet, but using Xitami as my server)
the browser wants to download it.
I already know how to run my script from the dos prompt, and this is not
want I want to do. I want to evoke from my browser using Xitami.
The (part) solution I have found:
Tell your pc that *.pl should be opened...
How do you do this for windows 95, I have found a solution for windows 98,
using REGEDIT, but windows 95 seems to be different.
Any help would be most appreciated.
It would also be nice if you could email me as well as posting here.
Email to rj-nospam-@telinco.co.uk
Remove the "-nospam-"
Many thanks,
Robert
In article <3707B04C.9887C6C5@webknights.com>,
"WebMaster of WebKnights.com" <webmaster@webknights.com> wrote:
> Hello! I installed Perl 5.005 and I don't have any clue what the paths
> are. I installed Perl into C:\Perl if that helps. I need to know all of
> the most commonly used paths, pleeeease. Also, when I run a Perl script
> using my webserver (MS WebServer, which is running on my local hard
> drive, not on the web), but the browser doesnt seem to want to run it.
> It wants to download it! Please help!
>
> Please send replies to: webmaster@webknights.com
>
> --
> -Defiant
> webmaster@webknights.com
> http://www.webknights.com/
>
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 06 Apr 1999 22:14:44 -0400
From: Dikheel Al-Dikheel <Dikheel@ResumeGuide.com>
Subject: LWP Request Discrepancy
Message-Id: <370ABF93.E88F95AF@ResumeGuide.com>
Greetings,
I was trying out LWP on diffrent URL's but what caught my attention
was the fact that the simple get method
$res = get('http://www.yahoo.com/r/ar');
worked on a spesific URL above, and many more from the Yahoo site, while
the more robust $ua->request method
$res = $ua->request(HTTP::Request->new(GET =>
'http://www.yahoo.com/r/ar'));
failed? does any one know why that happened? $ua->request results in a
404 page not found, while the other get's the actual page. My guess
would have to redirection, but the second method should be able to
handle it.
If anyone know the answer please help me out with it. I'm very puzzeled.
Kindest Regards,
Dikheel
------------------------------
Date: Wed, 07 Apr 1999 14:17:15 +1200
From: Arran Price <arranp@datamail.co.nz>
Subject: mod_perl and apache installation problems
Message-Id: <370AC02B.711D@datamail.co.nz>
Hi all,
Im having problems trying to install modperl into apache on my debian
linux box.
Versions are as follows:
gcc version egcs-2.91.63 19990224 (egcs-1.1.2 pre-release-3)
apache_1.3.6
mod_perl-1.18
perl, version 5.004_04 built for i386-linux
uname -a = Linux myhostname 2.0.29
I made modperl using the following
perl Makefile.PL APACHE_SRC=/usr/src/apache_1.3.6/src DO_HTTPD=1
USE_APACI=1 PREP_HTTPD=1 PERL_CHILD_INIT=1 PERL_AUTHEN=1 PERL
_AUTHZ=1 PERL_CLEANUP=1 PERL_STACKED_HANDLERS=1
then tried to make apache (the output follows)
/usr/src/apache_1.3.6> ./configure --prefix=/usr/local/apache
--activate-module=src/modules/perl/libperl.a
Configuring for Apache, Version 1.3.6
+ using installation path layout: Apache (config.layout)
+ activated perl module (modules/perl/libperl.a)
Creating Makefile
Creating Configuration.apaci in src
Creating Makefile in src
+ configured for Linux platform
+ setting C compiler to gcc
+ setting C pre-processor to gcc -E
+ checking for system header files
+ adding selected modules
o perl_module uses ConfigStart/End
+ mod_perl build type: OBJ
+ id: mod_perl/1.18
+ id: Perl/5.00404 (linux) [perl]
Note (probably harmless): No library found for -ldbm
+ setting up mod_perl build environment
+ adjusting Apache build environment
/usr/bin/ld: cannot open -lgdbm: No such file or directory
collect2: ld returned 1 exit status
make: *** [dummy] Error 1
+ doing sanity check on compiler and options
** A test compilation with your Makefile configuration
** failed. This is most likely because your C compiler
** is not ANSI. Apache requires an ANSI C Compiler, such
** as gcc. The above error message from your compiler
** will also provide a clue.
Aborting!
I have no idea what lgdbm is or why it causes this. I tried to find it
and remove the reference to it, but havent been able to.
Any help greatly appreciated.
I have checked out dejanews and FAQs to no avail.
Arran,
arranp@datamail.co.nz
My opinions are my own and do not reflect those of my employer.
------------------------------
Date: 6 Apr 1999 21:57:49 -0600
From: hudson@swcp.com (Tramm Hudson)
Subject: Re: Most elegant random string generator? (and => oddity)
Message-Id: <7eel3t$lbq@llama.swcp.com>
[cc'd to cited author]
In article <MPG.11746705ea3fe583989856@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
[snipage]
>@charlist = (0 .. 9, 'A' .. 'Z', 'a' .. 'z');
>
>$random_string = join "" =>
> map $charlist[rand @charlist] => 1 .. $number_of_chars;
Your code is essentially the same as mine, but with an interesting
use of the => and , equivilance. According to perldoc -f map,
the first argument may be an expression -- I didn't know that!
And since map supplies list context, my parentheses on (1..$nchar)
were superfluous.
Ok, and as I look at it some more the => "operator" makes more
sense now in this context. Cool. So according to perlop it is
more than just a synonym -- the left hand side is forced to be a string.
Well, not really, since if it "looks like an expression" it will be
treated as one. DWIM again.
Weird -- perl 5.004_01 does this on my x86 Linux box:
: straylight:/tmp% perl -e 'x-a => b'
: syntax error at -e line 1, near "x-a"
: Execution of -e aborted due to compilation errors.
: zsh: segmentation fault (core dumped) perl -e x-a => b
: straylight:/tmp% perl -v
:
: This is perl, version 5.004_01
: ....
and then in the debugger:
: DB<1> x aaaaa-z => 'foo'
: syntax error at (eval 3) line 2, near "aaaaa-z"
: DB<2> x foo-bar => bar
: 0 0
: 1 'bar'
: DB<3> x x-y => z
: syntax error at (eval 7) line 2, near "x-y"
: DB<4>
Huh? It appears that any single character after the - makes an error.
This was repeated with version 5.004_04 built for sun4-sunos in
the debugger, but the command line segfault failed to manifest.
Perhaps it is trying to treat the -y or -z as a file test operator
and the foo-bar as two barewords in an expression.
And for real silyness, combine with the repeat operator:
: % touch x ; chmod +x x
: % perl -de 42
: DB<1> x x x-x 'x'
: 0 'x'
Just A Tramm
(we come in six-packs)
--
o hudson@swcp.com tbhudso@cs.sandia.gov O___|
/|\ http://www.swcp.com/~hudson/ H 505.266.59.96 /\ \_
<< KC5RNF @ N5YYF.NM.AMPR.ORG W 505.284.24.32 \ \/\_\
0 U \_ |
------------------------------
Date: Tue, 6 Apr 1999 19:47:10 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Most elegant random string generator?
Message-Id: <MPG.11746705ea3fe583989856@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <370A9C02.DD16F793@well.com> on Tue, 06 Apr 1999 16:42:58 -
0700, Greg McCann <gregm@well.com> says...
+ The following simple program generates a random string of characters
+ (it's being used as a session ID in a web application). It works
+ well, but being new to Perl I'm wondering if there is a more efficient
+ and/or elegant way of doing this - without being TOO obfuscatory!
...
+ #!/usr/local/bin/perl -w
+ use strict;
+
+ my @charlist; # chars to use in random string
+ my $random_string; # string of random chars
+ my $number_of_chars = 20; # final length of string
+ my $i; # loop counter
+
+ @charlist = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
+ 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
+ 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
+
+ for ($i = 0; $i < $number_of_chars; $i++) {$random_string .=
+ $charlist[rand 62]}
+
+ print $random_string;
Same algorithm, just expressed more concisely (Perlishly). It is
slightly more efficient, and it's not obfuscatory (to me :-). But I
don't know if I'd have come up with it had I not read it in this
newsgroup a long while ago.
@charlist = (0 .. 9, 'A' .. 'Z', 'a' .. 'z');
$random_string = join "" =>
map $charlist[rand @charlist] => 1 .. $number_of_chars;
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 6 Apr 1999 23:47:31 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Perl as a first programming language - suitability, good books ?
Message-Id: <1dpv4ap.1h1z0dxuyhm8bN@p93.block2.tc4.state.ma.tiac.com>
Chris Newman <newman@dynamite.com.au> wrote:
> I had read some very encouraging reviews about a book called "Perl
> Cookbook" by Tom Christiansen (an OReilly's book) which suits all levels
> of programmer. Anyone get any thoughts on this book?
The Perl Cookbook is a great book, and is suitable for all levels of
programmers, but I don't think it would make a good guide for actually
learning the language.
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Wed, 07 Apr 1999 02:06:20 GMT
From: "Carl Roth" <carl.roth@nospamhome.com>
Subject: Problem Installing DBD:Pg
Message-Id: <w4zO2.23358$L66.18721@news.rdc1.bc.wave.home.com>
The readme for the DBD:Pg (version .73 as I am using Postgresql 6.3 and
RedHat Linux 5.1) insists that I be logged in as a normal user for the
install but when I run "perl Makefile.PL" I get an error that says "Unable
to open MakeMaker.tmp: Permission denied at (eval 1) line 613". I have
successfully tested postrgresql and the DBI module but when I installed DBI
I did it as root so no problems came up. Could someone tell me what is the
cause of this problem ie. what permission am I lacking?
Thanks and please email me as well as post to the group.
Carl
carl.roth@home.com
(please remove the 'nospam' form my email address)
------------------------------
Date: Tue, 6 Apr 1999 23:47:32 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Q: array ref prototype in module
Message-Id: <1dpv53p.bs5dkj11rrblwN@p93.block2.tc4.state.ma.tiac.com>
Dan Halbert <halbert@bbn.com> wrote:
> This is perl 5.005_02.
>
> I'm getting an unexpected compile error complaining about an array vs.
> ref arg mismatch on a routine imported from a module, but not on a
> similar routine not in a module. I'm puzzled; It looks OK to me.
>
> test.pl:
> ==============================================================================
> #!/usr/local/bin/perl -w
>
> use strict;
> use MyModule;
>
> my @a = ();
>
> f(\@a); # defined in MyModule
> g(\@a); # defined here
>
> sub g(\@) { }
You code is incorrect for both function calls. You don't get an error
on the non-module subroutine because the call is compiled before the
subroutine definition, i.e. before the prototype is specified.
Change this to:
#!/usr/local/bin/perl -w
use strict;
use MyModule;
sub g(\@) { }
my @a = ();
f(\@a); # defined in MyModule
g(\@a); # defined here
And you should get the error for both lines.
Solution: Refer to the perlsub documentation:
Because the intent is primarily to let you define subroutines that
work like builtin commands, here are the prototypes for some other
functions that parse almost exactly like the corresponding builtins.
Declared as Called as
...
sub mypop (\@) mypop @array
sub mysplice (\@$$@) mysplice @array,@array,0,@pushme
...
Any backslashed prototype character represents an actual argument that
absolutely must start with that character. The value passed to the
subroutine (as part of @_) will be a reference to the actual argument
given in the subroutine call, obtained by applying \ to that argument.
When you use a prototype of (\@), you call the function as func(@array),
not func(\@array). The reference is implicit.
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Wed, 07 Apr 1999 04:37:02 GMT
From: northernnj@my-dejanews.com
Subject: random number
Message-Id: <7eendd$8uh$1@nnrp1.dejanews.com>
Why doesn't the random number generator work?
When I put in:
#!usr/bin/perl -w
srand;
@array = (1 .. 10);
$random_number = "rand(@array)";
print = "$random_number\n";
I get:
rand 1 2 3 4 5 6 7 8 9 10
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 7 Apr 1999 00:45:18 -0400
From: "Jason Simms" <ffchopin@worldnet.att.net>
Subject: Re: random number
Message-Id: <7eeom4$476$1@bgtnsc01.worldnet.att.net>
> When I put in:
>
> #!usr/bin/perl -w
> srand;
> @array = (1 .. 10);
> $random_number = "rand(@array)";
> print = "$random_number\n";
>
>
> I get:
> rand 1 2 3 4 5 6 7 8 9 10
Well, the " " are doing variable interpolation. Do this:
$random_number = rand(@array);
This should work better... The quotes are printing the word rand followed
by the contents of @array, due to the quotes, instead of the value of the
function.
Jason Simms
------------------------------
Date: Tue, 6 Apr 1999 23:47:34 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Seemingly Simple Regexp problem...
Message-Id: <1dpv5dm.1in62i9k2f6dnN@p93.block2.tc4.state.ma.tiac.com>
Diggy Tim <tim@diggy.com> wrote:
> Here is my problem.. I am trying to delimit a string so that only specified
> allowed characters arn't replaced by an underscore...
> The allowed characters are
> A-Z a-z 0-9 . (fullstop) - @
>
> I can easliy make a regexp which replaces the allowed characters, but i was
> hoping it would be possible to specifiy it to only replace characters not in
> that group... This has stumped me, this will be in a fairly intensive area
> of operation so it needs to be as fast as possible...
>
> Is a regexp the best solution??
No. For character to character translations, tr/// is the better
choice.
tr/a-zA-Z0-9.@-/_/c;
--
#!/usr/bin/sh -- chipmunk (aka Ronald J Kimball)
perl -se 'print sort grep tr/ \n//, keys %main::
' -- -is -' Just' -' another ' -'Perl ' -'hacker
' http://www.tiac.net/users/chipmunk/ [rjk@linguist.dartmouth.edu]
------------------------------
Date: Tue, 6 Apr 1999 23:47:35 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Very large regular expressions
Message-Id: <1dpv5qc.wmdlcm99y6pvN@p93.block2.tc4.state.ma.tiac.com>
Sean McAfee <mcafee@waits.facilities.med.umich.edu> wrote:
> Now if I can only figure what effect, if any, the \G assertion has.
The same effect it always has. :) \G anchors the match at pos().
> foreach $regex (@regex) {
> $letter =~ /$regex/g or die;
> # The above line seems to work exactly the same if I say:
> # $letter =~ /\G$regex/g or die;
> $i = 0; $hash{ $keys[$n++] } = $$i while defined ${++$i};
> }
Note that to keep pos() from being reset for a failed match, you should
add the /c modifier.
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
perl -e '$_="\012534`!./4(%2`\cp%2,`(!#+%2j";s/./"\"\\c$&\""/gees;print'
------------------------------
Date: Tue, 06 Apr 1999 20:04:56 -0700
From: Richard Greenwood <richard@sourceinternet.com>
Subject: WANTED: Freelance PERL Developer
Message-Id: <370ACB58.41A32D89@sourceinternet.com>
respond to perl@sourceinternet.com
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 5316
**************************************