[6892] in Perl-Users-Digest
Perl-Users Digest, Issue: 518 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 22 22:07:15 1997
Date: Thu, 22 May 97 19:02:30 -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 Thu, 22 May 1997 Volume: 8 Number: 518
Today's topics:
Re: Randal Schwartz (Michael Lauzon)
Re: Random number generator <david.s.patterson@boeing.com>
Re: RCS-style version mgmt implementation in Perl? (Abigail)
Re: REGEXP Help Needed <karlv@wayback.er.usgs.gov>
Re: REGEXP Help Needed <usenet-tag@qz.little-neck.ny.us>
Re: Split function <djohnson@uu.net>
Re: split'\|'; except when preceded by '/' (Tad McClellan)
Re: storing the output of commands to perl variables . (Chipmunk)
The perl way? What is it really? (Niklas Paulsson)
Re: The perl way? What is it really? <rra@stanford.edu>
Re: The perl way? What is it really? (Ilya Zakharevich)
Re: Time stamping with perl <karlv@wayback.er.usgs.gov>
US FL Jacksonville 904 Perl, SQL, Unix, HTML, Internet internet@nettrust.com
Re: What do you do in place of 'case' or 'switch' (Zach Baker)
Why doesn't this simple script work? <skip@tecelite.com>
Re: yyyymmdd from localtime? (John L. Allen)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 22 May 1997 21:21:43 GMT
From: ce940@torfree.net (Michael Lauzon)
Subject: Re: Randal Schwartz
Message-Id: <EALq07.ABA.0.bloor@torfree.net>
I put Randal's name down, so I could get him to email me...I would post
my code to this NG if the freenet I use for my emaill acoount; if the
would update their version of Pine. So, I can't hit [alt] whatever to
bring up the newsgroup thing through pine. I have to get shell access
first...and so far I am looking for a ISP that has it.
Tung-chiang Yang (tcyang@netcom.com) wrote:
: Hmmm, it seems the analogy from "Intel Inside" is not a good idea.
: I apologize for what I did to Randal.
: ==================================
: Paddy Spencer (paddy.spencer@parallax.co.uk) wrote:
: : : He wanted to put the label "Randal Inside" on his script :)
: : ^^^^^^^^^^^^^
: : Given that Randal has
: : at the end of his post, I'm not sure he'll approve of the concept...
: --
: Tung-chiang Yang tcyang@netcom.com
: soc.culture.taiwan, soc.culture.china (by SCC FAQ Team) FAQ's:
: http://www.clever.net/tcyang/Taiwan_faq.shtml, China_faq.shtml
--
Michael
Free email address: http://www.hotmail.com/
'Eat, drink, and be merry, for tomorrow you may work.'
------------------------------
Date: Thu, 22 May 1997 20:45:57 GMT
From: "David S. Patterson" <david.s.patterson@boeing.com>
To: Simon Pearce <simon@scoutnet.org.uk>
Subject: Re: Random number generator
Message-Id: <3384B085.41C6@boeing.com>
Simon Pearce wrote:
>
> Hi all,
>
> I'm after a snippet of code that will produce a random number between
> 1 and 49 (yes for a lottery number generator).
>
> Any ideas?
>
> Simon Pearce
> simonp@dircon.co.uk
Simon,
As it happens, I found something in my
toybox you might be able to (ab)use...
It is designed for use from a unix shell...
#!/bin/perl
##
## rand by David S. Patterson Ver 1.0 07 Feb 97
##
## NAME
## rand - Generates a random integer between 0 and numerical
argument.
##
## SYNTAX
## rand NNN
##
## DESCRIPTION
## Works for values of NNN in the range 2 - 1000000.
## Generates a seed file ("seed.rand") in $HOME/tmp.
##
if (! @ARGV || $ARGV[0] =~ /^\-[\?hH]/)
{
system ("cat $0 | grep \"^##\"");
exit (-1);
}
$TMP = "$ENV{HOME}/tmp";
if (! -d $TMP)
{
`mkdir $TMP`;
}
$SEEDFILE = "$TMP/seed.rand";
if (-f $SEEDFILE)
{
$COMMAND = "cat $SEEDFILE";
$SEED = `$COMMAND`;
$SEED = ($SEED + time) % 1428571; ## (prime number)
}
else
{
$SEED = time % 1428571;
}
$ANS = rand ($SEED) % $ARGV[0];
$SEED += $ANS;
system ("echo $SEED >$SEEDFILE");
print "$ANS\n";
--
"What could possibly go wrong?..."
David S. Patterson, Sr. Software Engineer
Production Illustration Systems (206) 865-3176
david.s.patterson@boeing.com Mail Stop: 7J80
------------------------------
Date: Thu, 22 May 1997 20:32:42 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: RCS-style version mgmt implementation in Perl?
Message-Id: <EALnqI.C8K@nonexistent.com>
On 22 May 1997 00:13:14 -0400, Paul D. Smith (psmith@baynetworks.com) wrote
in comp.lang.perl.misc
<URL: news:p5enb0nnz9.fsf@baynetworks.com>:
++ Uh, I think it'd probably be faster and easier to port RCS itself to the
++ Mac. Heck, maybe someone's already done it (try asking on
++ gnu.utils.bug).
++
++ Aside from a working diff there's nothing in RCS that's very
++ system-dependent. If it works on DOS (and it does) it could surely work
++ on Macs.
The O'Reilly book about RCS ("Applying RCS and SCCS" by Bolinger &
Bronson) mentions ports to DOS, Windows/NT and OS/2, but I can't
find a reference to Mac.
Abigail
------------------------------
Date: Thu, 22 May 1997 15:46:11 -0500
From: Karl Vietmeier <karlv@wayback.er.usgs.gov>
Subject: Re: REGEXP Help Needed
Message-Id: <3384B093.2307@wayback.er.usgs.gov>
Richard Kennedy wrote:
>
> The following regexp attempts to check for a valid e-mail address:
>
> if ($in{'from'} !~ m/^[^\s\n@]+\@(([a-z0-9][a-z0-9-]*[a-z0-9]\.)+[a-z]{2,3}|\
> [(\d{1,3}\.){3}\d{1,3}\])$/) {
> # If the E-mail address is wrong, return an error message
> .
> .
> .
>
> However, it incorrectly rejects the following valid e-mail address:
>
> student@u.washington.edu
>
> Any suggestions for correcting the above problem will be appreciated!
>
> Richard_Kennedy@ci.des-moines.wa.us
This is actually a deceptively difficult task. In the book "Mastering
Regular Expressions" the author developed a 6500 byte long regexp to do
the job! You can take a look at his code at the following url:
http://enterprise.ic.gc.ca/~jfriedl/regex/code.html
Good luck :)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Karl S. Vietmeier karlv@wayback.er.usgs.gov
Web Development
USGS Center For Coastal Geology voice: (813)-893-3100 x3081
Saint Petersburg, Forida fax : (813)-893-3333
------------------------------
Date: 22 May 1997 22:35:07 GMT
From: Eli the Bearded <usenet-tag@qz.little-neck.ny.us>
Subject: Re: REGEXP Help Needed
Message-Id: <5m2hmr$flj$1@news.netusa.net>
Karl Vietmeier <karlv@wayback.er.usgs.gov> wrote:
>Richard Kennedy wrote:
>> The following regexp attempts to check for a valid e-mail address:
<snort>
>> if ($in{'from'} !~ m/^[^\s\n@]+\@(([a-z0-9][a-z0-9-]*[a-z0-9]\.)+[a-z]{2,3}|\
>> [(\d{1,3}\.){3}\d{1,3}\])$/) {
What about ! paths? What about Perfectly legal addresses like
<eli (Pogonatus (latin for <the bearded>))@ (qz (pronounced (queasy) ) \
.little-neck (I did not want that, but RFC1480 required it) .ny (New \
F%@!: York) .us (USA) or ) netusa (Located on Long Island) . net> (Elijah)
<"eli at qz"@qz.little-neck.ny.us>
<eli@[204.141.25]>
All of those get delivered to me and will be accepted by the mail
server I use (204.141.0.25: droping the zero low end quad is obscure
but legal). And that neglects also the valid TLDs of .arpa and .firm.
>> Any suggestions for correcting the above problem will be appreciated!
The correct the pattern matching problem you have there, change this:
m/^[^\s\n@]+\@(([a-z0-9][a-z0-9-]*[a-z0-9]\.)+[a-z]{2,3}|\
to this:
m/^[^\s\n@]+\@(([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,3}|\
But don't pretend you are validating an address.
>This is actually a deceptively difficult task. In the book "Mastering
>Regular Expressions" the author developed a 6500 byte long regexp to do
>the job! You can take a look at his code at the following url:
>http://enterprise.ic.gc.ca/~jfriedl/regex/code.html
You neglect to mention that Friedl conceeds it will not match all
legitimate addresses, just most. My first example will break it.
(That one breaks *everything* but MTAs. :^)
Elijah
------
has spent considerable hours pouring over rfc 822 bnf
------------------------------
Date: Thu, 22 May 1997 14:43:56 -0500
From: Dale Johnson <djohnson@uu.net>
Subject: Re: Split function
Message-Id: <3384A1FC.15FB7483@uu.net>
> Greg,
>
> If you are looking to split a line that might have delimiters of
> colon(:),
> slash(/), or by whitespace(/s), then you might want to use this:
>
> @array = split(/[:|\\|\s]/, $string);
>
> If you want to split by a single one of those, then you would use:
>
> @array = split(/XX/, $string);
>
> where XX is a ":", a "\s" or "\\".
>
> Good luck.
>
Oops. Found a typo. Thought you were looking for a backslash, not a
forward slash. For the forward, substitute a "\/" for the "\\".
Sorry! :)
--
Dale R. Johnson, Jr. <djohnson@uu.net> http://www.drsj.com/drj/
PGP Key fingerprint = D5 2D F7 96 E5 69 3A A3 F5 00 A8 FC EF 35 41 54
perl -e 'foreach(`finger johnson\@doit.net`){$a=1if/^-/;print if$a};'
-=-=- If at first you don't succeed, skydiving is not for you. -=-=-
------------------------------
Date: Thu, 22 May 1997 17:02:02 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: split'\|'; except when preceded by '/'
Message-Id: <qof2m5.vo8.ln@localhost>
Dan Boorstein (danboo@ixl.com) wrote:
: Here is the problem.
: A string with: no linefeeds
: fields separated by |
: nested |'s are escaped with \ (i.e., \|)
: I want to split this string on unescaped |'s, removing
: the \'s preceding the escaped |'s. I thought this would
: be a 2 line split-regex block, but has turned into
: something much less elegant which I pieced together
: from various FAQ's and Dejanews articles. Behold:
^^^^^^^^^^^^^^^^^
Ahh, but you missed one ;-)
You basically need "look-behind" instead of look-ahead. Alas,
look-behind is not available.
I remember this being discussed on c.l.p.m recently (regular
readership helps yet again), and sure enough a Dejanews search
for "look-behind" found:
Subject: Poor man's look-behind
Posted by Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Which led me to write:
--------------------------
#! /usr/bin/perl -w
$_ = '\||split|me|\|<no split|1\|=\|1|3|';
foreach $field ( split /\|(?!\\)/, reverse $_) { # '|' not followed by '/'
($field = reverse $field) =~ s/\\//g;
unshift(@fields, $field);
}
foreach (@fields) {print "'$_',"}
print "\n";
--------------------------
To get look-behind, reverse the string and use look-ahead. Too cool!
[ snip current code ]
: After execution @fields contains (as expected):
: ('|','split','me','|<no split','1|=|1','3','')
: It does everything I wanted it to do, but not as cleanly as I'd
: hoped. Any ideas on how to clean up this process (not necessarily
: my coding style)?
: Thanks,
You're welcome.
Thanks to Andrew too ;-)
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: 22 May 1997 19:28:32 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: storing the output of commands to perl variables ..... NT specific
Message-Id: <5m26p0$6kj$1@dartvax.dartmouth.edu>
In article <33837F63.78B9@peakaccess.net>
lji@peakaccess.net writes:
> Hello - is there a straight-forward way of storing the
> output of a sub-command into perl variable (a way that works
> accross platforms - even NT). I'm looking for the
> equivalent of the following in korn shell
> VAR="$(cmd line)"
>
> I would like to avoid using system(" ") to dump to
> a file, and then reading in the file ....
Have you tried $var = `cmd line`?
Chipmunk
------------------------------
Date: 22 May 1997 21:02:20 +0200
From: niklas@grok.adb.gu.se (Niklas Paulsson)
Subject: The perl way? What is it really?
Message-Id: <5m257s$mbi@grok.adb.gu.se>
Hi there fellow perlers,
I have been a sysadmin for some time now, and regualary using all the
"usuasl" tools, such as sed, awk, C, etc
Some time ago I finally took the step towards learning perl.
My first impression was "What a sick and perverted brain has put
together this pile of mud?", but I keept hacking, and slowly, more and
more I began to like perl more and more.
When I finally read the book "mastering regular expresions" I feel in
love with perl. Today I use perl for a wide variety of tasks in my
everyday job, and most of all I think it is great fun hacking in perl.
I think it is mostly quite easy to tell if a person "thinks in C" or
if he "thinks in awk" (or whatever) when i see some examples in perl.
I remember some programing course at the university when my lecturer
said something like "break and countinue statements are only to use
for those who are incapable of writing down a correct iteration
condition", somehow I get the impression that perl-people aren't to
picky about those things....
But people keep refering to "the perl way of doing things", and I
really wonder what is "the perl way of doing things"...
See you around....
--
Niklas Paulsson
System Administrator at Dept. of Informatics, Gvteborgs University
niklas@adb.gu.se
------------------------------
Date: 22 May 1997 12:51:59 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: The perl way? What is it really?
Message-Id: <m3lo57xp28.fsf@windlord.Stanford.EDU>
Niklas Paulsson <niklas@grok.adb.gu.se> writes:
> I remember some programing course at the university when my lecturer
> said something like "break and countinue statements are only to use for
> those who are incapable of writing down a correct iteration condition",
> somehow I get the impression that perl-people aren't to picky about
> those things....
Right. Those are also the sorts of people who say that you should never,
ever use a goto. While out in the real world, people discover that gotos
are by far the best way of implementing something that looks like a finite
state machine.
> But people keep refering to "the perl way of doing things", and I really
> wonder what is "the perl way of doing things"...
The Perl way is the intuitive way. In other words, when I'm coding in
Perl, I write the program the way it makes the most sense to me to read.
So I regularly make use of constructs like:
open (DATA, "datafile") or die "$0: unable to open file: $!\n";
because that's what I'm thinking (open the file or die with an error
message). Similarly:
print "Now checking data...." if $verbose;
(print out this status message if we're being verbose). Perl lets me,
more than any other language, forget about the structure of the language
and just write down code in an order that's natural for me. This is the
reason why, as you mentioned, it's so easy to determine what a person's
"base" programming language paradigm is when you read their Perl code,
since their Perl code will look like C, awk, Lisp, or shell.
Therein lies the strength of Perl; it can cope with all of those paradigms
easily.
--
Russ Allbery (rra@stanford.edu) <URL:http://www.eyrie.org/~eagle/>
------------------------------
Date: 22 May 1997 20:19:40 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: The perl way? What is it really?
Message-Id: <5m29os$iil$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Russ Allbery
<rra@stanford.edu>],
who wrote in article <m3lo57xp28.fsf@windlord.Stanford.EDU>:
> Right. Those are also the sorts of people who say that you should never,
> ever use a goto. While out in the real world, people discover that gotos
> are by far the best way of implementing something that looks like a finite
> state machine.
Not in Perl. Never ever use goto in perl. If you want to know why,
look in the source of pp_goto (Approximate answer: it open connection
to your news server, and looks through ALL the groups looking for
an article with body matching your label best, then proceeds basing on
the subject of this article).
Ilya
------------------------------
Date: Thu, 22 May 1997 15:32:25 -0500
From: Karl Vietmeier <karlv@wayback.er.usgs.gov>
Subject: Re: Time stamping with perl
Message-Id: <3384AD59.780B@wayback.er.usgs.gov>
Raul Almquist wrote:
> ($sec, $min, $hour, $day, $mon, $yr, $wday, $yday, $isdst) = localtime (time);
> $month = ($mon + 1);
> $year = ($yr + 1900);
> $time = sprintf ("%02d:%02d:%02d", $hour, $min, $sec);
> $date = sprintf ("19%02d-%02d-%02d", $year, $month, $day);
>
> then just put in $date and $time where ever you need to do the time stamping.
>
> enjoy
What about using perls ctime.pl library?
require "ctime.pl";
$date = &ctime(time);
Works great, less lines too :)
------------------------------
Date: Thu, 22 May 1997 15:21:40 -0600
From: internet@nettrust.com
Subject: US FL Jacksonville 904 Perl, SQL, Unix, HTML, Internet Dev
Message-Id: <864331856.82@dejanews.com>
Subject: US FL Jacksonville 904 Perl, SQL, Unix, HTML, Internet Dev
Management openings also. Internet Commerce, Finance background a plus.
> > Web database applications. Heavy PERL, Database, some CGI experience
> > required.
> >
> > Solaris/Informix/Java a plus.
> >
> > 1-3 persons needed.
> >
> > Major corporation/benefits.
> >
> > Email resume + salary requirements
keywords: florida fl jax jacksonville 904 perl unix sql database informix
sql html java apache ssl cgi servlet jdbc mgmt management manager
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: 22 May 1997 21:19:57 GMT
From: zbaker@venom.st.hmc.edu (Zach Baker)
Subject: Re: What do you do in place of 'case' or 'switch'
Message-Id: <5m2d9t$2e1$1@cinenews.claremont.edu>
In article <33838D4C.4E9A@roguewave.com>,
Steve Moody <moody@roguewave.com> wrote:
>What I am needing to do is to parse out a series of command
>line options, and based on their value enact a specific routine
>within my program. In C this was handled nicely with "switch"
>statements in ksh with "case" statements.
You know, I think a hash might help you do this quite easily. And if
you're OK with iterating over the keys manually you can even evaluate
regular expressions or anonymous subroutines to determine whether to
perform the action in the value.
Just another mind-bending way-to-do-it. Hope this helps.
---
Zach Baker <zbaker@venom.st.hmc.edu>
"The good news is these games kick butt. The bad news is you're the butt."
------------------------------
Date: 22 May 1997 17:56:31 -0400
From: Skip Koppenhaver <skip@tecelite.com>
Subject: Why doesn't this simple script work?
Message-Id: <t59117dvcg.fsf@solo.tecelite.com>
I'm a perl newbie and I can't figure out why this simple script won't do
what I want it to. It's supposed to squeeze multiple blank lines into one
blank line. If there's a better way of doing this, please tell me. But I'd
also like to know why this script doesn't work. Thanks.
BTW, I'm using perl 5.003 on Solaris 2.5
#!/usr/local/bin/perl
while (<>) {
# Squeeze multiple blank lines into one
if ($_ eq "\n" && $prevLine eq "\n") {
next;
}
$prevLine = $_;
print;
}
Please email me the answer since I don't usually read this newsgroup.
--
Skip Koppenhaver WEB: http://brute.tecelite.com/~skip/
Technically Elite, Inc. EMAIL: skip@tecelite.com
------------------------------
Date: 22 May 1997 17:16:11 -0400
From: allen@gateway.grumman.com (John L. Allen)
Subject: Re: yyyymmdd from localtime?
Message-Id: <5m2d2r$rud@gateway.grumman.com>
In article <EALH1z.9LK@nonexistent.com>, Abigail <abigail@fnx.com> wrote:
>On 22 May 1997 15:13:23 GMT, felix k sheng (felix@chance.em.nytimes.com)
>wrote in comp.lang.perl.misc
><URL: news:slrn5o8ove.bfc.felix@chance.em.nytimes.com>:
>++ On 22 May 1997 14:51:47 GMT, felix k sheng <felix@chance.em.nytimes.com>
>++ wrote:
>++ >On Wed, 21 May 1997 16:32:38 -0400, Vincent Kargatis
>++ ><kargatis@jackaldog.gsfc.nasa.gov> wrote:
>++ >>I want to get a YYYYMMDD from localtime. [chomp]
>++ here's another shorter and even uglier version!
>++ sprintf( "19%02d%02d%02d", map { $_+=1-($x^=1) } (localtime)[5,4,3] );
>
>That fails on Jan 1, 2000 and any date beyond.
>
>perl -wlMDate::Format -e 'print time2str "%Y%m%e", time;'
>
>And guess what? It's even shorter....
And if you haven't installed Date::Format, this'll do
perl -wlMPOSIX=strftime -e 'print strftime "%Y%m%e", localtime time'
John.
------------------------------
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 518
*************************************