[11715] in Perl-Users-Digest
Perl-Users Digest, Issue: 5315 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 6 22:27:27 1999
Date: Tue, 6 Apr 99 19:00:20 -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: 5315
Today's topics:
Re: Anyone help with reading from data file? Read here (Randal L. Schwartz)
Can Perl script compile & call Perl source? <cummins@jamstec.go.jp>
Can you stepthrough a Perl program? <newman@dynamite.com.au>
Re: duplicate checker (Larry Rosler)
Re: Elegant parsing of HTML title and metatags? <nmorison@ozemail.com.au>
Re: Elegant parsing of HTML title and metatags? (Randal L. Schwartz)
Re: Hash help <jglascoe@giss.nasa.gov>
Re: Hash help (Tad McClellan)
How do I grab a page on the net using sockets? <indexfinger@usa.net>
Re: How do I grab a page on the net using sockets? <indexfinger@usa.net>
Re: How do I grab a page on the net using sockets? <rick.delaney@home.com>
Re: How do I grab a page on the net using sockets? (Randal L. Schwartz)
Re: Most elegant random string generator? (Andre L.)
Re: Most elegant random string generator? (Matthew Bafford)
Re: Most elegant random string generator? (Tramm Hudson)
need to make http request jdinkler@my-dejanews.com
Newbie to PERL - SUGGESTION NEEDED index file <jychu@us.oracle.com>
Re: Perl as a first programming language - suitability, <newman@dynamite.com.au>
Re: Perl as a first programming language - suitability, <jglascoe@giss.nasa.gov>
Re: regexp matching digits <cassell@mail.cor.epa.gov>
Re: regexp matching digits <rick.delaney@home.com>
Seemingly Simple Regexp problem... <tim@diggy.com>
Re: Seemingly Simple Regexp problem... <rick.delaney@home.com>
Re: setting env variables, sourcing, etc. (Tad McClellan)
Trouble with DBI and Oracle (Darren Greer)
Re: Trouble with Oraperl, and simple select statement <campbellh@cs.net>
Re: typeglobs and strict....simple qn. <rick.delaney@home.com>
Re: Unpack Question <rick.delaney@home.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 06 Apr 1999 18:32:17 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Anyone help with reading from data file? Read here.
Message-Id: <m1lng56wri.fsf@halfdome.holdit.com>
>>>>> "Ed" == Ed Prochak <prochae@diebold.com> writes:
Ed> reverse(@lines);
You keep using that line. I do not think that line means[1] what
you think it means.[2]
print "Just another Perl hacker,"
[1] as in, there's no action going on there. reverse doesn't alter
its arguments
[2] reference to Princess Bride
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Wed, 07 Apr 1999 10:46:56 +0900
From: Phil Cummins <cummins@jamstec.go.jp>
Subject: Can Perl script compile & call Perl source?
Message-Id: <370AB910.53380918@jamstec.go.jp>
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.
------------------------------
Date: Wed, 07 Apr 1999 10:23:18 +1000
From: Chris Newman <newman@dynamite.com.au>
Subject: Can you stepthrough a Perl program?
Message-Id: <370AA575.FE37C521@dynamite.com.au>
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?
------------------------------
Date: Tue, 6 Apr 1999 18:00:51 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: duplicate checker
Message-Id: <MPG.11744e1954824622989854@nntp.hpl.hp.com>
In article <370AA001.11747E2F@mail.cor.epa.gov> on Tue, 06 Apr 1999
17:00:01 -0700, David L. Cassell <cassell@mail.cor.epa.gov> says...
> Surgie wrote:
> > I'm wondering if there was a built-in perl function to check if 2 arrays
> > have any of the same entries, and if not if anyone has a good function I
> > could use?
...
> > and it would tell me there was a duplicate (return false, true, whatever)
>
> You want the intersection of two arrays. At the command line,
> type 'perldoc -q intersection' and get the FAQ for this question:
> "How do I compute the difference of two arrays? How do I compute
> the intersection of two arrays?"
>
> perldoc is worth learning to use. You'll always be happier
> finding your own answers in a second, rather than waiting hours
> to have some jerk just say "At the command line, type 'perldoc -q
> intersection'." :-)
You are being rather harsh on someone who might never have studied
Boolean algebra. I would guess that had Surgie known to search the
documentation for 'intersection' he might have used that rather
technical term in the problem statement.
`perldoc -q array` would have produced the FAQ with 'intersection' in
its title (among several others), but even that wouldn't have answered
the problem without knowing what 'intersection' means.
Only a complete reading of the section 'Arrays' in perlfaq4 might have
sufficed. That would have had long-lasting good effects, but would also
have taken longer than simply asking here for a pointer to a function.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 07 Apr 1999 10:52:08 +1000
From: Neale Morison <nmorison@ozemail.com.au>
Subject: Re: Elegant parsing of HTML title and metatags?
Message-Id: <370AAC37.2CDE@ozemail.com.au>
Neale Morison wrote:
>
> I'd appreciate any help. I'm new to regexs and I'm looking for the most
> elegant and efficient syntax.
> I'm trying to parse out the title and metatags from an HTML file.
> The following is my partial solution but it has serious flaws:
> - it's inelegant - for example, I don't think I should have to
> explicitly set $_ and use an if statement with the match.
> - it doesn't work - it only extracts the last metatag, and I want to get
> them all
> - it may be memory inefficient and slow for large files - do I have to
> read the whole file into memory, or is there a cute way of doing this
> reading line by line?
> - I have heard that using $1 and $2 has an overhead and ideally I'd like
> to avoid that
>
> $filename = "test1.html";
> open FILE, $filename ;
> local $pagetext;
> local $metatags;
>
> while (<FILE>) { $pagetext .= $_ }
> close FILE;
> $_ = $pagetext;
> if (m{.*<TITLE>(.*)</TITLE>.*}si) { # parse out the title
> $title = $1;
> $title =~ s/\n//;
> }
> if (m{^.*<META NAME\s*=\s*\"(.*)\"\s*CONTENT\s*=\s*\"(.*)\"\s*>.*$}si) {
> # parse out the metatags
> $metatags{$1} = $2;
> }
>
> print $title;
> while(($key,$val) = each(%metatags))
> {
> print "$key: $val\n";
> }
Thanks very much for all your help. This is a great newsgroup.
All the best,
--
Neale Morison
Consultant, Wordface
mailto:nmorison@NOSPAMozemail.com.au http://www.wordface.com.au
------------------------------
Date: 06 Apr 1999 18:27:51 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Elegant parsing of HTML title and metatags?
Message-Id: <m1soad6wyw.fsf@halfdome.holdit.com>
>>>>> "Neale" == Neale Morison <nmorison@ozemail.com.au> writes:
Neale> I'd appreciate any help. I'm new to regexs and I'm looking for the most
Neale> elegant and efficient syntax.
Neale> I'm trying to parse out the title and metatags from an HTML file.
Neale> The following is my partial solution but it has serious flaws:
Neale> - it's inelegant - for example, I don't think I should have to
Neale> explicitly set $_ and use an if statement with the match.
Neale> - it doesn't work - it only extracts the last metatag, and I want to get
Neale> them all
Neale> - it may be memory inefficient and slow for large files - do I have to
Neale> read the whole file into memory, or is there a cute way of doing this
Neale> reading line by line?
Neale> - I have heard that using $1 and $2 has an overhead and ideally I'd like
Neale> to avoid that
it's also reinventing the wheel...
use HTML::HeadParser;
my $p = HTML::HeadParser->new;
while (<DATA>) {
last unless $p->parse($_);
}
print "title is ", $p->header->title, "\n";
print $p->header->as_string;
__END__
<html><head>
<title>Stupid example</title>
<base href="http://www.sn.no/libwww-perl/">
<meta name="fred" content="barney">
<meta http-equiv="Foo" content="Bar">
</head><body>
Normal text starts here.
</body></html>
which yields:
title is Stupid example
Content-Base: http://www.sn.no/libwww-perl/
Foo: Bar
Title: Stupid example
X-Meta-Fred: barney
You're allowed to reinvent the wheel, but only if you first study
the wheel. :)
print "Just another Perl hacker,"
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Tue, 06 Apr 1999 19:46:46 -0400
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: John Christena <john.christena@tivoli.com>
Subject: Re: Hash help
Message-Id: <370A9CE6.96E07AD8@giss.nasa.gov>
[courtesy copy of post sent to cited author]
John Christena wrote:
>
> I would like the hash to point to the variable $varname and be
> recognized as that variable with the value of $varname. Any hints are
> appreciated.. Thx.
my $num = 7;
my %hash = ('num' => \$num);
# now "$hash{'num'}" is a reference to a scalar
# dereference it like so "${ $hash{'num'} }"
my $fmt = "\$num = %s, \${ \$hash{'num'} } = %s\n";
printf $fmt, $num, ${ $hash{'num'} };
$num *= 6;
printf $fmt, $num, ${ $hash{'num'} };
${ $hash{'num'} } -= 5;
printf $fmt, $num, ${ $hash{'num'} };
Jay Glascoe
------------------------------
Date: Tue, 6 Apr 1999 16:10:26 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Hash help
Message-Id: <inpde7.bq1.ln@magna.metronet.com>
John Christena (john.christena@tivoli.com) wrote:
: Hello. I have a hash that contains several scalar variables.
Good. Since scalar variables are the only thing that you are
allowed to have in a hash :-)
: I want to
: reference members of this hash and have the value of the scalar
: interpreted.
Have it interpreted as _what_?
: Is this possible?
I don't understand the question.
: Such as:
: $varname="list"
: $hashname{$varname}=?
: I would like the hash to point to the variable $varname
That sounds like you want the value of the hash to be a
reference to $varname:
$hashname{$varname} = \$varname;
: and be
: recognized as that variable with the value of $varname.
I'm not sure what that means, but this:
print "${$hashname{$varname}}\n";
prints 'list'.
Is that what you meant?
: Any hints are
: appreciated.. Thx.
perldoc perlref
: Please respond to john.christena@tivoli.com
Ask it here, get the answer here.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 07 Apr 1999 00:43:06 GMT
From: "IndexFinger.com" <indexfinger@usa.net>
Subject: How do I grab a page on the net using sockets?
Message-Id: <uSxO2.251$xI5.9780@typhoon.nycap.rr.com>
How do I grab a page on the net using sockets?
------------------------------
Date: Wed, 07 Apr 1999 00:55:20 GMT
From: "IndexFinger.com" <indexfinger@usa.net>
Subject: Re: How do I grab a page on the net using sockets?
Message-Id: <Y1yO2.256$xI5.9808@typhoon.nycap.rr.com>
> How do I grab a page on the net using sockets?
So I don't confuse you about want I'm trying to do, I need to get an html
file off my partner's site each day. Using the contents of that page, I
produce an html file on my site. I've seen some perl programs use sockets.
Basically, I need the contents of that page to be pushed in to an array
where I can look at each line. The hard part is that I don't know how to get
the contents of the text file in to the array.
Can someone give me all the code I need?
Thanks.
------------------------------
Date: Wed, 07 Apr 1999 01:42:31 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: How do I grab a page on the net using sockets?
Message-Id: <370ABA00.7AF797FF@home.com>
[posted & mailed]
IndexFinger.com wrote:
>
> > How do I grab a page on the net using sockets?
>
> So I don't confuse you about want I'm trying to do, I need to get an html
> file off my partner's site each day. Using the contents of that page, I
> produce an html file on my site. I've seen some perl programs use sockets.
That's one way. You might want to look into LWP as another.
perldoc LWP
> Basically, I need the contents of that page to be pushed in to an array
> where I can look at each line. The hard part is that I don't know how to get
> the contents of the text file in to the array.
That's the easy part. The hard part is reading the docs on LWP so you
can retrieve the page. Once you've done that you should be able to get
the contents into a scalar and then it's just:
@array = split /\n/, $scalar;
Heck, there may be a way to get the contents directly into an array with
an LWP method. I haven't read all the docs on it yet either.
>
> Can someone give me all the code I need?
Someone might, but you'll feel more rewarded if you do some of it
yourself.
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: 06 Apr 1999 18:52:12 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: How do I grab a page on the net using sockets?
Message-Id: <m1hfqt6vub.fsf@halfdome.holdit.com>
>>>>> "IndexFinger" == IndexFinger com <indexfinger@usa.net> writes:
IndexFinger> Can someone give me all the code I need?
use LWP::Simple;
$his_page = get "http://www.his.server.com/his/url/goes/here";
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Tue, 06 Apr 1999 20:46:12 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: Most elegant random string generator?
Message-Id: <alecler-0604992046120001@dialup-362.hip.cam.org>
In article <370A9C02.DD16F793@well.com>, Greg McCann <gregm@well.com> wrote:
> 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!
If you want more elegant, consider this:
my @charlist = (0..9, 'A'..'Z', 'a'..'z');
If you want to avoid hardcoding the argument to rand():
for (1..$numchars) {
$randstr .= $charlist[rand @charlist];
}
HTH,
Andre
------------------------------
Date: Wed, 07 Apr 1999 01:05:35 GMT
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: Most elegant random string generator?
Message-Id: <slrn7gl6en.1ve.dragons@dragons.duesouth.net>
Tue, 06 Apr 1999 16:42:58 -0700 -- Greg McCann <gregm@well.com>:
-> 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!
$ cat > random_letter
#!/usr/bin/perl -w
use strict;
my $max = 20;
my @chars = (0, 0..9, 'A'..'Z', 'a'..'z');
my $str = '';
$str .= $chars[rand @chars] for 1 .. $max;
print "$str\n";
__END__
^D
$ perl ./random_letter
JjUQLgthHBiguzkpkdGX
$ perl ./random_letter
PxElfa0tXCTheUyl3lJ5
$ perl ./random_letter
xwYuhMNOVnH8M3yaf4XZ
$ perl ./random_letter
A34g4DbWGL6XvCbBLd4q
$
So, really, the only major change is getting rid of the large array
initialization...
Hope This Helps!
--Matthew
------------------------------
Date: 6 Apr 1999 18:51:53 -0600
From: hudson@swcp.com (Tramm Hudson)
Subject: Re: Most elegant random string generator?
Message-Id: <7eea79$j56@llama.swcp.com>
[cc'd to cited author and edited]
In article <370A9C02.DD16F793@well.com>, Greg McCann <gregm@well.com> wrote:
>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!
What? Without being too obfuscatory? Isn't that the whole reason
for these sorts of micro-optimizational things? Besides, it all comes
down to how you define elegant...
>(BTW, a simple chr(rand $something + $something_else) does NOT work
>because digits, l.c. alpha, and u.c. alpha are not consecutive in ASCII)
Since this is to be used for generating random session keys, why is
there the requirement that they contain both letters and numbers? How
about just a random number? Magic cookies don't need to be pronouncable
or even sensical.
But enough digression, on to the code.
>#!/usr/local/bin/perl -w
>use strict;
Yeah! A warning flag and using strict. Most excellent choice.
>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
Uh oh -- your C or Pascal upbringing is showing. Big list of
declarations with comments. It is hard to shake what they've
taught you. However, your use of lexical variables is also quite
good (do you know why to use 'my' instead of 'local'?)
>@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');
Definitly check into the range operators. ('A'..'Z') in a list
context is a nice idiom that makes intuitive sense. It also saves
your reader from having to read the entire list to ensure that you
have not skipped any letters.
> for ($i = 0; $i < $number_of_chars; $i++) {
> $random_string .= $charlist[rand 62]
> }
Since you've shown that you have been taught good technique (comments,
warnings, strict, etc) I'll assume that the formatting was due to a
braindead newsreader. Again, however, your procedural background
is poking through -- the C style for loop, while powerful, is overkill
for this application.
Anyway, here is my version of the program:
#!/usr/bin/perl -w
use strict;
my $len = shift || 10;
my @chars = ( 0..9 , 'A'..'Z', 'a'..'z' );
my $key = join '', map { $chars[rand @chars] } (1..$len);
print "$key\n";
__END__
Or is that too obfuscated? Any better ideas Abigail?
Tramm
--
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: Wed, 07 Apr 1999 00:06:47 GMT
From: jdinkler@my-dejanews.com
Subject: need to make http request
Message-Id: <7ee7ij$s7g$1@nnrp1.dejanews.com>
I have to send a http request to a daemon on a server - and would like to do
this in perl. I can request via a browser, but this lacks the ability to
script the responses.
the request would be:
"http://server:port/mqsearchd?MQSearchRequest=MQClientID:n;MQPlace:n,,address,ci
ty,state,zip,,country"
any help would be greatly appreciated.
- jef
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 06 Apr 1999 15:50:34 -0700
From: Janie Chu <jychu@us.oracle.com>
Subject: Newbie to PERL - SUGGESTION NEEDED index file
Message-Id: <370A8FBA.B07536E3@us.oracle.com>
Hi,
I'm new to PERL. I'm working on a web site which gives user the ability
to do query against a file which is created in EXCEL and saved as COMMAS
SEPARATED VALUE file (.csv). The file contains data such as product
name and product version. There is a one to many relationship between
product name and product version. In other words, one product can have
more than one version. What is the best way to handle this so, that my
list of value will not contain duplicate values. Any help you can offer
is greatly appreciated.
Janie
"The statements and opinions expressed here are my own
and do not necessarily represent those of Oracle Corporation"
------------------------------
Date: Wed, 07 Apr 1999 10:14:37 +1000
From: Chris Newman <newman@dynamite.com.au>
Subject: Re: Perl as a first programming language - suitability, good books ?
Message-Id: <370AA36C.A1794D61@dynamite.com.au>
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?
Larry Rosler wrote:
> [Posted and a courtesy copy mailed.]
>
> In article <7ee23c$e6p$1@ultra.sonic.net> on Tue, 6 Apr 1999 15:30:03 -
> 0700, Jeff Kirk <jeff@co.mendocino.ca.us> says...
> > Jonathan <jonathan@meanwhile.freeserve.co.uk> wrote in message
> > news:7edtvp$v10$1@news4.svr.pol.co.uk...
> ...
> > > But most important of all, I was wondering if anyone could recommend a
> > > Perl book aimed at people like my friend ? Something that explains what an
> > > array is, what a sort is, even what an interpreter is ?
> >
> > O'Reilly is the place to go. The Camel book and the Ram book are
> > indespensible.
> > http://perl.oreilly.com/
>
> Gosh, no! Those are fine books for intermediate to advanced
> programmers, but novices would have trouble, to say nothing of
> beginners. (Skiers will grok those categories.)
>
> This person is not far enough along even for the Llama book. There was
> a thread about this recently, and I don't recall anyone proposing a Perl
> book for beginners in programming. Search DejaNews for more.
>
> --
> (Just Another Larry) Rosler
> Hewlett-Packard Company
> http://www.hpl.hp.com/personal/Larry_Rosler/
> lr@hpl.hp.com
------------------------------
Date: Tue, 06 Apr 1999 20:39:03 -0400
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: Jonathan <jonathan@meanwhile.freeserve.co.uk>
Subject: Re: Perl as a first programming language - suitability, good books ?
Message-Id: <370AA927.E42B2415@giss.nasa.gov>
[courtesy copy sent to cited author]
Jonathan wrote:
>
> A friend of mine from an arts background is interested in learning to
> program, partly from intellectual curiousity and partly for career reasons.
<snip>
> Until recently I didn't know what language to
> suggest to her -
<snip>
> I was thinking maybe
> you-know-what, but last week I started to learn Perl.
"you-know-what" meaning, of course, Scheme ;^) _SICP_!
> But most important of all, I was wondering if anyone could recommend a Perl
> book aimed at people like my friend ?
Maybe awk would be an appropriate first language?
The best awk book is free: _Effective_AWK_Programming_
ftp://ftp.cs.columbia.edu/archives/gnu/prep/gawk/
The book assumes basic familiarity with Unix, but
doesn't seem to require any programming experience.
Learning awk would be a solid first step to learning
Perl.
BTW, Perl was my second programming language: I learned
FORTRAN first. My first Perl book was Jon Orwant's
_Perl_5_Interactive_Course_ (first edition, it was riddled
with editorial errors). Waite Group Press sucks, but
Jon wrote a pretty good intro.
However, Randal's _Learning_Perl_ is shorter, cheaper, and
seems to be aimed at the same audience. Both books get
good reviews at amazon.com
Jay Glascoe
------------------------------
Date: Tue, 06 Apr 1999 17:06:17 -0700
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: regexp matching digits
Message-Id: <370AA179.ED26CE52@mail.cor.epa.gov>
frf wrote:
>
> I am hoping someone can give me an elegant way to extract the
> digits from a string. (sfour030299data.log)
>
> I have a list of files that include the date of their creation in the
> filename, and I want to extract that date string from the name.
> All I can come up with is matching everything before the digits, and
> then matching everything after the digits, but it seems lame.
>
> Given $filename = sfour030299data.log
> I'd like to get $filedate = 030299.
>
> Thanks much
Read up on regexes in perlre. There's some neat stuff waiting
for you. For instance, you can match digits with \d and you
can capture with parens. Like this:
($date = $filename) =~ /(\d+)/;
You can learn about the pattern-binding operator =~ in the
perlop section. Since + is greedy, this grabs all the digits.
But regexen match leftmost first. So if you have a filename
like s7four030299data.log this will fail. You'll get a 7 for
your date. If you need to constrain your regex to only match
on strings of, say, four to six digits, write it like this:
($date = $filename) =~ /(\d{4,6})/;
{n,m} is greedy too, so it will match as many digits (up to
6 here) as possible according to the max number in the {} .
David
--
David L. Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Wed, 07 Apr 1999 00:47:05 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: regexp matching digits
Message-Id: <370AAD08.348D8521@home.com>
[posted & mailed]
David L. Cassell wrote:
>
> frf wrote:
> >
> > Given $filename = sfour030299data.log
> > I'd like to get $filedate = 030299.
> >
> > Thanks much
>
> Read up on regexes in perlre. There's some neat stuff waiting
> for you. For instance, you can match digits with \d and you
> can capture with parens. Like this:
>
> ($date = $filename) =~ /(\d+)/;
ITYM
($date) = $filename =~ /(\d+)/;
or maybe
($date = $filename) =~ s/\D//g;
better written as
($date = $filename) =~ tr/0-9//cd;
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: Wed, 7 Apr 1999 11:33:05 +1000
From: "Diggy Tim" <tim@diggy.com>
Subject: Seemingly Simple Regexp problem...
Message-Id: <7eec4r$t2a$1@gnamma.connect.com.au>
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??
Any help will be greatly appreciated.
Cheers,
Tim
--
--
Tim Gunn
tim@diggy.com
_ _ _ _ _ _ _ _ _ _ _
Diggy Internet Services
Lv 2, 132 Albert Street
Brisbane Qld 4000
Ph +61 7 3236 5855
Fax +61 7 3236 5733
http://www.diggy.com.au
------------------------------
Date: Wed, 07 Apr 1999 01:48:37 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Seemingly Simple Regexp problem...
Message-Id: <370ABB75.FBFE0BD9@home.com>
[posted & mailed]
Diggy Tim 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...
In that case you can ignore all the s///g solutions you're about to get.
>
> Is a regexp the best solution??
No.
tr/A-Za-z0-9.@-/_/c;
perldoc -f tr
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: Tue, 6 Apr 1999 16:20:22 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: setting env variables, sourcing, etc.
Message-Id: <6aqde7.bq1.ln@magna.metronet.com>
Tom Kralidis (tom.kralidis@ccrsDotnrcandOtgc.ca) wrote:
: I tried setting an environment
: variable in one of the directories, and when executing the script, I
: received an error message.
But you are not going to share the error message text?
Error messages are designed to help you figure out what is
wrong. You should include them if you want help with
clearing them up.
Did you look up the error message in the perldiag.pod
standard Perl doc?
: I tried this with a simple
: system("cd tables;setenv TABLES $cwd");
: and was not successful.
How do you know that it was not successful?
You never access the TABLES env var in the shell where
you set it (that shell dies when the system() call returns,
taking its environment to the grave with it...)
Try this to see if it was successful:
system("cd tables;setenv TABLES $cwd; echo $TABLES");
: Does anyone know why this won't happen,
Anybody that checks the Perl FAQ before posting to the
Perl newsgroup does.
Perl FAQ, part 8:
"I {changed directory, modified my environment} in a perl script.
How come the change disappeared when I exited the script?
How do I get my changes to be visible?"
comp.lang.perl.misc is not a "look it up in the docs for me" service.
You are expected to try that yourself before posting (you are
expected to do that in all Usenet newsgroups).
[snip excessively long .signature]
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 07 Apr 1999 01:03:06 GMT
From: drgreer@qtiworld.com (Darren Greer)
Subject: Trouble with DBI and Oracle
Message-Id: <370aaea0.84462871@news.qgraph.com>
Sorry for the repost: I had the subject in the wrong field:
Howdy all....I am having problems with DBI and Oracle. Below is my
code, to access our Database, and perform a simple query. Following
the code, is the error I get.
--------------------- CODE ----------------------
#!/usr/bin/perl -w
use DBI;
$ENV{ORACLE_HOME} = '/usr/oracle/7.3.4';
$ENV{TWO_TASK} = 'T:homer:QTI';
my $dbh = DBI->connect('dbi:Oracle:','drgreer/drgreer@QTI','');
$query = "SELECT partnumber FROM partmaster WHERE partno = '108755'";
my $sth = $dbh->prepare($query) || die "Cant execute prepare
statement";
my $rc = $sth->execute || die "Cant execute statment: $DBI::errstr";
print "$sth->{NAME}->[0]\n";
while (@row = $sth->fetchrow_array) {
print "$row[0]\n";
}
$sth->finish;
$dbh->disconnect || warn $sth->errstr;
--------------- END CODE --------------
This is not much of an error, as it is more of a lock-up. This was
run from the debugger, and below, is the point where it locks up. The
debugger never gets past the "connect" line in the code. The
following is where my code locks up, and sites there eating a TON of
cpu. The process eventually has to be killed, to stop it. Any help
or insight would be greatly appreciated.
------------------ ERROR -----------------
DB<1>
DBD::Oracle::dr::connect(/opt/perl5/lib/site_perl/DBD/Oracle.pm:206):
206: DBD::Oracle::db::_login($dbh, $dbname, $user, $auth)
207: or return undef;
DB<1>
---------------------------------------------------
Darren
------------------------------
Date: Tue, 6 Apr 1999 21:08:20 -0400
From: "Henry Campbell" <campbellh@cs.net>
Subject: Re: Trouble with Oraperl, and simple select statement
Message-Id: <7eec0v$k5t$1@ffx2nh5.news.uu.net>
I just started using Oraperl about 3 weeks ago. So I'm not up to speed on
the syntax of the language. From what I see here everything looks find
except.
You want to use this as you environment variables set up.
$ENV{'LD_LIBRARY_PATH'} = $ORACLE_HOME/lib;
$ENV{'ORACLE_HOME'} = $ORACLE_HOME;
**Where $ORACLE_HOME is your oracle install directory
Example:
# Environmental Vars
$ENV{'LD_LIBRARY_PATH'} = '.../oracle/products/8.0.3/lib';
$ENV{'ORACLE_HOME'} = '.../oracle/products/8.0.3/';
Also the SQL statement is questionable, but I'm no SQL guru either. I
suggest you put '|| die $ora_errstr' after every function call. This will
give you a descent error message at the command line as to what is going
wrong. O'yeah you must run this at the command line
not through the web. Else you error messages will be hidden.
Hope this helps,
Henry Campbell
Darren Greer wrote in message <37094222.269464559@news.qgraph.com>...
>Howdy all. I recently install DBD-Oracle-0.60, and DBI-Oracle-1.06,
>and they isntalled fine, and the test.pl file worked fine as well. So
>I wrote this VERY simple perl script to do a simple select statement.
>However, when I run this program it locks up right after running
>&ora_version, at least that is all I see. At that point, it sits
>there sucking a TON of cpu time. This select statement takes less
>than a 1/4 of a second to do from sqlplus, so something is messed up.
>Below is my simple code.
>
>#!/usr/bin/perl
>
>use Oraperl;
>
>&ora_version;
>
>$home = $ENV{'ORACLE_HOME'};
>$sid = $ENV{'ORACLE_SID'};
>$userid = "login";
>$passwd = "password";
>
>$lda = &ora_login($sid,$userid,$passwd) || die $ora_errstr;
>
>$partsearch = "select partno, partdescr from partmaster where partno =
>'108755'";
>
>$csr = &ora_open($lda, $partsearch);
>
>&ora_bind($csr);
>
>$test = &ora_fetch($csr)
>
>&ora_close($csr);
>
>&ora_logoff($lda);
>
>print $test;
>
>
>
------------------------------
Date: Wed, 07 Apr 1999 01:19:29 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: typeglobs and strict....simple qn.
Message-Id: <370AB49A.A3A64CE7@home.com>
[posted & mailed]
bhaskaracharya@my-dejanews.com wrote:
>
> Anyways my qn. is simple:
Your queen is simple? So is mine.
>
> * do typeglobs and strict go hand in hand?
No, but they can co-exist anyway.
Typeglobs are used to refer to all entries in a symbol table with the
name you specify.
So *foo refers to
$foo
@foo
%foo
&foo
foo
etc.
in the current package.
If you use variables that reside in a symbol table, use strict 'vars'
demands that you specify which symbol table. The name of the symbol
table is 'pkg::', where 'pkg' is the name of the package the variables
reside in.
So in your example,
>
> #!/local/perl -w
> use strict;
>
> sub func_from_book {
> local(*c, *d) = @_;
This can be made strict safe by writing it as
local(*main::c, *::d) = @_;
> if (@c > @d) {
And this by writing
if (@::c > @main::d) {
Note that *:: is a short form for *main::.
If you declare your variables as lexical with my then strict won't
complain because lexical variables aren't in any symbol table.
Sometimes you might want to use global or symbol table variables while
use'ing strict without specifying their package every time. If so, you
can declare them with
use vars qw(*c *d);
and then reference them normally, like
local *c;
Now you can go back to reading the docs for more detailed explanations.
perldoc perlmod
perldoc strict
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: Wed, 07 Apr 1999 00:41:39 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Unpack Question
Message-Id: <370AABBB.A570B157@home.com>
[posted & mailed]
David L. Cassell wrote:
>
> David Delikat wrote:
> >
> > first, if there are bits in between, then you have to account
> > for those in your unpack string. every bit of information
> > MUST be accounted for save any trailing info you dont care about.
> >
> > if your data looks like this:
> >
> > 0001100010000111
> >
> > then 'b5 b5 b6' will do fine.
No, it won't. Try it.
$foo = "\x18\x87";# 0001100010000111
@bar = unpack('B5B5B6', $foo);# use B to get high order 1st
print "@bar\n";
gives
00011 10000
Unfortunately pack and unpack byte-align when using b and B. So if you
want a bit string of 5 characters, unpack will pull 8 bits and give you
the first 5 (or last 5 if using b).
> >
> > but if it looks like this:
> >
> > 00011XX00010X000111
> >
> > then you need 'b5 b2 b5 b1 b6' and then ignore the
>
> Or 'b5 x2 b5 x1 b6' to skip over those guys.
Even if (un)?pack's behaviour is corrected at some time in the future,
this will still not work since x means to skip a *byte*, not a bit.
One possible solution would be
@bar = unpack('A5A5A6', unpack('B16', $foo));
It's about this time that Steffen Beyer usually steps in touting
Bit::Vector. I've not used it but I hear it's good.
--
Rick Delaney
rick.delaney@home.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 5315
**************************************