[25706] in Perl-Users-Digest
Perl-Users Digest, Issue: 7946 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 6 03:05:35 2005
Date: Wed, 6 Apr 2005 00:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 6 Apr 2005 Volume: 10 Number: 7946
Today's topics:
Re: auto-deleted explcitily named temp files - possible <tzz@lifelogs.com>
Emacs modules for Perl programming (Jari Aalto+mail.perl)
erase element in array but keep the order <lskatz@gmail.com>
Re: erase element in array but keep the order <1usa@llenroc.ude.invalid>
Re: erase element in array but keep the order <jurgenex@hotmail.com>
Re: erase element in array but keep the order xhoster@gmail.com
Re: Help with a script.. <abigail@abigail.nl>
perl and shared memory <alex_the_hart@yahoo.com>
Perl on TRIPOD hosted sites..file uploading question.. <wdflannery@aol.com>
Re: Perl on TRIPOD hosted sites..file uploading questio <noreply@gunnar.cc>
Re: Perl on TRIPOD hosted sites..file uploading questio <segraves_f13@mindspring.com>
Re: Perl on TRIPOD hosted sites..file uploading questio <tadmc@augustmail.com>
Re: Perl on TRIPOD hosted sites..file uploading questio <wdflannery@aol.com>
Re: Perl on TRIPOD hosted sites..file uploading questio <segraves_f13@mindspring.com>
Re: Q: // and "magic" <jkrugman345@yahbitoo.com>
Re: Q: // and "magic" (Anno Siegel)
Re: Q: // and "magic" <notvalid@email.com>
Re: Q: // and "magic" <alex_the_hart@yahoo.com>
Re: Regular expression question. (MENTAT)
Re: Regular expression question. (MENTAT)
Re: Regular expression question. <1usa@llenroc.ude.invalid>
Re: Regular expression question. <postmaster@castleamber.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 05 Apr 2005 15:11:00 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: auto-deleted explcitily named temp files - possible?
Message-Id: <4n1x9pvy2j.fsf@lifelogs.com>
On 4 Apr 2005, odigity@gmail.com wrote:
> I want to be able to control access to resources (in this case, CPUs)
> by using named temp files. Imagine you have twenty dual-cpu hosts with
> shared mount points, and several applications that each run in a
> distributed fashion. I don't want two apps both running on host01 and
> ignoring the fact that host02 is free.
>
> So I came up with the idea that there would be a directory - say
> /resource - where files would be created indicating that the cpu in
> question is being used. For example, if an app starts and launches two
> processes on host01, saturating both CPUs, it would create
> /resource/host01.1 and /resource/host01.2, and then delete them when
> finished. That way apps can efficiently use processor resources with
> tempfiles as a super-simple communication mechanism.
>
> One requirement is that the lockfile automatically get deleted no
> matter what happened to the process. This is imperative, since if it
> is possible for a process to exit and leave the lockfile behind, other
> apps will continue to think that resource is in use and not use it.
> Now, the usual trick for this is creating the file then immediately
> unlinking it, but this technique leaves the file nameless, which
> defeats the purpose of having the file open.
>
> I can't find any other way to open a named file and guarantee that it
> is deleted when the process exits. Any ideas?
I think files are the wrong way to approach this. Over NFS or in any
other fashion, you'll run into lock timeouts, bugs, and
incompatibilities that will make it unpleasant. What happens if a
host crashes, for example, before the lock file it created is deleted?
Not to mention that you need the OS to speak NFS (so Windows won't
work unless you use Samba, and that's extra work again).
Using Perl or any other language, you can just broadcast (or
multicast, depending on your network setup) packets on the network
that tell all the other hosts what resources the current one is using.
Make the broadcast interval N seconds, and then if in 2.5*N seconds
you have not heard that a resource is used, you can assume that it's
not used. You don't need to know how many others are listening, the
broadcasts will be heard by everyone.
This is not really Perl-specific, but you can use Perl easily to
generate and listen for network broadcasts.
Ted
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
------------------------------
Date: 06 Apr 2005 04:44:48 GMT
From: <jari.aalto <AT> poboxes.com> (Jari Aalto+mail.perl)
Subject: Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_1112762666@rtfm.mit.edu>
Archive-name: perl-faq/emacs-lisp-modules
Posting-Frequency: 2 times a month
URL: http://tiny-tools.sourceforge.net/
Maintainer: Jari Aalto A T poboxes com
Announcement: "What Emacs lisp modules can help with programming Perl"
Preface
Emacs is your friend if you have to do anything comcerning software
development: It offers plug-in modules, written in Emacs lisp
(elisp) language, that makes all your programmings wishes come
true. Please introduce yourself to Emacs and your programming era
will get a new light.
Where to find Emacs/XEmacs
o Unix:
http://www.gnu.org/software/emacs/emacs.html
http://www.xemacs.org/
o Unix Windows port (for Unix die-hards):
install http://www.cygwin.com/ which includes native Emacs 21.x.
and XEmacs port
o Pure Native Windows port
http://www.gnu.org/software/emacs/windows/ntemacs.html
ftp://ftp.xemacs.org/pub/xemacs/windows/setup.exe
o More Emacs resources at
http://tiny-tools.sourceforge.net/ => Emacs resource page
Emacs Perl Modules
Cperl -- Perl programming mode
http://www.cpan.org/modules/by-authors/id/ILYAZ/cperl-mode/
http://math.berkeley.edu/~ilya/software/emacs/
by Ilya Zakharevich
CPerl is major mode for editing perl files. Forget the default
`perl-mode' that comes with Emacs, this is much better. Comes
standard in newest Emacs.
TinyPerl -- Perl related utilities
http://tiny-tools.sourceforge.net/
If you ever wonder how to deal with Perl POD pages or how to find
documentation from all perl manpages, this package is for you.
Couple of keystrokes and all the documentaion is in your hands.
o Instant function help: See documentation of `shift', `pop'...
o Show Perl manual pages in *pod* buffer
o Grep through all Perl manpages (.pod)
o Follow POD references e.g. [perlre] to next pod with RETURN
o Coloured pod pages with `font-lock'
o Separate `tiperl-pod-view-mode' for jumping topics and pages
forward and backward in *pod* buffer.
o Update `$VERSION' variable with YYYY.MMDD on save.
o Load source code into Emacs, like Devel::DProf.pm
o Prepare script (version numbering) and Upload it to PAUSE
o Generate autoload STUBS (Devel::SelfStubber) for you
Perl Module (.pm)
TinyIgrep -- Perl Code browsing and easy grepping
[TinyIgrep is included in Tiny Tools Kit]
To grep from all installed Perl modules, define database to
TinyIgrep. There is example file emacs-rc-tinyigrep.el that shows
how to set up dattabases for Perl5, Perl4 whatever you have
installed
TinyIgrep calls Igrep.el to to do the search, You can adjust
recursive grep options, set search case sensitivity, add user grep
options etc.
You can find latest `igrep.el' module at
<http://groups.google.com/groups?group=gnu.emacs.sources> The
maintainer is Jefin Rodgers <kevinr <AT> ihs.com>.
TinyCompile -- To Browse grep results in Emacs *compile* buffer
TinyCompile is a minor mode for *compile* buffer from where
you can collapse unwanted lines or shorten file URLs:
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file1:NNN: MATCHED TEXT
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file2:NNN: MATCHED TEXT
-->
cd /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/
file1:NNN: MATCHED TEXT
file1:NNN: MATCHED TEXT
End
------------------------------
Date: 5 Apr 2005 13:53:49 -0700
From: "Lee" <lskatz@gmail.com>
Subject: erase element in array but keep the order
Message-Id: <1112734429.388077.92830@o13g2000cwo.googlegroups.com>
I have an array of DNA sequences, ordered by length.
>From this, I want to be able to keep it ordered and just take out
selected sequences. Thus, shift or pop won't work. I'm not so sure
what splice does entirely, but I'm pretty sure it doesn't work either.
Does anyone have a suggestion on a function or algorithm? Thanks.
------------------------------
Date: Tue, 05 Apr 2005 21:00:57 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: erase element in array but keep the order
Message-Id: <Xns962FAD16BE7E5asu1cornelledu@127.0.0.1>
"Lee" <lskatz@gmail.com> wrote in news:1112734429.388077.92830
@o13g2000cwo.googlegroups.com:
> I have an array of DNA sequences, ordered by length.
> From this, I want to be able to keep it ordered and just take out
> selected sequences. Thus, shift or pop won't work. I'm not so sure
> what splice does entirely, but I'm pretty sure it doesn't work either.
Hmmm ... How are you 'pretty sure' splice doesn't do what you want if
you don't know what it does?
#! /usr/bin/perl
use strict;
use warnings;
my @t = (1 .. 20);
splice(@t, 8, 4);
print "@t\n";
__END__
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Tue, 05 Apr 2005 21:04:53 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: erase element in array but keep the order
Message-Id: <V3D4e.14147$Fh2.9245@trnddc04>
Lee wrote:
> I have an array of DNA sequences, ordered by length.
>> From this, I want to be able to keep it ordered and just take out
> selected sequences. Thus, shift or pop won't work.
Neither shift nor pop will alter the sequence of the rest of the array, so
yes, they "will work".
Of course it is very cumbersome to delete some arbitrary element from the
middle of an array using either one but that is a different issue.
> I'm not so sure
> what splice does entirely,
Then why don't you check the documentation for splice()?
> but I'm pretty sure it doesn't work either.
And why do you think so?
splice() doesn't alter the sequence the of the remaining elements of an
array, either.
> Does anyone have a suggestion on a function or algorithm?
Sure. Use splice().
jue
------------------------------
Date: 05 Apr 2005 21:10:51 GMT
From: xhoster@gmail.com
Subject: Re: erase element in array but keep the order
Message-Id: <20050405171051.085$5i@newsreader.com>
"Lee" <lskatz@gmail.com> wrote:
> I have an array of DNA sequences, ordered by length.
> From this, I want to be able to keep it ordered and just take out
> selected sequences.
"selected" how?
> Thus, shift or pop won't work. I'm not so sure
> what splice does entirely, but I'm pretty sure it doesn't work either.
If you mean "selected" by index, then of course splice works. It is linear
time in the size of the array, but it is a very fast linear time.
splice @array,$selected_index,1;
> Does anyone have a suggestion on a function or algorithm? Thanks.
The best choice of algorithm probably depends on why you (think you) need
to keep it sorted by length. But often you don't need the best choice of
algorithm, just a good enough one will be good enough.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 05 Apr 2005 23:37:31 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Help with a script..
Message-Id: <slrnd5689r.u4c.abigail@alexandra.abigail.nl>
Felix Geerinckx (felix.geerinckx@gmail.com) wrote on MMMMCCXXXV September
MCMXCIII in <URL:news:xn0e0mxv425phh000@news.easynews.com>:
][ On 05/04/2005, Abigail wrote:
][
][ > Felix Geerinckx (felix.geerinckx@gmail.com) wrote on MMMMCCXXXIV
][ > September MCMXCIII in <url: news:xn0e0lj3e1r1u3000@news.easynews.com>:
][ > ~~ $shortyear = '04';
][ > ~~
][ > ~~ could mean any of
][ > ~~
][ > ~~ $longyear = '1904';
][ > ~~ $longyear = '2004';
][ > ~~ $longyear = '2104';
][ > ~~
][ > ~~ etc.
][ >
][ > Not in this case. The OP defined '04' to be 2004. Given that it's a
][ > timestamp, 2104 isn't logical, as it's only 2005, and neither is 1904.
][ > There was a shortage of computers in 1904.
][
][ You are right, of course, but isn't it about making one's programs
][ future proof?
Making it future proof starts by not assuming. If it's *defined* that
04 is 2004, you _break_ your program by assuming 04 is in any other
century. A program should never ever change assuming what the data means
if the data doesn't change.
][ And speaking of dates, would you care to share why you stopped using
][ the standard calendar in Sept 1993?
No. Use google.
Abigail
--
$_ = "\x3C\x3C\x45\x4F\x54" and s/<<EOT/<<EOT/e and print;
Just another Perl Hacker
EOT
------------------------------
Date: 5 Apr 2005 23:02:21 -0700
From: "Alex Hart" <alex_the_hart@yahoo.com>
Subject: perl and shared memory
Message-Id: <1112765753.934429.222030@f14g2000cwb.googlegroups.com>
I just can't get my head around shared memory.
I am writing a mail server in perl which uses Mail::SpamAssassin.
Spamassassin adds about 9Mb to the memory size of the server. The
question is, am I duplicating this 9Mb each time I fork a new server?
Or does perl use the same memory for both processes?
This is a partial output from running top:
SIZE RSS SHARE COMMAND
15888 15M 14916 SMTP Server
Since nearly all the memory used by the server is in the share column,
does that mean that the overhead in forking a process is very low? I'm
skeptical that each new server requires less than 1Mb of memory. Will
my performance increase if I use a separate SpamAssassin server, or is
this as efficient as it gets?
- Alex Hart
------------------------------
Date: 5 Apr 2005 13:09:31 -0700
From: "joesplink" <wdflannery@aol.com>
Subject: Perl on TRIPOD hosted sites..file uploading question..
Message-Id: <1112731770.987450.106940@g14g2000cwa.googlegroups.com>
www.tripod.com has free web hosting with CGI and PERL, however there
may be some limitations. I've got a PERL program that I use on another
host to upload files..... and it works fine.... however, it doesn't
work on my TRIPOD hosted site.....I asked support at TRIPOD about this
but didn't get a response....(I've asked them again)....
------------------------------
Date: Tue, 05 Apr 2005 22:34:13 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Perl on TRIPOD hosted sites..file uploading question..
Message-Id: <3bgb09F6f8o7vU1@individual.net>
joesplink wrote:
> www.tripod.com has free web hosting with CGI and PERL, however there
> may be some limitations. I've got a PERL program that I use on another
> host to upload files..... and it works fine.... however, it doesn't
> work on my TRIPOD hosted site.....I asked support at TRIPOD about this
> but didn't get a response....(I've asked them again)....
You don't have a file uploading question; you have problems with
installing a script. This newsgroup is for discussing Perl programming
matters, not for providing free assistance with installing scripts.
Anyway, this document may provide some useful info:
http://my.execpc.com/~keithp/bdlogcgi.htm
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 06 Apr 2005 00:07:58 GMT
From: "Bill Segraves" <segraves_f13@mindspring.com>
Subject: Re: Perl on TRIPOD hosted sites..file uploading question..
Message-Id: <yLF4e.4332$44.3712@newsread1.news.atl.earthlink.net>
"joesplink" <wdflannery@aol.com> wrote in message
news:1112731770.987450.106940@g14g2000cwa.googlegroups.com...
> www.tripod.com has free web hosting with CGI and PERL, however there
> may be some limitations.
You may benefit from reading the CGI Support Field Guide at
http://www.tripod.lycos.com/guides/cgi.html to identify the limitation, if
any, that is causing your problem.
> I've got a PERL program that I use on another
> host to upload files..... and it works fine.... however, it doesn't
> work on my TRIPOD hosted site.....I asked support at TRIPOD about this
> but didn't get a response....(I've asked them again)....
>
It's not surprising you received no response. You should help yourself by
providing, e.g., the error messages you received, as well as the code for a
small program that exhibits the same "doesn't work" problem you're having
with Tripod.
If you're using CGI.pm, what is the version of CGI.pm that you've installed
at Tripod? Last time I checked, Tripod was not providing a recent version.
--
Bill Segraves
------------------------------
Date: Tue, 5 Apr 2005 18:26:07 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Perl on TRIPOD hosted sites..file uploading question..
Message-Id: <slrnd567kf.5s3.tadmc@magna.augustmail.com>
joesplink <wdflannery@aol.com> wrote:
> www.tripod.com has free web hosting
> I asked support at TRIPOD about this
> but didn't get a response.
Looks like you got what you paid for.
Anyway, did you mean to ask a Perl question?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 5 Apr 2005 19:04:04 -0700
From: "joesplink" <wdflannery@aol.com>
Subject: Re: Perl on TRIPOD hosted sites..file uploading question..
Message-Id: <1112751241.515395.211190@o13g2000cwo.googlegroups.com>
TRIPOD has their own version of GCI, called TripodCGI....they don't
provide any documentaton.
They specifically state that they don't help debugging Perl .... fair
enough...besides..there was no error msg.... the first read failed and
no bytes were transferred....
My guess is that they don't support it, and I thought someone on this
group might know.....
I also thought it might be interesting to the general reader that
Tripod provides free web hosting for sites using
Perl................great for learning, experimenting .... but not with
file uploads I think.....
------------------------------
Date: Wed, 06 Apr 2005 04:24:16 GMT
From: "Bill Segraves" <segraves_f13@mindspring.com>
Subject: Re: Perl on TRIPOD hosted sites..file uploading question..
Message-Id: <QvJ4e.1621$sp3.482@newsread3.news.atl.earthlink.net>
"joesplink" <wdflannery@aol.com> wrote in message
news:1112751241.515395.211190@o13g2000cwo.googlegroups.com...
> TRIPOD has their own version of GCI, called TripodCGI....they don't
> provide any documentaton.
>
Not exactly. While Tripod DOES have a module called TripodCGI, it is not a
version of the CGI module, which they also provide. They DO provide
documentation for their modules, but not for CGI.pm (for reasons they've
stated).
Dig a bit more and you'll find the CGI module. Hint: Click on the Script
Editor Quick Link, after which you'll see a link to Tripod's CGI Guide. If
you're still stumped, here's a direct link:
http://www.tripod.lycos.com/guides/cgi.html
> They specifically state that they don't help debugging Perl .... fair
> enough...besides..there was no error msg.... the first read failed and
> no bytes were transferred....
>
ISTM, if there was no error message, you didn't ask for any.
> My guess is that they don't support it, and I thought someone on this
> group might know.....
>
They DO support file uploading. You might examine the file manager interface
to see how they do it.
> I also thought it might be interesting to the general reader that
> Tripod provides free web hosting for sites using
> Perl................great for learning, experimenting .... but not with
> file uploads I think.....
>
You have argued so strongly for your limitations that they have become real.
IMO, that's not a good thing to do. If you think you can't, you're right.
;-)
I don't see a Perl question here, so I'm entering end-of-thread mode.
--
Bill Segraves
------------------------------
Date: Tue, 5 Apr 2005 18:20:23 +0000 (UTC)
From: J Krugman <jkrugman345@yahbitoo.com>
Subject: Re: Q: // and "magic"
Message-Id: <d2ukt7$fmb$1@reader1.panix.com>
In <20050405125614.353$RT@newsreader.com> xhoster@gmail.com writes:
>"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote:
>>
>> In the context of the split function, // matches the empty string.
>>
>> Elsewhere, // means the last successful pattern match.
>>
>> IMHO, the passage above is very clear, but here is the relevant section
>> from perldoc perlop (where m// is being discussed):
>>
>> If the PATTERN evaluates to the empty string, the last
>> *successfully* matched regular expression is used instead. In
>> this case, only the "g" and "c" flags on the empty pattern is
>> honoured - the other flags are taken from the original pattern.
>> If no match has previously succeeded, this will (silently) act
>> instead as a genuine empty pattern (which will always match).
>So, does anyone find this behavior useful? I've never intentionally used
>it, and I can't imagine doing so in the future.
I think this may have something to do with my confusion: I have
never seen // used in any situation in which it wasn't clearly
intended to match the empty string, as in split //, ... . It would
be great to se a meaningful example.
jill
--
To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.
------------------------------
Date: 5 Apr 2005 22:17:29 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Q: // and "magic"
Message-Id: <d2v2pp$pre$1@mamenchi.zrz.TU-Berlin.DE>
Chris Mattern <matternc@comcast.net> wrote in comp.lang.perl.misc:
> A. Sinan Unur wrote:
>
> > xhoster@gmail.com wrote in news:20050405125614.353$RT@newsreader.com:
> >
> >> "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote:
> >>>
> >>> In the context of the split function, // matches the empty string.
> >>>
> >>> Elsewhere, // means the last successful pattern match.
> >>>
> >>> IMHO, the passage above is very clear, but here is the relevant
> >>> section from perldoc perlop (where m// is being discussed):
> >>>
> >>> If the PATTERN evaluates to the empty string, the last
> >>> *successfully* matched regular expression is used instead. In
> >>> this case, only the "g" and "c" flags on the empty pattern is
> >>> honoured - the other flags are taken from the original pattern.
> >>> If no match has previously succeeded, this will (silently) act
> >>> instead as a genuine empty pattern (which will always match).
> >>
> >> So, does anyone find this behavior useful? I've never intentionally
> >> used it, and I can't imagine doing so in the future.
> >
> > At the risk of sounding like an AOLer, I am curious as well. I tried
> > thinking of a way to use this feature. Couldn't think of anything, but
> > that is probably a reflection of my limitations :)
> >
> > I have a feeling Abigail might contribute some magic.
> >
> If you have an "untaint this" regexp, you might wind up using several
> times in a row on several variables. But mostly, I think this was
> Larry getting a little overenthusiastic in "save the programmer
> keystrokes" mode. And once it was around for awhile, of course it
> couldn't be taken out because it would break stuff.
I'm inclined to believe it was at some stage meant to be the last
successfully *compiled* regex that set //. That would make much more
sense as a keystroke-saver, though still somewhat obscure.
As it is, it could be used to choose a regex from a selection by
matching them against a test string (or more), then using //. There
are clearer, not much longer ways to do that, even without qr//.
It's a misfeature and no one uses it.
Anno
------------------------------
Date: Tue, 05 Apr 2005 22:53:26 GMT
From: Ala Qumsieh <notvalid@email.com>
Subject: Re: Q: // and "magic"
Message-Id: <GFE4e.9715$FN4.8077@newssvr21.news.prodigy.com>
xhoster@gmail.com wrote:
> So, does anyone find this behavior useful? I've never intentionally used
> it, and I can't imagine doing so in the future.
I have used it and have seen it used before, but only in the context of
Perl Golf to save some chars. Of course, in real production code, I
would strongly advise against using it since it can easily lead to
confusion and has no real advantage.
--Ala
------------------------------
Date: 5 Apr 2005 23:05:52 -0700
From: "Alex Hart" <alex_the_hart@yahoo.com>
Subject: Re: Q: // and "magic"
Message-Id: <1112766502.126555.292900@z14g2000cwz.googlegroups.com>
> So, does anyone find this behavior useful? I've never intentionally
used
> it, and I can't imagine doing so in the future.
I use this all the time.
This can be used instead of the "o" option. Meaning the regex will not
be recompiled each time perl sees it. If perl sees a string inside a
regex, it will recompile it each time, even if the string hasn't
changed. If you set the "o" option, then it is fixed for the whole
program, once it is compiled. Using // can avoid perl recompiling each
time, but the string can still change later.
Here's an example
sub Search { # search a list of names for a string
my ($string) = @_;
$string =~ /$string/i;
foreach (@list_of_names) {
if (//) {
push @found, $_;
}
}
}
Now, the regex is only compiled once each time the function is called.
With the "o" flag, running Search() twice would search for the same
string twice.
There are other ways to achieve the same thing, but I like //.
Hope that makes sense.
- Alex Hart
------------------------------
Date: 5 Apr 2005 20:58:06 -0700
From: chaitanyag@hotmail.com (MENTAT)
Subject: Re: Regular expression question.
Message-Id: <5a286c02.0504051958.7eaa7f0@posting.google.com>
Thanks Guys. It works with the input record seperator. That was the
missing key. The following code works.
$required_pattern = "(\\|Line 4)";
if (-e $file_name)
{
open (THEFILE, $file_name) or die "Unable to open file $file_name";
$/ = "<<<<<<<\n"; #set the input record seperator to this string.
while (<THEFILE>)
{
if ($_ =~ m/$required_pattern/ms)
{
print $_;
}
}
close (THEFILE);
}
Thanks again ...
Tad McClellan <tadmc@augustmail.com> wrote in message news:<slrnd555v6.4mj.tadmc@magna.augustmail.com>...
> MENTAT <chaitanyag@hotmail.com> wrote:
>
> > I have a log file that looks something like this
> >
> > 2005-03-29 17:17:11.293|DEBUG|Line 1|
> >>>>>>>>
> > Actual Log output line 1
> > Actual Log output line 2
> > Actual Log output line 3
> > Actual Log output line ...
> ><<<<<<<
> > 2005-03-29 17:17:11.293|DEBUG|Line 9|
> >>>>>>>>
> > Actual Log output line 1
> > Actual Log output line 2
> > Actual Log output line 3
> > Actual Log output line ...
> ><<<<<<<
>
>
> > I am trying to write a regular expression that extracts all the log
> > entries for a given value of "Line".
>
>
> Would a much easier way that makes no use of regular expressions be OK?
>
>
> > Ofcourse, if i remove the s global modifier, i can easily match it
> > using "(^.*\|Line 4.*)", but then I can't get all the (variable) lines
> > between <<<<<<< and >>>>>>>. The .* won't match across new line.
>
>
> There are several ways to write "any character" (which includes
> newline) that remain unaffected by the m//s modifier.
>
> [\000-\0377]
> [\d\D]
> [\w\W]
> [\s\S]
>
>
> > Any idea how this problem could be solved?
>
>
> Setting
>
> $/ = "<<<<<<<\n";
>
> before reading the input would help a lot.
------------------------------
Date: 5 Apr 2005 21:04:20 -0700
From: chaitanyag@hotmail.com (MENTAT)
Subject: Re: Regular expression question.
Message-Id: <5a286c02.0504052004.6e915de9@posting.google.com>
PS: Tad, what was the other approach that doesn't use regular expressions?
Tad McClellan <tadmc@augustmail.com> wrote in message news:<slrnd555v6.4mj.tadmc@magna.augustmail.com>...
> MENTAT <chaitanyag@hotmail.com> wrote:
>
> > I have a log file that looks something like this
> >
> > 2005-03-29 17:17:11.293|DEBUG|Line 1|
> >>>>>>>>
> > Actual Log output line 1
> > Actual Log output line 2
> > Actual Log output line 3
> > Actual Log output line ...
> ><<<<<<<
> > 2005-03-29 17:17:11.293|DEBUG|Line 9|
> >>>>>>>>
> > Actual Log output line 1
> > Actual Log output line 2
> > Actual Log output line 3
> > Actual Log output line ...
> ><<<<<<<
>
>
> > I am trying to write a regular expression that extracts all the log
> > entries for a given value of "Line".
>
>
> Would a much easier way that makes no use of regular expressions be OK?
>
>
> > Ofcourse, if i remove the s global modifier, i can easily match it
> > using "(^.*\|Line 4.*)", but then I can't get all the (variable) lines
> > between <<<<<<< and >>>>>>>. The .* won't match across new line.
>
>
> There are several ways to write "any character" (which includes
> newline) that remain unaffected by the m//s modifier.
>
> [\000-\0377]
> [\d\D]
> [\w\W]
> [\s\S]
>
>
> > Any idea how this problem could be solved?
>
>
> Setting
>
> $/ = "<<<<<<<\n";
>
> before reading the input would help a lot.
------------------------------
Date: Wed, 06 Apr 2005 04:15:57 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Regular expression question.
Message-Id: <Xns96302B52AEF7asu1cornelledu@127.0.0.1>
chaitanyag@hotmail.com (MENTAT) wrote in
news:5a286c02.0504051958.7eaa7f0@posting.google.com:
[ top-posting fixed. please don't do that. ]
> Tad McClellan <tadmc@augustmail.com> wrote in message
> news:<slrnd555v6.4mj.tadmc@magna.augustmail.com>...
>> MENTAT <chaitanyag@hotmail.com> wrote:
...
>> > I am trying to write a regular expression that extracts all the log
>> > entries for a given value of "Line".
...
>> Setting
>>
>> $/ = "<<<<<<<\n";
>>
>> before reading the input would help a lot.
> Thanks Guys. It works with the input record seperator. That was the
> missing key. The following code works.
use strict;
use warnings;
> $required_pattern = "(\\|Line 4)";
my $required_pattern = '(\|Line 4)';
Why are you capturing?
> if (-e $file_name)
This is a useless test.
> {
> open (THEFILE, $file_name) or die "Unable to open file $file_name";
Because open will fail if the file does not exist. BTW, you should
include the reason open failed in the error message:
open my $file, '<', $file_name
or die "Unable to open file $file_name: $!";
> if ($_ =~ m/$required_pattern/ms)
By default, m// matches against $_, so no need to explicitly specify it.
What do you think using both the m and s options for the match above
achieves?
From perldoc perlop:
m Treat string as multiple lines.
s Treat string as single line.
Which one is it?
> {
> print $_;
> }
The whole thing can be written as
print if /$required_pattern/ose;
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: 6 Apr 2005 04:31:14 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Regular expression question.
Message-Id: <Xns962FEF0A9564Ecastleamber@130.133.1.4>
MENTAT wrote:
> PS: Tad, what was the other approach that doesn't use regular
> expressions?
Not Tad, but perldoc -f index
print if index( $_, '\\' ) >= 0 or index( $_, 'Line 4' ) >= 0;
The order of the index calls can make a difference :-)
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V10 Issue 7946
***************************************