[16913] in Perl-Users-Digest
Perl-Users Digest, Issue: 4325 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 14 18:11:12 2000
Date: Thu, 14 Sep 2000 15:10:24 -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: <968969424-v9-i4325@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 14 Sep 2000 Volume: 9 Number: 4325
Today's topics:
Re: Cyrillic in Perl? <bkennedy@hmsonline.com>
Deleting Files penpendisarapen@my-deja.com
Re: Deleting Files (Mark-Jason Dominus)
escape strings ? (James Stevenson)
Re: escape strings ? (Jerome O'Neil)
Re: File name with space in Net::FTP put <lr@hpl.hp.com>
Re: Finding subdirectories on Windows Systems nobull@mail.com
Re: format @<<< wrathmolten@my-deja.com
Re: Getting File stats on a remote file nobull@mail.com
Re: Getting started w/ Perl (Richard J. Rauenzahn)
Re: golf (Was Re: transliterating file names in a dir) <lr@hpl.hp.com>
Re: golf (Was Re: transliterating file names in a dir) <ren.maddox@tivoli.com>
Re: golf (Was Re: transliterating file names in a dir) <uri@sysarch.com>
Re: golf (Was Re: transliterating file names in a dir) <lr@hpl.hp.com>
Re: golf (Was Re: transliterating file names in a dir) <lr@hpl.hp.com>
Re: grep in perl (Richard J. Rauenzahn)
Re: How do I sort a list of list by a certain column <lr@hpl.hp.com>
HTML::LinkExtor and <applet> problem (Walter Pienciak)
Re: I really need help !!!! <lr@hpl.hp.com>
Re: I really need help !!!! <flavell@mail.cern.ch>
Re: Is there a good freeware/shareware IDE for PERL? <lr@hpl.hp.com>
Iterate over greed? <karner@fore.com>
Re: Iterate over greed? (Mark-Jason Dominus)
Re: Iterate over greed? <ren.maddox@tivoli.com>
Re: Iterate over greed? <spragg@cs.ucdavis.edu>
Re: Iterate over greed? <uri@sysarch.com>
Re: Iterate over greed? <lr@hpl.hp.com>
Re: Iterate over greed? <yanick@babyl.sympatico.ca>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 14 Sep 2000 21:03:01 GMT
From: "Ben Kennedy" <bkennedy@hmsonline.com>
Subject: Re: Cyrillic in Perl?
Message-Id: <92bw5.25949$AW2.348370@news1.rdc2.pa.home.com>
"Elisa Roselli" <e.roselli@volusoft.com> wrote in message
news:8pq0oh$hck$1@wanadoo.fr...
> Is Perl ASCII-based (like awk) or Unicode-based (like Java)? How do
> codepages and locale come into all this? Can screens display Latin and
> Cyrillic simultaneously? What kind of IO? Can computers bi-locate like
> medieval saints? When do I get to dance with Prince Andrey?
As of Perl 5.6, there is unicode support, but the page 'perldoc perlunicode'
says off the bat -
WARNING: The implementation of Unicode support in Perl is incomplete.
There is also a decently sized chapter in the 3rd edition of the Camel book,
which may help answer your questions. It does say in it "Avoidance of
locales is strongly encouraged". I have a feeling that you are not getting
a detailed repsonce from people because people haven't bothered to learn the
details about unicode (especially myself). Anyway, I hope this helps -
--Ben Kennedy
------------------------------
Date: Thu, 14 Sep 2000 21:24:53 GMT
From: penpendisarapen@my-deja.com
Subject: Deleting Files
Message-Id: <8prfmb$p1t$1@nnrp1.deja.com>
Is there another way to delete a file without using 'system'? I couldn't
seem to find one in my Perl reference book.
--
BBQ
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 14 Sep 2000 21:57:00 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Deleting Files
Message-Id: <39c149a4.428c$120@news.op.net>
In article <8prfmb$p1t$1@nnrp1.deja.com>, <penpendisarapen@my-deja.com> wrote:
>Is there another way to delete a file without using 'system'?
You use hte 'unlink()' function.
>I couldn't seem to find one in my Perl reference book.
Perhaps you should get a better reference book? _Programming Perl,
3rd Edition_ from O'Reilly is supposed to be pretty good. I have the
second edition, and when I look in the index under 'delete files' I
find that it refers tme to the page about unlink().
------------------------------
Date: 14 Sep 2000 20:17:38 GMT
From: James@linux.home (James Stevenson)
Subject: escape strings ?
Message-Id: <slrn8s2g4m.s8p.James@linux.home>
Hi
is there a generic function in perl to convert a string to an escape
string and back again eg
"the 'text
that is h"ere"
to
"the \'text\nthat is h\"ere"
thanks
James
--
---------------------------------------------
Check Out: http://www.users.zetnet.co.uk/james/
E-Mail: mistral@stevenson.zetnet.co.uk
9:10pm up 6 days, 11:51, 9 users, load average: 0.12, 0.33, 0.32
------------------------------
Date: Thu, 14 Sep 2000 20:48:06 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: escape strings ?
Message-Id: <aQaw5.708$wN2.169646@news.uswest.net>
James@linux.home (James Stevenson) elucidates:
> Hi
>
> is there a generic function in perl to convert a string to an escape
> string and back again eg
>
> "the 'text
> that is h"ere"
>
> to
>
> "the \'text\nthat is h\"ere"
Generaly, you should use quote like operators for stuff like this.
It's much easier to read. Some modules will provide specialized encoding
functions for their own needs.
print qq{the 'text\nthat is h"ere"};
HTH!
------------------------------
Date: Thu, 14 Sep 2000 11:47:27 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: File name with space in Net::FTP put
Message-Id: <MPG.142abd1ea509de9798ad63@nntp.hpl.hp.com>
In article <m3zolbcocu.fsf@stig.a.sol.no> on 14 Sep 2000 11:30:25 +0200,
Stig Palmquist <stig@palmquist.org> says...
...
> You sould probably try to escape "\" the space character.
>
> Like:
>
> $filenametoupload=~ s/ /\ /g;
That is a costly no-op. Probably you had the following in mind, but
didn't bother to test it before posting:
$filenametoupload =~ s/ /\\ /g;
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 14 Sep 2000 18:53:21 +0100
From: nobull@mail.com
Subject: Re: Finding subdirectories on Windows Systems
Message-Id: <u9bsxqsvvy.fsf@wcl-l.bham.ac.uk>
"FX" <FX@hasnomail.com> writes upside down because he's too lazy to
write the right way up:
> >> How can I find the subdirectories from base directory on a windows
> >> machine?
> >
> >Look into File::Find where you test with a "-d".
> I'm quite new to perl
>
> so thanks for your answer but it doesn't help me much.
OK since you are new I'll explain. When someone says "look into
Foo::Bar" then they mean you should read the documentation associated
with the Perl module Foo::Bar. Unless they state otherwise the module
will be part of the standard Perl5 distribution or can be found on the
"Comprehensive Perl Archive Network" at http://www.cpan.org/
To read the documentation for an installed module type:
perldoc Foo::Bar
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 14 Sep 2000 21:50:10 GMT
From: wrathmolten@my-deja.com
Subject: Re: format @<<<
Message-Id: <8prh6a$r5f$1@nnrp1.deja.com>
Does anyone have any ideas on this? I'm still stuck on this piece of my
code. Everything else is working like a dream!
Thanks,
Rathmore
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 14 Sep 2000 18:53:52 +0100
From: nobull@mail.com
Subject: Re: Getting File stats on a remote file
Message-Id: <u9aedasvv3.fsf@wcl-l.bham.ac.uk>
haazi2@aol.com (Haazi2) writes:
> I'm accessing audio files on a remote server and I need to retrieve the last
> modified time of these files. How can I do this in Perl. Can I use File::stat
> on files located on a remote server?
That rather depends on what protocol you are using to the remote server.
If protocol is HTTP then use the HEAD method.
HTTP in Perl is implemented by the LWP modules.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 14 Sep 2000 20:35:12 GMT
From: nospam@hairball.cup.hp.com (Richard J. Rauenzahn)
Subject: Re: Getting started w/ Perl
Message-Id: <968963710.562789@hpvablab.cup.hp.com>
abigail@foad.org writes:
>I've to wonder about such linear progressions. Mine is more (time going
>vertically, with the present downwards)
>
>
>ed/vi Awk sh .-------Pascal 68k *roff 1984
> | \ | / | .-Modula-II / | | X 1985
> | | | | | / X / | Simula67 | 1986
> | | | | | / Modpas | X | LaTeX 1987
> | | | | | / X | Miranda 6810 | 1988
> | | | | | / | X X | 1989
> | | | | | .-C / | | 1990
> | | | | +-' LPC | | 1991
> vile | | / /| /| | | 1992
> | \ |/ /.+--' | X | 1993
> | \||// | | |
> | Perl | | | 1995
> | | | | Javascript SQL | 1996
> | | | | X | |
> | | | | | Java | 1998
> | | | | | X | pic 1999
> V V V V V V V 2000
Hmm... the next time I rewrite my resume, I'm not listing languages the
old fashioned way anymore! =-)
Rich (forced to do some Ada in college. yeeeuck.)
--
Rich Rauenzahn ----------+xrrauenza@cup.hp.comx+ Hewlett-Packard Company
Technical Consultant | I speak for me, | 19055 Pruneridge Ave.
Development Alliances Lab| *not* HP | MS 46TU2
ESPD / E-Serv. Partner Division +--------------+---- Cupertino, CA 95014
------------------------------
Date: Thu, 14 Sep 2000 12:09:18 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: golf (Was Re: transliterating file names in a dir)
Message-Id: <MPG.142ac23d72cd95e598ad65@nntp.hpl.hp.com>
In article <slrn8s0qv0.ku0.abigail@alexandra.foad.org> on 14 Sep 2000
06:11:45 GMT, Abigail <abigail@foad.org> says...
> Abigail (abigail@foad.org) wrote on MMDLXXI September MCMXCIII in
> <URL:news:slrn8s0oli.ku0.abigail@alexandra.foad.org>:
> :: Stephen Kloder (stephenk@cc.gatech.edu) wrote on MMDLXXI September
> :: MCMXCIII in <URL:news:39C04B8C.48B38120@cc.gatech.edu>:
> :: --
> :: -- This is starting to look like a golf problem: Rename all filenames in the
> :: -- current directory so that all letters are lowercase, and all spaces are
> :: -- replaced with dashes.
> :: -- My submission:
> :: -- perl -e 'rename"$_",(tr/A-Z /a-z-/+1&&$_)for(<*>)'
> ::
> :: Saving 12 strokes:
> ::
> :: perl -e'rename"$_",y/ /-/x0|lc,for<*>'
>
> I missed the obvious obfuscation touch:
>
> perl -e'rename"$_",y, ,-,x0|lc,for<*>'
There are lots of cute touches in there, particularly the trailing null
unused argument instead of a space. (Why does this get by the two-
argument prototype for remane()?)
But I wonder why you waste two strokes to stringify the original
filename. Perl isn't the shell, so any interior spaces in the filename
don't cause any problems on interpolation.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 14 Sep 2000 14:40:58 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: golf (Was Re: transliterating file names in a dir)
Message-Id: <m31yym2245.fsf@dhcp11-177.support.tivoli.com>
Larry Rosler <lr@hpl.hp.com> writes:
> In article <slrn8s0qv0.ku0.abigail@alexandra.foad.org> on 14 Sep 2000
> 06:11:45 GMT, Abigail <abigail@foad.org> says...
> > I missed the obvious obfuscation touch:
> >
> > perl -e'rename"$_",y, ,-,x0|lc,for<*>'
>
> There are lots of cute touches in there, particularly the trailing null
> unused argument instead of a space. (Why does this get by the two-
> argument prototype for remane()?)
If you are referring to the "0", it isn't an unused argument, it is
the multiplier for the "x" operator. Presumably, this produces an
empty string that is the "|"'d with the result of "lc" to produce the
second argument to "rename".
> But I wonder why you waste two strokes to stringify the original
> filename. Perl isn't the shell, so any interior spaces in the filename
> don't cause any problems on interpolation.
Got me on the quotes... the only thing I could think of was that you
need the value of $_ before the transliteration is applied, and maybe
putting in a string is needed for that??? Doesn't seem like it would
be, though....
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Thu, 14 Sep 2000 20:37:09 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: golf (Was Re: transliterating file names in a dir)
Message-Id: <x77l8ehfrf.fsf@home.sysarch.com>
>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:
LR> In article <slrn8s0qv0.ku0.abigail@alexandra.foad.org> on 14 Sep 2000
LR> 06:11:45 GMT, Abigail <abigail@foad.org> says...
>> :: perl -e'rename"$_",y/ /-/x0|lc,for<*>'
>>
>> I missed the obvious obfuscation touch:
>>
>> perl -e'rename"$_",y, ,-,x0|lc,for<*>'
LR> There are lots of cute touches in there, particularly the trailing null
LR> unused argument instead of a space. (Why does this get by the two-
LR> argument prototype for remane()?)
i like it too especially the use of x. why do you think there are not
two args to rename? the first is the "$_" and the second is the lc of $_
after the tr is done.
the quoted $_ is to keep the original value intact for rename's first
arg (the old name) while the rest of the code mungs $_ to the new name.
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, 14 Sep 2000 13:50:05 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: golf (Was Re: transliterating file names in a dir)
Message-Id: <MPG.142ad9db4a4fdfe598ad6c@nntp.hpl.hp.com>
In article <m31yym2245.fsf@dhcp11-177.support.tivoli.com> on 14 Sep 2000
14:40:58 -0500, Ren Maddox <ren.maddox@tivoli.com> says...
+ Larry Rosler <lr@hpl.hp.com> writes:
+
+ > In article <slrn8s0qv0.ku0.abigail@alexandra.foad.org> on 14 Sep
+ > 2000 06:11:45 GMT, Abigail <abigail@foad.org> says...
+ > > I missed the obvious obfuscation touch:
+ > >
+ > > perl -e'rename"$_",y, ,-,x0|lc,for<*>'
+ >
+ > There are lots of cute touches in there, particularly the trailing
+ > null unused argument instead of a space. (Why does this get by the
+ > two-argument prototype for rename()?)
+
+ If you are referring to the "0", it isn't an unused argument, it is
+ the multiplier for the "x" operator. Presumably, this produces an
+ empty string that is the "|"'d with the result of "lc" to produce the
+ second argument to "rename".
No. I mean the nothingness that follows the comma before the 'for',
where 'normal' people would use a space.
+ > But I wonder why you waste two strokes to stringify the original
+ > filename. Perl isn't the shell, so any interior spaces in the
+ > filename don't cause any problems on interpolation.
+
+ Got me on the quotes... the only thing I could think of was that you
+ need the value of $_ before the transliteration is applied, and maybe
+ putting in a string is needed for that??? Doesn't seem like it would
+ be, though....
That is it. Though Perl evaluates the elements of a list left-to-right,
the values may be obtained via references. The pseudo-stringification
simply copies $_ to another variable.
$_ = 'Abc Def ';
print $_, "$_", y/ /-/ x 0 | lc;
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 14 Sep 2000 14:39:11 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: golf (Was Re: transliterating file names in a dir)
Message-Id: <MPG.142ae55d33dff53498ad6d@nntp.hpl.hp.com>
In article <x77l8ehfrf.fsf@home.sysarch.com> on Thu, 14 Sep 2000
20:37:09 GMT, Uri Guttman <uri@sysarch.com> says...
> >>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:
>
> LR> In article <slrn8s0qv0.ku0.abigail@alexandra.foad.org> on 14 Sep 2000
> LR> 06:11:45 GMT, Abigail <abigail@foad.org> says...
>
> >> :: perl -e'rename"$_",y/ /-/x0|lc,for<*>'
> >>
> >> I missed the obvious obfuscation touch:
> >>
> >> perl -e'rename"$_",y, ,-,x0|lc,for<*>'
>
> LR> There are lots of cute touches in there, particularly the trailing null
> LR> unused argument instead of a space. (Why does this get by the two-
> LR> argument prototype for remane()?)
>
> i like it too especially the use of x. why do you think there are not
> two args to rename? the first is the "$_" and the second is the lc of $_
> after the tr is done.
I can see the two arguments. So tell me about the comma before the
'for'. It seems like list context, with a trailing nothing before the
'for'.
print 'x', for 0;
works just fine, but I can't see how to parse it.
For that matter, so does this:
1, for 0;
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 14 Sep 2000 20:27:03 GMT
From: nospam@hairball.cup.hp.com (Richard J. Rauenzahn)
Subject: Re: grep in perl
Message-Id: <968963222.922538@hpvablab.cup.hp.com>
"Brad" <flyboy@optushome.com.au> writes:
>Hi,
> Well I can honestly say I know nothing of perl. The thing is I need a
>script, and I guess perl would be the answer.
It's certainly one answer, and a pretty good one.
> I need this script to do a "netstat -M |grep keyword" and then output each
>instance of this into another logfile...say output.log, complete with
>timestamp. If there is no instances of the keyword, then it should not
>output anything at all into the other log file. This is just so I can see
>who is doing things they should not be doing on the network at time
>intervals. I plan on executing this through cron.
Ok, sounds simple.
> As this is only relatively small, is there a simple way of doing this?
> Any help would be very much appreciated.
Ok, here's what you need to look at (at the minimum):
perldoc perlop (read up on backticks in Quote and Quote-like Operators)
perldoc -f open
perldoc -f print
A robust program would also use..
perldoc perlvar (read up on $! for error diagnostics)
perldoc -f open (read up on using | with open)
perldoc perlop (read up on =~ operator)
> Thanks.
> Brad
Give that a go, and if you still have problems, come back with what you
have so far and we can help you along,
Rich
p.s. Of course, just a crontab entry of
'netstat -M | grep key >> /var/log/foo' might be easier, but
then you wouldn't get to learn perl! =-)
--
Rich Rauenzahn ----------+xrrauenza@cup.hp.comx+ Hewlett-Packard Company
Technical Consultant | I speak for me, | 19055 Pruneridge Ave.
Development Alliances Lab| *not* HP | MS 46TU2
ESPD / E-Serv. Partner Division +--------------+---- Cupertino, CA 95014
------------------------------
Date: Thu, 14 Sep 2000 12:47:12 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: How do I sort a list of list by a certain column
Message-Id: <MPG.142acb1fe35346cb98ad68@nntp.hpl.hp.com>
In article <ub7w5.409$0j.136503@news.uswest.net> on Thu, 14 Sep 2000
09:39:54 -0700, Christopher M. Jones <christopher_j@uswest.net> says...
> "Malte Ubl" <ubl@schaffhausen.de> wrote:
...
> > I want to sort a list of lits by a certain column. An example would be
> > to sort a list of the names of all the members of a family by the third
> > member of the family.
> >
> > I have written my one little algorithm to do this, but it is fairly
> > slow, so I was wondering if there was a module to do this (havent found
> > anything at CPAN) or if anybody else had a nice way to do this.
>
> You should probably check the faq, there's a lot of helpful
> stuff in there (including about this). Basically, what you
> want it to use a hash and then use 'sort' to sort the keys
> of the hash.
>
> However, if you have duplicate key values, you could run into
> problems. I had a situation like this a while back and what
> I did to solve the problem was create a hash of arrays of
> index values to the original array (keyed by the column of
> data that I wanted to sort by). That way I was able to sort
> without clobbering the rows with the same key value.
Serious overkill. Wrong FAQ. There is no need for a hash at all.
Assuming the field to control the sort is the third element of each
sublist:
@sorted = sort { $a->[2] cmp $b->[2] } @unsorted;
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 14 Sep 2000 21:36:22 GMT
From: walter@ganymede.frii.com (Walter Pienciak)
Subject: HTML::LinkExtor and <applet> problem
Message-Id: <qxbw5.146$W3.135467520@news.frii.net>
Hi,
I'm using HTML::LinkExtor to extract links from some HTML documents.
Works pretty well.
But, when it hits an <applet> tag looking like
<applet codebase="./classes" code="Bounce">
which reflects an actual directory structure of ./classes/Bounce.class
it's not reporting back one link to
./classes/Bounce.class
or even one link to
./classes/Bounce
but rather 2 links to
./classes
Bounce
Any thoughts, ideas? Both HTML::LinkExtor and HTML::Parser are up to
date.
Walter
------------------------------
Date: Thu, 14 Sep 2000 11:54:47 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: I really need help !!!!
Message-Id: <MPG.142abed0ecde4ec98ad64@nntp.hpl.hp.com>
[You have quoted 86 lines of text in order to comment on one of them.
Please follow the accepted practice of this newsgroup (and mamy others),
by quoting only what you are commenting on, before your comment. I have
rearranged and snipped the post, to isolate the issue.]
In article <iN0w5.257$n4.17026@newsc.telia.net> on Thu, 14 Sep 2000
09:22:22 GMT, news@NOSPAMjstrom.cjb.net <news@NOSPAMjstrom.cjb.net>
says...
> "peter" <peterp100@hotmail.com> skrev i meddelandet
> news:j1t1sscggu9pappj4ocv3sfe67p3ttetr6@4ax.com...
...
> > >> print "Name = $Name, value = $Value<BR>\n";
> Try this:
>
> print "Name = $Name\, value = $Value\<BR>\n";
Did you try it before posting it? Except for including two superfluous
backslashes (in the code, but not in the printed output), they produce
identical results, so cannot solve whatever problem the original poster
has.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 14 Sep 2000 21:21:48 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: I really need help !!!!
Message-Id: <Pine.GHP.4.21.0009142106110.6979-100000@hpplus03.cern.ch>
On Thu, 14 Sep 2000, Larry Rosler addresses some would-be purveyor of
advice:
> [You have quoted 86 lines of text in order to comment on one of them.
It's a rather expensive, but IME almost 100% effective, bogosity
indicator. And taken in conjunction with the oh-so-expressive:
> > Try this:
the bogosity alarms are ringing practically out of their belfry.
Mind you, the original poster's choice of subject line wasn't exactly
calculated to attract good answers; now what happened to that FAQ
about choosing meaningful subject lines for one's posting?
all the best
------------------------------
Date: Thu, 14 Sep 2000 12:55:53 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Is there a good freeware/shareware IDE for PERL?
Message-Id: <MPG.142acd2215139ae998ad69@nntp.hpl.hp.com>
In article <39C0E5B8.6804A8FF@class.class.lviv.ua> on Thu, 14 Sep 2000
17:50:32 +0300, Victor Koldun <lkh@class.class.lviv.ua> says...
> I am into Perl programming for a long time, but I don't have the
> Internet at home and can't work on my scripts at home. Whereas the
> Internet class, where I have to work on them, keeps me for 5 minutes
> waiting for my script to get uploaded/executed... and the plain text
> editor seems to date back to early 70s. ANd I can't change anything,
> since I'm not the boss... :(
>
> Does anyone know of some good and freeware/shareware PERL IDE to build
> and debug scripts without the Internet access? Yeah I know I want too
> much! :) But the evergrowing amount of free cool software brings me
> hope...
Assuming you have a PC or equivalent, install Perl (from
http://www.activestate.com) and a web server (for example, from
http://www.apache.org), and you're on your way.
Most everyone just uses a text editor, not a Perl IDE. There are many
free text editors, but the only IDEs I know of are commercial products.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 14 Sep 2000 14:36:16 -0400
From: Keith Arner <karner@fore.com>
Subject: Iterate over greed?
Message-Id: <4FBEA8857476D311A03300204840E1CFCFBC6B-100000@whq-msgusr-02.pit.comms.marconi.com>
Consider the following code:
$_ = 'abc-defgh-ijk-lm-nop';
($a, $b) = m/(.*)-(.*)/;
print " [$a] [$b]\n";
In this case, the sub-expressions are greedy, and I'll (effectively) get:
[abc-defgh-ijk-lm] [nop]
At the opposite extreeme, if I change the first subexpression to be
non-greedy, I'll get:
[abc] [defgh-ijk-lm-nop]
Is there any way to iterate over greed? Can I write a regex which, when
used as the condition in a while() loop, will iterate over the possible
levels of greed that would match?
I would like to be able to do:
$_ = 'abc-defgh-ijk-lm-nop';
while ( m/(.*?!)-(.*?!)/g! ) {
print " [$a] [$b]\n";
}
...and get:
[abc-defgh-ijk-lm] [nop]
[abc-defgh-ijk] [lm-nop]
[abc-defgh] [ijk-lm-nop]
[abc] [defgh-ijk-lm-nop]
Where .*?! and /g! are hypothetical modifiers to make such a thing happen.
I realize that for this simple example, I could use:
while ( m/-/g ) {
print " [$`] [$']\n";
}
But $& and company are frowned upon, and I would prefer not to use them if
possible.
Thanks,
Keith
--
------------------------------
Date: Thu, 14 Sep 2000 20:02:04 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Iterate over greed?
Message-Id: <39c12ebc.3c5b$1c4@news.op.net>
In article <4FBEA8857476D311A03300204840E1CFCFBC6B-100000@whq-msgusr-02.pit.comms.marconi.com>,
>Is there any way to iterate over greed?
What you really mean is just that you want to find all the possible
matches.
> $_ = 'abc-defgh-ijk-lm-nop';
>
> while ( m/(.*?!)-(.*?!)/g! ) {
> print " [$a] [$b]\n";
> }
One would like to use /g here, but each match of /g picks up where the
previous one left off, so that doesn't work.
Here's a solution, although I have a nagging feeling that there is a
much easier way to do the same thing:
1 while m/^
(.*)-(.*)
$
(?{push @matches, [$1, $2]}) # Build data structure current match
(?!) # backtrack for another match
/x;
Now @matches contains information about all the matches. You can dump
it out like this:
for (@matches) {
my ($a, $b) = @$_;
print "$a $b\n";
}
or instead of building a data structure, you can make a subroutine
call with the information from the current match:
1 while m/^
(.*)-(.*)
$
(?{my_function($1, $2)}) # Build data structure current match
(?!) # backtrack for another match
/x;
sub my_function { print "@_\n" }
Caveat: This only works properly in perl 5.005_57 or later.
------------------------------
Date: 14 Sep 2000 14:04:12 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Iterate over greed?
Message-Id: <m37l8e23tf.fsf@dhcp11-177.support.tivoli.com>
Keith Arner <karner@fore.com> writes:
> I would like to be able to do:
>
> $_ = 'abc-defgh-ijk-lm-nop';
>
> while ( m/(.*?!)-(.*?!)/g! ) {
> print " [$a] [$b]\n";
> }
>
> ...and get:
>
> [abc-defgh-ijk-lm] [nop]
> [abc-defgh-ijk] [lm-nop]
> [abc-defgh] [ijk-lm-nop]
> [abc] [defgh-ijk-lm-nop]
>
> Where .*?! and /g! are hypothetical modifiers to make such a thing happen.
>
How 'bout something like this?:
$_ = 'abc-defgh-ijk-lm-nop';
my $tail = '.*';
print "[$1] [$2]\n" and $tail .= '-.*' while /(.*)-($tail)/;
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 14 Sep 2000 20:17:33 GMT
From: Adam Trace Spragg <spragg@cs.ucdavis.edu>
Subject: Re: Iterate over greed?
Message-Id: <8prbot$9nn$1@mark.ucdavis.edu>
Keith Arner <karner@fore.com> wrote:
: $_ = 'abc-defgh-ijk-lm-nop';
: while ( m/(.*?!)-(.*?!)/g! ) {
: print " [$a] [$b]\n";
: }
: ...and get:
: [abc-defgh-ijk-lm] [nop]
: [abc-defgh-ijk] [lm-nop]
: [abc-defgh] [ijk-lm-nop]
: [abc] [defgh-ijk-lm-nop]
How about splitting on '-'? Then you'd get each subfield in a list ("abc",
"defgh", etc), and you could maniuplate those to get the desired result...?
To answer your specific questions, I don't know a way to manipulate the greed
factor. Seems REs are either Greedy or Not, but not in between.
Adam
------------------------------
Date: Thu, 14 Sep 2000 20:22:23 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Iterate over greed?
Message-Id: <x7em2mhgg0.fsf@home.sysarch.com>
>>>>> "KA" == Keith Arner <karner@fore.com> writes:
KA> Consider the following code:
KA> $_ = 'abc-defgh-ijk-lm-nop';
KA> ($a, $b) = m/(.*)-(.*)/;
KA> print " [$a] [$b]\n";
KA> Is there any way to iterate over greed? Can I write a regex which, when
KA> used as the condition in a while() loop, will iterate over the possible
KA> levels of greed that would match?
MJD answered with a regex solution. my idea is to skip regexes
altogether and use index. given you problem, it is simple to run index
on '-' and loop until you don't find it anymore. building up the
substrings is easy with substr and i leave that as an exercise to you.
if you have a more complex regex than just '-' you could use split and
loop over the list of returned parts building up longer (greedier)
strings. again, i leave the coding to you.
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, 14 Sep 2000 13:37:14 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Iterate over greed?
Message-Id: <MPG.142ad6d9a8f6896598ad6a@nntp.hpl.hp.com>
In article <4FBEA8857476D311A03300204840E1CFCFBC6B-100000@whq-msgusr-
02.pit.comms.marconi.com> on Thu, 14 Sep 2000 14:36:16 -0400, Keith
Arner <karner@fore.com> says...
...
> I would like to be able to do:
>
> $_ = 'abc-defgh-ijk-lm-nop';
>
> while ( m/(.*?!)-(.*?!)/g! ) {
> print " [$a] [$b]\n";
> }
>
> ...and get:
>
> [abc-defgh-ijk-lm] [nop]
> [abc-defgh-ijk] [lm-nop]
> [abc-defgh] [ijk-lm-nop]
> [abc] [defgh-ijk-lm-nop]
A regex solution:
$_ = 'abc-defgh-ijk-lm-nop';
my $fields = tr/-//;
for (my $n = 0; $n < $fields; ++$n) {
my ($a, $b) = m/^((?:[^-]+-){$n}[^-]+)-(.*)/;
print " [$a] [$b]\n";
}
A split() solution:
my @a = split /-/;
for (my $n = 0; $n < $#a; ++$n) {
local $" = '-';
print " [@a[0 .. $n]] [@a[$n + 1 .. $#a]]\n";
}
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 14 Sep 2000 21:18:56 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: Iterate over greed?
Message-Id: <4hbw5.13020$Kp4.525277@news20.bellglobal.com>
Keith Arner <karner@fore.com> wrote:
: Consider the following code:
: $_ = 'abc-defgh-ijk-lm-nop';
: ($a, $b) = m/(.*)-(.*)/;
: print " [$a] [$b]\n";
: In this case, the sub-expressions are greedy, and I'll (effectively) get:
: [abc-defgh-ijk-lm] [nop]
: At the opposite extreeme, if I change the first subexpression to be
: non-greedy, I'll get:
: [abc] [defgh-ijk-lm-nop]
: Is there any way to iterate over greed? Can I write a regex which, when
: used as the condition in a while() loop, will iterate over the possible
: levels of greed that would match?
A way to do it would be
$_ = 'abc-defgh-ijk-lm-nop';
for( my $accum; /($accum(^|-)([^-]*))-(.*)$/; $accum = $1 )
{
print "[$1] [$+]\n";
}
but, frankly, I prefer the $`, $' solution. :)
Joy,
Yanick
--
eval" use 'that poor Yanick' ";
print map{ (sort keys %{{ map({$_=>1}split'',$@) }})[hex] }
qw/8 b 15 1 9 10 11 15 c b 13 1 12 b 13 f 1 c 9 a e b 13 0/;
------------------------------
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 4325
**************************************