[16711] in Perl-Users-Digest
Perl-Users Digest, Issue: 4123 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 24 18:16:10 2000
Date: Thu, 24 Aug 2000 15:15:41 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <967155326-v9-i4123@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 24 Aug 2000 Volume: 9 Number: 4123
Today's topics:
Replace "XYZ" but not "ABCXYZ"??? - HELP!! <holysmokes99@hotmail.com>
Re: Replace "XYZ" but not "ABCXYZ"??? - HELP!! <stephenk@cc.gatech.edu>
Re: Self-Answering Questions (Was Re: Flipflop matching <russ_jones@rac.ray.com>
Re: Self-Answering Questions (Was Re: Flipflop matching <uri@sysarch.com>
Re: Self-Answering Questions (Was Re: Flipflop matching <jeff@vpservices.com>
Re: Self-Answering Questions (Was Re: Flipflop matching <lr@hpl.hp.com>
Re: sorting a hash by key value (I've looked at the TIE (Mark-Jason Dominus)
Re: Sorting by a subfield (WAS: Re: This is my last que pape_98@my-deja.com
Re: Sorting by a subfield (WAS: Re: This is my last que <lr@hpl.hp.com>
Re: Sorting by a subfield (WAS: Re: This is my last que <ren.maddox@tivoli.com>
trying to pull each string from file to evaluate... <gasper@cis.ohio-state.edu>
Re: Where is the Perl Newbie or Begginers group? <gdonovanNOgdSPAM@jeffco.k12.co.us.invalid>
Re: Where is the Perl Newbie or Begginers group? (Jon S.)
WORKIN WITH C in PERL <nail.uenlue@freesurf.ch>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 24 Aug 2000 21:20:42 GMT
From: Marcus <holysmokes99@hotmail.com>
Subject: Replace "XYZ" but not "ABCXYZ"??? - HELP!!
Message-Id: <8o43it$ir5$1@nnrp1.deja.com>
I am having some trouble using regular expressions to search and
replace. The problem is that I want to replace the occurrence
of "\w+@\w+\.\S+" (i.e. any email address like jack@whatever.com) with
some other text, but if "\w+@\w+\.\S+" is preceded by "XYZ"
(i.e. "XYZjack@whatever.com") then I DO NOT want the replacement to
take place. Is this possible with regular expressions? I am more
familiar using VBScript regular expressions (the VB NG hasn't been able
to help me out yet). If I recall my Perl, then the expression I am
using in vbscript would look somethingl like this:
/[^X][^Y][^Z]\w+@\w+\.\S+/WHATEVERTEXT/
This does not work though because once the scanning of the pattern gets
past the first character that I don't want (i.e. "X"), it then gets a
match on the second character "Y" because is is not an "X". I need
to 'glue' the "XYZ" together somehow. Any thoughts? This is giving me
a headache!
Cheers,
Marcus Bell
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 24 Aug 2000 17:41:18 -0400
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: Replace "XYZ" but not "ABCXYZ"??? - HELP!!
Message-Id: <39A5967D.6F19ACA8@cc.gatech.edu>
Marcus wrote:
> I am having some trouble using regular expressions to search and
> replace. The problem is that I want to replace the occurrence
> of "\w+@\w+\.\S+" (i.e. any email address like jack@whatever.com) with
> some other text, but if "\w+@\w+\.\S+" is preceded by "XYZ"
> (i.e. "XYZjack@whatever.com") then I DO NOT want the replacement to
> take place. Is this possible with regular expressions? I am more
> familiar using VBScript regular expressions (the VB NG hasn't been able
> to help me out yet). If I recall my Perl, then the expression I am
> using in vbscript would look somethingl like this:
>
> /[^X][^Y][^Z]\w+@\w+\.\S+/WHATEVERTEXT/
>
> This does not work though because once the scanning of the pattern gets
> past the first character that I don't want (i.e. "X"), it then gets a
> match on the second character "Y" because is is not an "X". I need
> to 'glue' the "XYZ" together somehow. Any thoughts? This is giving me
> a headache!
>
s/(?<!XYZ)\w+@\w+\.\S+/WHATEVERTEXT/ should do the trick.
perldoc perlre
--
Stephen Kloder | "I say what it occurs to me to say.
stephenk@cc.gatech.edu | More I cannot say."
Phone 404-874-6584 | -- The Man in the Shack
ICQ #65153895 | be :- think.
------------------------------
Date: Thu, 24 Aug 2000 13:04:51 -0500
From: Russ Jones <russ_jones@rac.ray.com>
Subject: Re: Self-Answering Questions (Was Re: Flipflop matching)
Message-Id: <39A563C3.8DAACB36@rac.ray.com>
Larry Rosler wrote:
>
>
> Many of the other words (including syntactic elements I didn't quote,
> such as 'do', 'for' and 'while') are adopted from C. I don't know why
> 'last' replaced 'break', or 'next' replaced 'continue', though. And
> there's still no 'switch' or 'case'. :-)
>
"do" is at least as old as FORTRAN (as is the practice of using "i"
for the name of the counter in a do loop).
--
Russ Jones - HP OpenView IT/Operatons support
Raytheon Aircraft Company, Wichita KS
russ_jones@rac.ray.com 316-676-0747
Quae narravi, nullo modo negabo. - Catullus
------------------------------
Date: Thu, 24 Aug 2000 19:22:08 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Self-Answering Questions (Was Re: Flipflop matching)
Message-Id: <x7k8d6sbvm.fsf@home.sysarch.com>
>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:
LR> And there's still no 'switch' or 'case'. :-)
damian has a module (i think it is on cpan now) which does a switch in
very perlish style. and it is proposed to be in the core with even more
power in perl6. so just be patient.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Thu, 24 Aug 2000 13:08:18 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Self-Answering Questions (Was Re: Flipflop matching)
Message-Id: <39A580B2.74C63CDB@vpservices.com>
Larry Rosler wrote:
>
> [Posted and a courtesy copy mailed.]
>
> In article <x7wvh7sbq7.fsf@home.sysarch.com> on Thu, 24 Aug 2000
> 01:13:04 GMT, Uri Guttman <uri@sysarch.com> says...
> > >>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:
>
> ...
>
> > that list just shows you larry (the wall's) linguistic background. and it
> > highlights the interesting split of perl into line noise and well chosen
> > english words.
>
> A lot of the background is in Unix, because many of those English words
> are the names of traditional Unix system calls.
Yes Larry W uses many "well chosen english words" (thanks Larry :-)).
But let's not confuse the fact that the words have English meanings with
their meanings in Perl. Sure, once you know what "pop" or "shift" or
"push" mean, they seem to have a very natural flow to them and the way
they are used in perl "makes sense" and *becomes* intuitive. That's
partly because they all are part of the same metaphor that physically
manipulating something is the same as mentally manipulating it. But for
beginners (especially those without the Unix and other programming
background) the use of those words to describe those operations is not
inately intuitive. They become intuitive as you use them but aren't
necessarily so on first sight. And then there are cases where a 100%
mapping of the English word and the Perl word can be misleading. I
think the common confusion between "array" and "list" is an example.
And, what exactly would it mean to "unshift" a physical object?
--
Jeff
------------------------------
Date: Thu, 24 Aug 2000 13:45:07 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Self-Answering Questions (Was Re: Flipflop matching)
Message-Id: <MPG.140f29322d7c145798acdd@nntp.hpl.hp.com>
In article <39A580B2.74C63CDB@vpservices.com> on Thu, 24 Aug 2000
13:08:18 -0700, Jeff Zucker <jeff@vpservices.com> says...
> Larry Rosler wrote:
...
> Yes Larry W uses many "well chosen english words" (thanks Larry :-)).
> But let's not confuse the fact that the words have English meanings with
> their meanings in Perl. Sure, once you know what "pop" or "shift" or
> "push" mean, they seem to have a very natural flow to them and the way
> they are used in perl "makes sense" and *becomes* intuitive. That's
> partly because they all are part of the same metaphor that physically
> manipulating something is the same as mentally manipulating it. But for
> beginners (especially those without the Unix and other programming
> background) the use of those words to describe those operations is not
> inately intuitive. They become intuitive as you use them but aren't
> necessarily so on first sight. And then there are cases where a 100%
> mapping of the English word and the Perl word can be misleading. I
> think the common confusion between "array" and "list" is an example.
> And, what exactly would it mean to "unshift" a physical object?
Neither 'unshift' nor 'unlink' was on my list. Nor several other
reasonable English words with less than intuitive Perl meanings.
('unshift' isn't an English word.)
I thought 'shift' could be intuitive to people with any engineering
background (vide 'shift register'); 'push' and 'pop' were marginal
choices. But the whole exercise was 'once though the list' from
perlfunc, so please don't make too much of it.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 24 Aug 2000 20:45:00 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: sorting a hash by key value (I've looked at the TIE functions and I'm still confused...)
Message-Id: <39a5894c.662f$38a@news.op.net>
[mailed and posted]
In article <8o37e7$mq6$1@news.doit.wisc.edu>,
Eric White <ejwhite1@facstaff.wisc.edu> wrote:
> checkbox_group(-name=>'D1A2', -linebreak=>1, Values=>\%care),
Values is supposed to be an array, not a hash. The idea is that you
give checkbox_group two pieces of information:
* an array of values in the order you want them displayed
* a hash that maps values to labels
Labels are what the user sees, and values are what is reported back to
the program when the user submits the form.
So you want your @values hash to have [1, 2, 3, 4, 98, 99] in
numerical order, and you want a %labels hash that uses the numbers as
keys and the strings like "Non-relative adult" as values.
In the %labels hash, the order of the items doesn't matter, because
the hash is only there to express which label goes with which value.
The order that the buttons are displayed is determined completely by
the @values array.
Try this:
@values = sort { $a <=> $b } (keys %care); # ascending numeric order
checkbox_group(-name=>'D1A2', -linebreak=>1,
-values => \@values, # this determines the order
-labels => \%care, # this says what the labels are
)
You don't want 'tie' or IxHash or anything like that here.
------------------------------
Date: Thu, 24 Aug 2000 18:46:17 GMT
From: pape_98@my-deja.com
Subject: Re: Sorting by a subfield (WAS: Re: This is my last question, I swear!!!!!!!!!!)
Message-Id: <8o3qhi$7lu$1@nnrp1.deja.com>
Hi,
Now I am really stuck.
I have recently been unsing this formula to sort my database:
@sorted = map { $_->[0] }
sort { $a->[0] cmp $b->[0]
||
$a->[1] <=> $b->[1]
} map { [$_, /(\d+)/, uc($_)] } @unsorted;
but it still does not produce the desired result. It sorts the words
correctly, but not the numbers, it still sorts them in the 1,10,11,2,22
manner. I am desperate to find an answer to this problem, so please
help.
Thanks
In article <MPG.140cfb6afebcef1098acc5@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
> In article <8nv28o$nao$1@nnrp1.deja.com>, pape_98@my-deja.com says...
> > Thank you guys this all very helpfull.
> > Now my problem is that I might end up having to sort more than one
> > field. By this I mean that I would have to do something like this:
> >
> > for ($i=0; $i <= $#lines; $i++) {
> > @names = split(/,/,$lines[$i]);
> > Once the lines would have been broken down (into 6 sections), how
(if I
> > can) do I go about sorting both fields; the first by letter and the
> > second by numbers in increasing number.
>
> This is discussed in the Perl documentation:
>
> perldoc -f sort
>
> perldoc -q sort
>
> and in our paper on sorting techniques (which includes other
> references):
>
> http://www.hpl.hp.com/personal/Larry_Rosler/sort/
>
> > I'm sorry if I seem to be dragging this discussion into eternity,
but
> > this is all new to me; and not as easy to soak in.
>
> You will have to do some reading, and some playing with simple
examples.
>
> > PS: Larry, couldn't do newsgroup style because I wasn't responding
to
> > your points; But you've been very helpful.
>
> If there is nothing to quote, quote nothing, not everything.
>
> > Thanks again,
>
> You're welcome. Now go and learn.
>
> <SNIP of previous article, quoted in its entirety>
>
> --
> (Just Another Larry) Rosler
> Hewlett-Packard Laboratories
> http://www.hpl.hp.com/personal/Larry_Rosler/
> lr@hpl.hp.com
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 24 Aug 2000 12:54:47 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Sorting by a subfield (WAS: Re: This is my last question, I swear!!!!!!!!!!)
Message-Id: <MPG.140f1d625cb59db198acdb@nntp.hpl.hp.com>
[You still haven't learned not to quote the entire article you are
replying to, out of sequence at the end. Even if your newsreader X-
Http-User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)
does this by default, you must edit it manually, or be prepared to lose
tolerance around here.]
In article <8o3qhi$7lu$1@nnrp1.deja.com> on Thu, 24 Aug 2000 18:46:17
GMT, pape_98@my-deja.com <pape_98@my-deja.com> says...
> Hi,
> Now I am really stuck.
> I have recently been unsing this formula to sort my database:
> @sorted = map { $_->[0] }
> sort { $a->[0] cmp $b->[0]
> ||
> $a->[1] <=> $b->[1]
> } map { [$_, /(\d+)/, uc($_)] } @unsorted;
>
> but it still does not produce the desired result. It sorts the words
> correctly, but not the numbers, it still sorts them in the 1,10,11,2,22
> manner. I am desperate to find an answer to this problem, so please
> help.
Your first (lexicographical) comparison should be between the ->[2]
elements, not the ->[0] elements. So you aren't getting the case-
folding you desire.
But that still won't deal with the second (numerical) comparison, which
is specified correctly.
One can't help you further without a small sample of the unsorted data,
so one can verify your assertion about the incorrect numerical sort.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 24 Aug 2000 14:43:55 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Sorting by a subfield (WAS: Re: This is my last question, I swear!!!!!!!!!!)
Message-Id: <m3vgwq5ts4.fsf@dhcp11-177.support.tivoli.com>
pape_98@my-deja.com writes:
> @sorted = map { $_->[0] }
> sort { $a->[0] cmp $b->[0]
> ||
> $a->[1] <=> $b->[1]
> } map { [$_, /(\d+)/, uc($_)] } @unsorted;
>
> but it still does not produce the desired result. It sorts the words
> correctly, but not the numbers, it still sorts them in the 1,10,11,2,22
> manner. I am desperate to find an answer to this problem, so please
> help.
It's not clear what you want to happen when a string is compared to a
number. In any event, try switching the order of your "cmp" and "<=>"
tests. That way you get a numeric test first and only resort to a
string comparison if the numbers are equal. Since a non-numeric
string will become the number 0, comparing (non-numeric) strings will
always fail over to the string comparison.
Of course, there is likely a much better Guttman-Rosler Transform for
this, but I'll leave that to Larry or Uri....
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Thu, 24 Aug 2000 17:25:28 -0400
From: "Keith Gasper" <gasper@cis.ohio-state.edu>
Subject: trying to pull each string from file to evaluate...
Message-Id: <8o43qg$3ah$1@news.cis.ohio-state.edu>
Hi everyone. I'm attempting to write a perl script that removes each string from
a text file and evaluates it. I know it is possilbe to remove the last line of a text from the
http://www.perl.com/pub/doc/manual/html/pod/perlfaq5.html#How_do_I_change_one_line_in_a_fi
document... however, it doesn't give a description of how you go about actually removing
from the very end of the file...
I have written a batch file that stops various services on a server on our intranet remotely. The
batch file fires all of the commands at once and oftentimes returns a success message before the
services are actually stopped/started. I'm writing the script to repeatedly get the URL of the
webpage whose service I'm stopping. Each time perl gets the text provided by the URL, I'd like
to search for the error message that appears when the service is not running. The script will
stop once the error message is not present (and the service is running). I just need to figure out
how to grab the last line of the file, evaluate it, then throw it away and grab the next line.
ANY IDEAS? Thanks so much. Much appreciation. happy coding
Keith
------------------------------
Date: Thu, 24 Aug 2000 12:13:18 -0700
From: sysnovice <gdonovanNOgdSPAM@jeffco.k12.co.us.invalid>
Subject: Re: Where is the Perl Newbie or Begginers group?
Message-Id: <02daf294.5eab77c2@usw-ex0109-069.remarq.com>
Thank you for your responces. I am now better informed and
will do my best to follow the guidlines you have shared with
me.
G.Donovan
* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping. Smart is Beautiful
------------------------------
Date: Thu, 24 Aug 2000 21:05:18 GMT
From: jonceramic@nospammiesno.earthlink.net (Jon S.)
Subject: Re: Where is the Perl Newbie or Begginers group?
Message-Id: <39a58cae.11670154@news.earthlink.net>
On Thu, 24 Aug 2000 07:45:21 -0700, sysnovice
<gdonovanNOgdSPAM@jeffco.k12.co.us.invalid> wrote:
>Hello,
>
>I am a Unix SysAd with no programming experience looking for
>a discussion group for Perl beginners like myself that don't
>have a clue. I'm so new I don't even know where to find
>FAQ's. It's evident that from many postings here that the
>experienced Perl programmers are more than a bit annoyed
>with folks like myself posting "dumb" questions. Does
>someone out there know of a group for the retarded perl
>wanabes? If I could find such a place I would address all my
>questions there until the year 2025 when I may have a
>question intelligent enough for this discussion group.
>Thanks for your help.
>G.Donovan
G, it ain't that bad.
The rules are like this for newbies...
1. Don't answer questions you don't know the answer to...
2. Check the FAQ before you ask your question...
3. Post relevant code snippets if applicable...
4. Don't argue with the actual gurus (there are a number of incredibly
important Perl people who hang out here)
and finally...
5. If you really mean Perl/CGI instead of just Perl, address the
question to either this group or comp.infosystems.www.cgi depending on
if it's a Perl or a CGI/www issue.
Otherwise, the newbies get tons of help here. I sure have.
I'd recommend using the docs at www.perl.com (unless you're at a
command line all day long) and getting your hands on a book like
Learning Perl.
Best of luck,
Jon
------------------------------
Date: Thu, 24 Aug 2000 23:16:35 +0200
From: "Nail Ünlü" <nail.uenlue@freesurf.ch>
Subject: WORKIN WITH C in PERL
Message-Id: <8o43g9$ao2$1@news.imp.ch>
hi everybody,
is there a way of executin a c programm under unix with perl and to read the
output with stdin ???
thanks in advance,
nail
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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.
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 V9 Issue 4123
**************************************