[10240] in Perl-Users-Digest
Perl-Users Digest, Issue: 3833 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Sep 26 20:07:19 1998
Date: Sat, 26 Sep 98 17:00:19 -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 Sat, 26 Sep 1998 Volume: 8 Number: 3833
Today's topics:
Re: Anyone have a set of Coding Standards? <gellyfish@gellyfish.btinternet.com>
Re: FS Check <gellyfish@gellyfish.btinternet.com>
Re: how to code: iterate through x statements but stop <merlyn@stonehenge.com>
Re: How to log click-thru's for URL's <merlyn@stonehenge.com>
How to read contents of all *.TXT files in directory in <flanker@sonnet.ru>
Re: How to read contents of all *.TXT files in director (Matthew Bafford)
Re: How to read contents of all *.TXT files in director (Matthew Bafford)
Re: How to strip binary data from a file <gellyfish@gellyfish.btinternet.com>
Re: Internal Server Error (Premature end of script head <samwang@freewwweb.com>
Re: Looking for System Admin <gellyfish@gellyfish.btinternet.com>
Re: M/// problem again... (Tad McClellan)
Multiple perlscripts editing same file (Hampus Brynolf)
Re: Multiple perlscripts editing same file <jdf@pobox.com>
Re: Need help with a simple program (newbie). <gellyfish@gellyfish.btinternet.com>
Re: newbie Perl Program help (Patrick Timmins)
Non-blocking I/O <jim@123stitch.com>
Perl inconsistency? <ff@creative.net>
Re: perl tutorial <gellyfish@gellyfish.btinternet.com>
Re: Perl version compatability <gellyfish@gellyfish.btinternet.com>
Porting Unix perl script to winNT servers (Belle)
Re: removing a-z from a string. Sorry, I forgot the [ ] <jim@siteplus.com>
removing a-z from a string. <jim@siteplus.com>
Re: removing a-z from a string. (Matthew Bafford)
Re: retaining user id <rra@stanford.edu>
Re: Returning a "near" hash key. (Tim Gim Yee)
Re: Running apps. list through Perl? <gellyfish@btinternet.com>
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 26 Sep 1998 20:02:45 -0000
From: Jonathan Stowe <gellyfish@gellyfish.btinternet.com>
Subject: Re: Anyone have a set of Coding Standards?
Message-Id: <6ujh95$46f$1@gellyfish.btinternet.com>
On 25 Sep 1998 16:06:26 -0600 Nathan Torkington <gnat@frii.com> wrote:
> lemull@unx.sas.com (Lee Mulleady) writes:
>> Can anyone point me to a set of Coding Standards developed
>> specifically for Perl?
> We get these questions once or twice a month. Surely *someone* has
> prepared, either for their own use or for their company/department's
> use, a set of coding standards?
> Everyone answers with "man perlstyle", I know, but this isn't what the
> people asking the questions want to hear. I'd like to collect a
> couple of sets of standards, regardless of how formal.
> Anyone ready to volunteer their company's?
Unfortunately the only one we have is for COBOL ;-} After that everything
just sort of takes off - we've got COBOL programmers learning to use VB
and possibly I'll persuade them Perl so I'm sure they'll draw up some
coding standard ;-}
/J\
--
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: 26 Sep 1998 19:22:39 -0000
From: Jonathan Stowe <gellyfish@gellyfish.btinternet.com>
Subject: Re: FS Check
Message-Id: <6ujetv$44q$1@gellyfish.btinternet.com>
On Fri, 25 Sep 1998 11:32:04 +0200 Patrick <pgh@ga.nl> wrote:
> Hi,
> Does someone have a example of a script to check a FS.
> What is should do is:
> Check a FS and when it's > 80%, post a mail, write a message on screen
> or create an pop-up screen.
A while back I hacked together something like this in response to a
similar question:
#!/usr/bin/perl
open(DF,"/bin/df -k |") || die "Cant execute df - ";
while(<DF>)
{
next if (/mounted/i);
my ($filesystem,$blocks,$used,$avail,$capacity,$mountpoint) = split(' ',$_);
$capacity =~ s/%//g; # my df puts a percent sign after capacity
$left = 100 - $capacity;
$avail = sprintf("%d.2",$avail / 1024) ;
print "The filesystem $filesystem mounted on $mountpoint ";
print "has $avail MB free ($left % remaining)\n";
}
close(DF) || die "Error in df";
__END__
You can check the value of left and respond as appropriate.
You may need to change the way that the output from 'df' is split.
/J\
--
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: Sat, 26 Sep 1998 22:28:49 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: how to code: iterate through x statements but stop if condition is true
Message-Id: <8c7lyqld9b.fsf@gadget.cscaper.com>
>>>>> "vicuna" == vicuna <vicuna@my-dejanews.com> writes:
vicuna> try_one();
vicuna> if (!success) {
vicuna> try_two(); {
vicuna> if (!success) {
vicuna> try_three();
vicuna> if (!success) {nothing_worked()}
vicuna> }
vicuna> }
Two ways I've used commonly (presuming the "tries" return true for success):
{
try_one() and last;
try_two() and last;
try_three() and last;
nothing_worked();
}
or perhaps:
try_one() or try_two() or try_three() or nothing_worked();
--
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: Sat, 26 Sep 1998 22:31:22 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: How to log click-thru's for URL's
Message-Id: <8c3e9eld52.fsf@gadget.cscaper.com>
>>>>> "Arvo" == Arvo Huru <ah@barentsnett.no> writes:
Arvo> How do I do the folowing :
Arvo> log how many times a link on my site referring to an outside page has
Arvo> been clicked in an database...
Arvo> The method I think i have to use is the one that each link is prosessed
Arvo> thru an cgi.
Arvo> Lats say the link will be looking like this :
Arvo> ..../cgi-bin/track.cgi?http://www.site.com/page/
Arvo> I'll be greatfull for any help I can get.
Then you'll be really "greatfull" [sic :-] to find out that this topic
and many more have been written up at
<URL:http://www.stonehenge.com/merlyn/WebTechniques/>. In particular,
you'll want the one that says "where did they go?".
--
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: Sun, 27 Sep 1998 03:31:30 +0100
From: "Michael Yevdokimov" <flanker@sonnet.ru>
Subject: How to read contents of all *.TXT files in directory into one file?
Message-Id: <6ujt33$lsc$1@bison.rosnet.ru>
Hi
How to read contents of all *.TXT files in directory into one file using
Perl?
--
Yours sincerely,
Michael Yevdokimov (flanker@sonnet.ru)
----------------------------------------------------------------------
The Basic Network
(Developers Support Site)
http://www.basicnet.sonnet.ru
quests@basicnet.sonnet.ru
----------------------------------------------------------------------
------------------------------
Date: Sat, 26 Sep 1998 19:49:46 -0400
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: How to read contents of all *.TXT files in directory into one file?
Message-Id: <MPG.107747a6438dd89d9896bb@news.south-carolina.net>
In article <6ujt33$lsc$1@bison.rosnet.ru> on Sun, 27 Sep 1998
03:31:30 +0100, Michael Yevdokimov (flanker@sonnet.ru) pounded in
the following text:
=> Hi
=>
=> How to read contents of all *.TXT files in directory into one file using
=> Perl?
Let's see to get the contents of all the files, you could use:
#!/usr/bin/perl -w
unshift @ARGV, glob('*.txt');
while ( <> ) {
# Do whatever
}
__END__
or:
#!/usr/bin/perl -w
foreach( glob('*.txt') ) {
open FILE, $_ or die "Can't open $_ :: $! ::";
while ( <FILE> ) {
# Do whatever
}
close FILE or die "Unable to close $_ :: $! ::";
}
__END__
or:
#!/usr/bin/perl -w
opendir DIR, '.' or die "Can't opendir! :: $! ::";
foreach ( grep /\.pl$/i, readdir DIR ) {
open FILE, $_ or die "Can't open $_ :: $! ::";
while ( <FILE> ) {
# Do whatever
}
close FILE or die "Can't close $_ :: $! ::";
}
closedir DIR or die "Can't closedir! :: $! ::";
__END__
Or to just join all of the text files into one file, try:
perl -pe '' *.txt > all_in_one.txt
=> Yours sincerely,
Hope This Helped!
=> Michael Yevdokimov (flanker@sonnet.ru)
--Matthew
!TMTOWTDI!
------------------------------
Date: Sat, 26 Sep 1998 19:52:29 -0400
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: How to read contents of all *.TXT files in directory into one file?
Message-Id: <MPG.1077484ad5a07df69896bc@news.south-carolina.net>
In article <MPG.107747a6438dd89d9896bb@news.south-carolina.net>
on Sat, 26 Sep 1998 19:49:46 -0400, Matthew Bafford
(dragons@scescape.net) pounded in the following text:
=> foreach ( grep /\.pl$/i, readdir DIR ) {
s/pl/txt/;
:)
--Matthew
------------------------------
Date: 26 Sep 1998 20:51:56 -0000
From: Jonathan Stowe <gellyfish@gellyfish.btinternet.com>
Subject: Re: How to strip binary data from a file
Message-Id: <6ujk5c$4e2$1@gellyfish.btinternet.com>
On Fri, 25 Sep 1998 13:18:26 -0700 Larry Rosler <lr@hpl.hp.com> wrote:
> [Posted to comp.lang.perl.misc and a copy mailed.]
[Posted to comp.lang.perl.misc and something else mailed.]
> In article <360be9ed.3523045@news.wirehub.nl> on Fri, 25 Sep 1998
> 19:09:50 GMT, SKa <stefank@wirehub.nl> says...
> ...
>> Can anybody tell me how to remove (or ignore) lines of binary data
>> from a file? I am reading the file line by line, but when the program
>> encounters some binary data, it stops.
> perlfaq4: "How do I handle binary data correctly?"
> You must be using a Windows/DOS system, which has the unfortunate
> characteristic of distinguishing 'binary' data from 'text' data. There
> must be a control-Z character in your data that is interrupting the
> 'read'.
> To fix this, see `perldoc -f binmode`. Then the reads will continue, and
> you can deal with lines you don't like any way you wish.
> How many times has this been this week???
But isnt he asking how to do the equivalent of "strings" in unix with Perl ?
I've been pissing around with a couple of REs to do this but all that is
required is to find an expression that will remove all non-alphanumeric
stuff from the input.
Of course you will have to binmode your input but the whole thing amounts
to some thing like:
$input =~ s/[^\s\w]//g;
(Actually that doesnt work right but can see where this is going )
/J\
--
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: Sat, 26 Sep 1998 16:52:52 -0500
From: Sam Wang <samwang@freewwweb.com>
Subject: Re: Internal Server Error (Premature end of script headers)
Message-Id: <360D6233.95D1FF07@freewwweb.com>
try removing the shebang line. i've had problems before with the shebang line on an
NT box.
------------------------------
Date: 26 Sep 1998 19:52:45 -0000
From: Jonathan Stowe <gellyfish@gellyfish.btinternet.com>
Subject: Re: Looking for System Admin
Message-Id: <6ujgmd$460$1@gellyfish.btinternet.com>
On Fri, 25 Sep 1998 16:19:25 GMT coolbrown@my-dejanews.com wrote:
> San Francisco Bay Area California
> Job Summary :
> Paralogic Software Corporation, the leader in Java based internet chat
> solutions, is
> seeking a UNIX System Manager for its network of chat and web servers.
:1,$!grep [Pp]erl
Newsgroups: comp.lang.perl.misc
Hmm
/J\
--
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: Sat, 26 Sep 1998 16:20:33 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: M/// problem again...
Message-Id: <1rlju6.u58.ln@flash.net>
Hampus Brynolf (hampus@globetree.org) wrote:
: (Re-sent due to unreadability...)
: I have a little problem with m/// (I think)
: My routine opens a file, read the content, search for a match, changes
: one variable and writes it back
: $filen contains the entire file (one line). The content looks like
: this:
: $star,$starpic,$starpicnr,$description;$star,$starpic,$starpicnr,$description;$star,$starpic,$starpicnr,$description;
: ex.
: my_star,1,4,this is my star; my_star_two,3,3,this is also my
: star;blue_star,3,5,this is a blue star;
: Now - what i want to do is the following:
: search the string (the file) for the correct $star, read the
: $starpicnr, increase the number with 1 and then write it back.
: $filen=~m/$star,$starpic,(.*),(.*);/;
^^ ^^
These are greedy. They want to match a lot of characters.
Even _past_ a comma or semicolon.
I don't think you want to allow that, do you?
: Ok. Now - the problem: everything works just fine BUT the
: rest of the entries in the file disappear. Let4s say I find a match:
: "my_star_two", read the starpic to 3, increase the number, and then
: write it all back. Then "blue_star" and all entries after that one
: dissappear. It will look like this:
: my_star,1,4,this is my star; my_star_two,3,4,this is also my star;
: So - how can I just make my change without loosing the rest of the
: file?
$filen =~ s/($star,$starpic,)([^,]+),/ $1 . ($2+1) . ","/e;
I don't like to match and then try and substitute the same thing
I matched. It is prone to error.
I prefer to do it all within a single s///.
(If it was up to me to do, I wouldn't try to do it directly with
a regex. I'd split(/;/) "records", and split(/,/) "fields", and
operate only on the field of interest
)
: What do I do wrong?
Too loose of a regex.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 26 Sep 1998 22:45:09 GMT
From: hampus@globetree.org (Hampus Brynolf)
Subject: Multiple perlscripts editing same file
Message-Id: <360d6d14.42948216@192.168.0.1>
Hi!
I have one question that might interest You all...
I have a couple of perlscripts that all are writing/editing the same
file. Which is the safest way to do this? I do not know when or what
script is doing it. There might be hundreds of clients trying to open
and write to the same file at the same time.
Should I just make a loop that is waiting until it's possible to open
the file for writing? Another idea I have is to write all changes to a
unique file, then have another script in the background that opens
thoose files (i.e name in seconds since year 1900 or something) and
makes the changes to the file.
Anyone got an idea?
/Hampus
hampus@globetree.org
------------------------------
Date: 27 Sep 1998 01:13:59 +0200
From: Jonathan Feinberg <jdf@pobox.com>
To: hampus@globetree.org (Hampus Brynolf)
Subject: Re: Multiple perlscripts editing same file
Message-Id: <m3n27mbh6w.fsf@joshua.panix.com>
hampus@globetree.org (Hampus Brynolf) writes:
> I have a couple of perlscripts that all are writing/editing the same
> file. Which is the safest way to do this?
Start with the sample code given in the documentation for flock() in
perlfunc, then perhaps browse the hundreds of messages posted here on
that topic by querying DejaNews.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: 26 Sep 1998 21:31:08 -0000
From: Jonathan Stowe <gellyfish@gellyfish.btinternet.com>
Subject: Re: Need help with a simple program (newbie).
Message-Id: <6ujmes$4fq$1@gellyfish.btinternet.com>
On Wed, 23 Sep 1998 12:00:22 -0500 Rich Grise <richgrise@entheosengineering.com> wrote:
> I HATE this netscrape snooze!
> "More included text than new text", indeed!
Yeah but that is the way of a responsible News Client isnt it ?
/J\
--
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: Sat, 26 Sep 1998 21:28:28 GMT
From: ptimmins@netserv.unmc.edu (Patrick Timmins)
Subject: Re: newbie Perl Program help
Message-Id: <6ujm9r$p6q$1@nnrp1.dejanews.com>
In article <356ae54e.0@newsprime.tidalwave.net>,
"caustic" <caustic@causticinteractive.nospam.com> wrote:
> Hi,
>
> I have been trying to write a quick CGI that displays news headlines from a
> newspage.
>
> Basically, this script needs to hit a flat html page and grab the first 3
> headlines it finds within <headline></headline> tags and display them on a
> homepage.
>
> Has anybody written anything similar to this that they could share with me?
> I've been trying to repurpose a search engine that I have to do this, but
> I've been running into a lot of problems.
Take it Zenin.
Patrick Timmins
$monger{Omaha}[0]
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Sat, 26 Sep 1998 16:15:24 -0700
From: Jim <jim@123stitch.com>
Subject: Non-blocking I/O
Message-Id: <360D758C.251127F2@123stitch.com>
Hello Everyone,
Does anyone know how to do a non-blocking READ operation with
PERL on Windows 95?? I need to be able to read from 2 I/O streams
at the same time without blocking. If I use the READ function,
PERL blocks (waits for input on that stream) until there is input
on that stream. Because READ is waiting for user input I can't
check if there is any input on the other stream. What I'd like
to be able to do is READ input from the stream and not get blocked
there if there is currently no input in the buffer. Or, is there
some way to check if there is input in the buffer before I do the
read?
I realize that on UNIX I could fork a separate task to handle each
input stream, but on Windows 95 fork cannot be used.
Any help would be appreciated!!
Jim
--
1-2-3 Stitch! (TM)
Sharing the Gift of Cross Stitch (TM)
http://www.123stitch.com
(925) 551-3111
------------------------------
Date: Sat, 26 Sep 1998 16:35:11 -0700
From: Farhad Farzaneh <ff@creative.net>
Subject: Perl inconsistency?
Message-Id: <360D7A30.D862BE6A@creative.net>
Hello,
First, I admit that it's probably my misunderstanding, but here is my problem:
I have some code that includes (modified for testing):
my $r = $rField->range; # a method of object instance $rField
print "Undefined\n" if ( !defined($r));
my @range = @$r;
and which does print the "Undefined". It chokes on the last line with the
following error:
# Can't use an undefined value as an ARRAY reference.
However, when I try to build a short script to test this behaviour, I never
get this
error. I'm not sure why this error occurrs in one case and not in another.
Is it because I'm using an object in the former case?? That doesn't make any
sense to me...
Here's the test script:
#!/bin/perl
my $f; # keep this undefined
print "Undefined\n" if ( !defined($f));
my @r = @$f; # This does not cause a complaint!
# Now play with unsing returns from undefined subroutines
print "foo = ",&foo,"\n";
print @{&foo};
print %{&foo};
sub foo {
return;
}
Thanks in advance.
Farhad Farzaneh
------------------------------
Date: 26 Sep 1998 21:28:01 -0000
From: Jonathan Stowe <gellyfish@gellyfish.btinternet.com>
Subject: Re: perl tutorial
Message-Id: <6ujm91$4fk$1@gellyfish.btinternet.com>
On Sat, 26 Sep 1998 05:53:12 GMT chaitra@my-dejanews.com wrote:
> Hi,
> can anyone help me in finding some good perl tutorial on the web.
If you look at http://www.perl.com/ and follow the link on the lower
left side marked peculiarly "Tutorials" you might find something of
help. Others of course might supply the complete URL.
/J\
--
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: 26 Sep 1998 21:10:09 -0000
From: Jonathan Stowe <gellyfish@gellyfish.btinternet.com>
Subject: Re: Perl version compatability
Message-Id: <6ujl7h$4eu$1@gellyfish.btinternet.com>
On Sat, 26 Sep 1998 00:22:09 -0500 I R A Aggie <fl_aggie@thepentagon.com> wrote:
> In article <01bde8c5$5b251480$0100007f@quibhrgm>, "Ian Wilkinson"
> <ian@no-spam.4site.co.uk> wrote:
> + When asked recently about upgrading to a more recent version of Perl, a
> + representative replied - "It has not been upgraded to avoid possible problems
> + with existing scripts". I'm not in a position to argue about the merits of
> + that statement
> If it runs under 5.001, it should run under 5.004/5.005. AFAIK, anyway.
> Go search the www.perl.com site for "Gotcha's".
> If you want to obtain their undivided attention, tho, ask them if they
> realize that 5.001 is CERTifably INsecure?
In article <01bde8c5$5b251480$0100007f@quibhrgm>, "Ian Wilkinson"
<ian@no-spam.4site.co.uk> also wrote:
>> My access to Perl (v5.001) is provided by one of the largest ISPs in Europe,
>> with sites hosted under Apache 0.8.14. (They provide newer environments and
>> I have an option to transfer from the old server should I wish).
I think that it would only be right to point out that that version of Apache
is also insecure - the only most secure version is 1.2.6 or 1.3 +
/J\
--
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: Sat, 26 Sep 1998 21:38:50 GMT
From: Sweets@sugarhigh.com (Belle)
Subject: Porting Unix perl script to winNT servers
Message-Id: <360d5e21.29780689@news.mindspring.com>
After several hours of hunting a good shopping cart script, I finally
found one that looked PERFECT for me. Unfortunately, the script was
for Unix based servers and may not run on NT servers, which is what my
host uses. Could someone tell me if it's possible to edit this script
(http://www.virtualcenter.com/scripts2/WWWOrder2.html) for NT? Any
help would be appreciated.
A
------------------------------
Date: Sat, 26 Sep 1998 17:51:49 -0400
From: "Jim Weeks" <jim@siteplus.com>
Subject: Re: removing a-z from a string. Sorry, I forgot the [ ] braces.
Message-Id: <6ujnll$mag$1@camel21.mindspring.com>
Sorry,
I forgot the [ ] braces.
------------------------------
Date: Sat, 26 Sep 1998 17:46:46 -0400
From: "Jim Weeks" <jim@siteplus.com>
Subject: removing a-z from a string.
Message-Id: <6ujnc6$od0$1@camel21.mindspring.com>
I should know this, but could someone tell me how to remove the letters from
this string.
Bmw Volvo 205-894-5660
$line =~ s/a-z//g; #remove lower case.
$line =~ s/A-Z//g; #remove upper case.
doesn't work.
Thanks, Jim
jim@siteplus.com
------------------------------
Date: Sat, 26 Sep 1998 19:15:15 -0400
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: removing a-z from a string.
Message-Id: <MPG.10773f83aa71d9219896ba@news.south-carolina.net>
In article <6ujnc6$od0$1@camel21.mindspring.com> on Sat, 26 Sep
1998 17:46:46 -0400, Jim Weeks (jim@siteplus.com) pounded in the
following text:
=> I should know this, but could someone tell me how to remove the letters from
=> this string.
=>
=> Bmw Volvo 205-894-5660
=>
=> $line =~ s/a-z//g; #remove lower case.
=> $line =~ s/A-Z//g; #remove upper case.
=>
=> doesn't work.
What 'cha mean 'doesn't work'? It's best if you post exactly
what you think it should do, and what it is actually doing. We
can't read your mind. :)
And while I'm at it, that's not the most efficient way of doing
it... :)
For one thing, your regex has to be run on the string for EVERY
character in the string. Talk about slow. :) And then you do it
I<again> for uppercase letters.
Slightly more efficient would be:
$line =~ s/[a-zA-Z]//g;
but that's almost as bad.
If you insist on using a regex, try something like:
$line =~ s/[a-zA-Z]+//g;
This scoops up as many [a-zA-Z]'s as it can in one shot, which
cuts the time down considerably.
Of course, if your really concerned about efficiency, go for:
$line =~ tr/a-zA-Z/d;
Some benchmarks:
#!/usr/bin/perl -w
use Benchmark;
# String designed to be closer to real data.
$string = q(abcdef3ghijkl mnopq4rstuvwxy7zABC8DEFGHIJKL
MNOPQ9RSTUVWXYZaBcCd9D eEf9Fg);
timethese ( 100_000, {
'Control' => sub { $_ = $string },
'SimpleRe' => sub { $_ = $string; $_ =~ s/[a-zA-Z]//g },
'RedundantRe' => sub { $_ = $string; $_ =~ s/[a-z]//g; $_ =~
s/[A-Z]//g },
'GreedyRe' => sub { $_ = $string; $_ =~ s/[a-zA-Z]+//g },
'Tr' => sub { $_ = $string; $_ =~ tr/a-zA-Z//d },
}
);
__END__
Benchmark: timing 100000 iterations of Control, GreedyRe,
RedundantRe, SimpleRe, and Tr...
Control: 1 wallclock secs ( 1.80 usr + 0.00 sys = 1.80 CPU)
GreedyRe: 10 wallclock secs (10.11 usr + 0.00 sys = 10.11 CPU)
RedundantRe: 30 wallclock secs (28.72 usr + 0.00 sys = 28.72
CPU)
SimpleRe: 26 wallclock secs (26.59 usr + 0.00 sys = 26.59 CPU)
Tr: 3 wallclock secs ( 4.07 usr + 0.00 sys = 4.07 CPU)
=> Thanks
Hope This Helped!
=> Jim
=> jim@siteplus.com
--Matthew
------------------------------
Date: 26 Sep 1998 16:34:50 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: retaining user id
Message-Id: <yliuiav46d.fsf@windlord.stanford.edu>
bc <bcgrafx@sprynet.com> writes:
> I have written a Perl Database that requires backwards compatiblity to
> our previous database on OpenVMS. The data files are just plain text
> files. The Perl CGI server is running IRIX 6.3 and uses an nfs mounting
> system to mount the database server.
> Now my problem. The files created by the Irix system won't transfer over
> to the OpenVMS system without losing their user id. The protections are
> maintained as created.
> The protections are RW for user,group,and other. The userid becomes
> ucx$nobody and the group becomes ucx$nobody. Both systems have logins
> that correspond.
This is consistent with an NFS-mounted file system using the security
model AUTH_NONE. From nfssec(5) on a Solaris system:
none Use null authentication (AUTH_NONE). NFS clients using
AUTH_NONE have no identity and are mapped to the anonymous
user nobody by NFS servers. A client using a security mode
other than the one with which a Solaris NFS server shares the
file system will have its security mode mapped to AUTH_NONE.
In this case, if the file system is shared with sec=none,
users from the client will be mapped to the anonymous
user. The NFS security mode none is supported by
share_nfs(1M), but not by mount_nfs(1M) or automount(1M).
What it sounds like you want instead is the more standard NFS behavior of
AUTH_SYS:
sys Use AUTH_SYS authentication. The user's UNIX user-id and
group-ids are passed in the clear on the network,
unauthenticated by the NFS server. This is the simplest
security method and requires no additional administration. It
is the default used by Solaris NFS Version 2 clients and
Solaris NFS servers.
(Excerpts of man pages copyright Sun Microsystems.) I'd say the first
thing to do is to try to locate similar settings in the documentation of
your OpenVMS NFS daemons and see if you can change what security model
they use. I'm guessing that one of the problems that you'll run into is
that Unix uses different notions of user ID and group than VMS does, and
the translation could be tricky.
Good luck with it!
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: Sat, 26 Sep 1998 22:26:57 GMT
From: tgy@chocobo.org (Tim Gim Yee)
Subject: Re: Returning a "near" hash key.
Message-Id: <360f660c.869685458@news.oz.net>
On Fri, 25 Sep 1998 21:31:55 EDT, dblack@saturn.superlink.net (David
A. Black) wrote:
>I'm posting this in the hope of flushing out a truly slender and
>idiomatic version. This one has that not-quite-there feel.... but
>it might suit your needs, if adapted.
>
>
>#!/usr/local/bin/perl -w
>
>use strict;
>
>my %h = map { $_, uc } qw(apple banana kiwi orange);
>
>for my $w ( qw( orangutan applutan kiwutan bananutan ) ) {
> print "Closest to $w: ", $h{closekey(\%h, $w)}, "\n";
>}
>
>sub closekey { closeidx([%{shift()}], shift) }
>
>sub closeidx {
> my ($l, $w) = @_;
> my @sl = sort(@$l, $w);
> my ($n, $p);
> do { $n = $p; $p = shift @sl } until $p eq $w;
> shift @sl || $n;
>}
The code above works as specified by the original poster:
Closest to orangutan: ORANGE
Closest to applutan: BANANA
Closest to kiwutan: ORANGE
Closest to bananutan: KIWI
Now I'm going to arbitrarily redefine 'closest' to do what I expect:
Closest to orangutan: ORANGE
Closest to applutan: APPLE
Closest to kiwutan: KIWI
Closest to bananutan: BANANA
#!/usr/bin/perl -w
use strict;
use Algorithm::LCS qw[diff];
sub approx {
my $want = [split //, shift];
return (
sort {$a->[1] <=> $b->[1] || $a->[0] cmp $b->[0]}
map [$_, scalar @{[map @$_, @{[diff $want, [split //]]}]}],
@_
)[0]->[0];
}
my %h = map { $_, uc } qw(apple banana kiwi orange);
for my $w ( qw( orangutan applutan kiwutan bananutan ) ) {
print "Closest to $w: ", $h{approx $w, keys %h}, "\n";
}
------------------------------
Date: 26 Sep 1998 20:14:27 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Running apps. list through Perl?
Message-Id: <6ujhv3$46u$1@gellyfish.btinternet.com>
On Fri, 25 Sep 1998 11:40:59 -0700 Alex Guberman <alex@digi-q.com> wrote:
> Hi,
> Does anybody know how to get a list of running applications on the
> system through Perl running under Windows95 or NT?
I am not sure whether there is some facility available in the Win32::*
modules - but for NT there is a utility called "tlist" available with
the Resource Kit - this shows all of the running process rather than
applications specifically.
/J\
--
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: 12 Jul 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 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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 3833
**************************************