[25506] in Perl-Users-Digest
Perl-Users Digest, Issue: 7750 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 7 18:10:30 2005
Date: Mon, 7 Feb 2005 15:10:20 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 7 Feb 2005 Volume: 10 Number: 7750
Today's topics:
Re: Exception handling in class: question (Anno Siegel)
Re: Exception handling in class: question <mjl69mjl69@myaccmyacc.net>
Re: Exception handling in class: question (Anno Siegel)
Re: greediness problem? <tintin@invalid.invalid>
ithreads + signals on modern Unices <Thomas.Jahns@epost.de>
Re: memory for regex engine xhoster@gmail.com
Re: memory for regex engine <abigail@abigail.nl>
Re: nntp scan <tadmc@augustmail.com>
one more IP addr regexp (Vasily Pomuran)
Re: one more IP addr regexp <tintin@invalid.invalid>
Re: one more IP addr regexp <matternc@comcast.net>
Re: one more IP addr regexp <noreply@gunnar.cc>
Re: one more IP addr regexp <matternc@comcast.net>
Re: one more IP addr regexp <noreply@gunnar.cc>
Re: one more IP addr regexp <abigail@abigail.nl>
Re: Perl - permute? <postmaster@castleamber.com>
Re: Perl - permute? <phaylon@dunkelheit.at>
Re: Perl - permute? xhoster@gmail.com
Re: Perl - permute? greymaus@yahoo.com
Re: Perl - permute? xhoster@gmail.com
Re: Perl - permute? <postmaster@castleamber.com>
Re: Perl - permute? <dtrudgett@holdthespam_yahoo.com>
Re: Perl - permute? (Anno Siegel)
Perl's strengths: How well does Python do them? <john_sips_teaz@yahooz.com>
Re: Perl's strengths: How well does Python do them? <ulrich.herbst@gmx.de>
Re: Perl's strengths: How well does Python do them? <abigail@abigail.nl>
should be simple..but eh Can you help <tallstyk@yahoo.com>
Re: should be simple..but eh Can you help <toreau@gmail.com>
Re: should be simple..but eh Can you help <1usa@llenroc.ude.invalid>
Re: should be simple..but eh Can you help <mritty@gmail.com>
Re: should be simple..but eh Can you help <noreply@gunnar.cc>
To compare dates in a script clearguy02@yahoo.com
Re: To compare dates in a script <emschwar@fc.hp.com>
Re: To compare dates in a script <1usa@llenroc.ude.invalid>
Re: Why aren't 'warnings' on by default? (Anno Siegel)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 7 Feb 2005 16:59:37 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Exception handling in class: question
Message-Id: <cu86pp$ef5$1@mamenchi.zrz.TU-Berlin.DE>
mjl69 <mjl69mjl69@myaccmyacc.net> wrote in comp.lang.perl.misc:
[snip]
> Note, that I was talking about exception handling and not error
> handling.
What *is* the relation between errors and exceptions? That's a serious
question. I do have some ideas, but nothing I'd like to pontificate
about.
The question in your text was (embedded comments)
### Is error handling ok or...
### Is this better?
so you don't seem to be too sure of the distinction either.
> I may be wrong, but I had
> the idea that my objects should not crash because of a fatal error, but
Methods crash, objects don't.
> continue and save the error
> description to a string, array, or file and possibly take additional
Gee, a file? If you have an object, give it an error slot and put
the error message there.
> action based on the exception.
That's an age-old question. A purist would say, no module (class or
otherwise) should die on the user unless specifically requested. The
decision should be up to the user. Recursively this means that the
decision always ends up in the main program.
Even if the module can't possibly do something useful in a situation,
the user may have an alternative approach, or just not care that much.
(Module authors can hardly imagine that. Don't I know it.)
Then again, that burdens users with having to check every time whether
they got what they asked for. The purist may be fundamentally right,
as purists are wont to be, but the user may not be grateful for the
freedom of choice.
Now, just because of "eval", the decision to die in a module isn't
as final as it seems. The user can re-gain control if needed. That
makes it possible to die in an error situation and still not give up
the purists demand, it's only harder. So in Perl, I'd say it's a
case-to-case decision.
If something is called in many places, is likely to be part of expressions,
is used in an overloaded operator, is high level, consider dying (croak)
in an error situation. If it is called in only one or two places, is
called in isolation, is low level, consider signalling an error (usually
by returning nothing: "return;") and providing a message.
To see how a potential user is going to call your code, use your crystal
ball. Sorry, no pat solution here.
Anno
------------------------------
Date: 7 Feb 2005 17:27:53 GMT
From: mjl69 <mjl69mjl69@myaccmyacc.net>
Subject: Re: Exception handling in class: question
Message-Id: <36pmopF53t8vqU1@individual.net>
...
>
> Now, just because of "eval", the decision to die in a module isn't
> as final as it seems. The user can re-gain control if needed. That
> makes it possible to die in an error situation and still not give up
> the purists demand, it's only harder. So in Perl, I'd say it's a
> case-to-case decision.
>
> If something is called in many places, is likely to be part of expressions,
> is used in an overloaded operator, is high level, consider dying (croak)
> in an error situation. If it is called in only one or two places, is
> called in isolation, is low level, consider signalling an error (usually
> by returning nothing: "return;") and providing a message.
>
> To see how a potential user is going to call your code, use your crystal
> ball. Sorry, no pat solution here.
>
> Anno
>
>
You're right, I am guilty of confusing the two. I did finally go with an array that is a class member to store specific error messages:
sub new
{
my $invocant = shift;
my $dbh = shift;
my $class = ref($invocant) || $invocant; # Object or class name
my $self = { };
$self->{_error} = [ ]; # to push errors into
bless($self, $class);
return $self;
}
and a sample of handling errors (not fully tested yet):
my @return = $dbh->selectrow_array( $query);
push @{$invocant->{_error}}, now().'DBI: '.$dbh->errstr if $dbh->err; #save DBI error to array
if ( not @return ) #save 'record not found' error to array
{
push @{$invocant->{_error}}, now().
'Record not found for: '.$querystring;
return undef;
}
I guess exceptions were not really my biggest issue after all. Sorry for the confusion and the poorly stated question.
I mostly needed a way to return undef for unsuccessful operations and still have access to detailed error information
for debugging. Thanks for your excellent detailed response.
mjl
------------------------------
Date: 7 Feb 2005 18:04:29 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Exception handling in class: question
Message-Id: <cu8ajd$har$1@mamenchi.zrz.TU-Berlin.DE>
mjl69 <mjl69mjl69@myaccmyacc.net> wrote in comp.lang.perl.misc:
[error/exception handling]
> You're right, I am guilty of confusing the two. I did finally go with
> an array that is a class member to store specific error messages:
What you call a class member it would call a field (or variable, or even
member) of the *object*. Oh well, OO terminology is funky.
[snip code]
> and a sample of handling errors (not fully tested yet):
>
> my @return = $dbh->selectrow_array( $query);
> push @{$invocant->{_error}}, now().'DBI: '.$dbh->errstr if $dbh->err;
> #save DBI error to array
> if ( not @return ) #save 'record not found' error to array
> {
> push @{$invocant->{_error}}, now().
> 'Record not found for: '.$querystring;
> return undef;
> }
Just one point. It is usually better to signal an error by returning
nothing instead of returning undef. It's how *you* recognize the error,
the user should be able to do the same:
if ( my @result = $obj->meth( ...) ) {
# use @result
} else {
my $msg = $obj->error;
# deal with error
}
That doesn't work when you "return undef;". Use just "return;" or make
it explicit: "return ();"
Anno
------------------------------
Date: Tue, 8 Feb 2005 09:26:37 +1300
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: greediness problem?
Message-Id: <36q14hF54n690U1@individual.net>
"justme" <eight02645999@yahoo.com> wrote in message
news:c0837966.0502070228.2a08e737@posting.google.com...
> hi
>
> i have an initial string such as
> $initial = "qqqqqqqq";
> a user needs to input another string
> $string =<STDIN>;
> If this user were to key in exactly 8 q's then it will match and do
> something.
> But i have a problem when the user key in 5 or 6 q's, it will still
> match, which i do not want.
> how can i overcome this problem..?
Don't use a regex (although you haven't showed us what you actually tried)
Assuming you did a
chomp $string;
then you can do
if ($initial eq $string) {
...
}
------------------------------
Date: 07 Feb 2005 23:31:38 +0100
From: Thomas Jahns <Thomas.Jahns@epost.de>
Subject: ithreads + signals on modern Unices
Message-Id: <87ekfsypbp.fsf@ID-48333.user.dfncis.de>
I wish to make a background application I told to 'use threads;' also
react nicely to a SIGHUP (and reread configuration). perldoc perlthrtut
tells me not to mix signals and ithreads but the other aspects to
consider are as follows:
- I don't care for portability to Win32, pre-X MacOS, MVS or whatever
platforms may also provide a Perl implementation. I just need the
program to run on relatively modern Unices (i.e. pthreads and POSIX
sigaction will be available).
- perlthrtut also tells me 'use Thread;' will break real soon and isn't
so great to begin with, and Thread::Queue which my program already
uses is--surprise--not meant to work with Thread but threads anyway.
So I seek a description of signal semantics for the systems outlined
when using ithreads. Is there such documentation available? I searched
but apart from the Perl source couldn't find anything useful (not that I
didn't get many google hits, but what I got was either outdated or a
repetition of the message from perlthrtut).
Since the I really like the ease at which Perl allows me to write
programs for Unix/Linux I'd really hate to turn my program into ten
times the number of code lines of C.
Thomas Jahns
--
"Computers are good at following instructions,
but not at reading your mind."
D. E. Knuth, The TeXbook, Addison-Wesley 1984, 1986, 1996, p. 9
------------------------------
Date: 07 Feb 2005 17:45:54 GMT
From: xhoster@gmail.com
Subject: Re: memory for regex engine
Message-Id: <20050207124554.121$cD@newsreader.com>
"Mark" <admin@asarian-host.net> wrote:
> Hello,
>
> Running FreeBSD 4.10, can someone tell me how to increase the memory for
> the regex engine on Perl 5.8.5? I have a process with some extremely
> complex regex-es, working on some extremely long strings (about 40MB). If
> the string size becomes too large, Perl seems to hang (stuck in R =
> runnable process).
>
> Apart from the optimizations I could make in the regex-es, still, it
> bothers me Perl may hang this way. Is there a way I can increase the
> memory for the regex engine?
This doesn't sound like a memory problem. Programs that run out of memory
usually die, not hang. If a complex regex requires large amounts of
memory, it almost certainly requires very large amounts of time.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 07 Feb 2005 22:12:41 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: memory for regex engine
Message-Id: <slrnd0fpuo.g2.abigail@alexandra.abigail.nl>
Mark (admin@asarian-host.net) wrote on MMMMCLXXVIII September MCMXCIII in
<URL:news:qaWdneFChqwUYJvfRVnyhw@giganews.com>:
?? Hello,
??
?? Running FreeBSD 4.10, can someone tell me how to increase the memory for
?? the regex engine on Perl 5.8.5? I have a process with some extremely
?? complex regex-es, working on some extremely long strings (about 40MB). If
?? the string size becomes too large, Perl seems to hang (stuck in R =
?? runnable process).
??
?? Apart from the optimizations I could make in the regex-es, still, it
?? bothers me Perl may hang this way. Is there a way I can increase the
?? memory for the regex engine? I have 1.5 G of physical memory. Could this
?? perhaps be related to the OS 'datasize' limit (set to 512 MB here)? Perl
?? does not throw an error, actually.
Perl will malloc the memory it needs all by itself. The only limits will
has will be imposed by the kernel.
?? I appreciate any suggestions,
What makes you think it's a memory problem? Perhaps the regex is
complicated and just takes a long time to complete? It's not too hard to
write a regex which, when matched against a 40Mb string, takes a couple
of millenia to decide there wasn't a match.
Abigail
--
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'
------------------------------
Date: Mon, 7 Feb 2005 09:13:57 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: nntp scan
Message-Id: <slrnd0f1dl.r9t.tadmc@magna.augustmail.com>
ruud <geen@mail.invalid> wrote:
> use News::Scan;
> my $posters = $scan->posters;
> print "$posters\n";
> But when i run the script, it only returns this:
> HASH(0xa145268)
> What am i doing wrong here ?
Failing to de-reference the reference returned by the
News::Scan::posters() method.
perldoc perlreftut
perldoc perlref
To see what the method is returning to you:
use Data::Dumper;
...
my $posters = $scan->posters;
print Dumper $posters;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 7 Feb 2005 09:59:39 -0800
From: pomuran@gmail.com (Vasily Pomuran)
Subject: one more IP addr regexp
Message-Id: <697dc2c9.0502070959.122784c6@posting.google.com>
Hi everybody.
It seems that this regexp works right.
/\b((\d|1{0,1}\d{2}|2[01234]\d|25[012345])\.){3}(\d|1{0,1}\d{2}|2[01234]\d|25[012345])\b/
Maybe you'll find it useful.
Best Regards
V.Pomuran
------------------------------
Date: Tue, 8 Feb 2005 09:32:08 +1300
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: one more IP addr regexp
Message-Id: <36q1esF52ibl3U1@individual.net>
"Vasily Pomuran" <pomuran@gmail.com> wrote in message
news:697dc2c9.0502070959.122784c6@posting.google.com...
> Hi everybody.
> It seems that this regexp works right.
>
> /\b((\d|1{0,1}\d{2}|2[01234]\d|25[012345])\.){3}(\d|1{0,1}\d{2}|2[01234]\d|25[012345])\b/
>
> Maybe you'll find it useful.
Would be useful if it matched valid IP addresses.
1.1.1.1.1 is not a valid IP address.
------------------------------
Date: Mon, 07 Feb 2005 15:49:32 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: one more IP addr regexp
Message-Id: <6YidncqrLo3BSZrfRVn-qw@comcast.com>
Tintin wrote:
>
> "Vasily Pomuran" <pomuran@gmail.com> wrote in message
> news:697dc2c9.0502070959.122784c6@posting.google.com...
>> Hi everybody.
>> It seems that this regexp works right.
>>
>> /\b((\d|1{0,1}\d{2}|2[01234]\d|25[012345])\.){3}(\d|1{0,1}\d{2}|
[01234]\d|25[012345])\b/
>>
>> Maybe you'll find it useful.
>
> Would be useful if it matched valid IP addresses.
>
> 1.1.1.1.1 is not a valid IP address.
Personally, I just use inet_aton(). Why reinvent the wheel?
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: Mon, 07 Feb 2005 22:08:28 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: one more IP addr regexp
Message-Id: <36q3p8F563a3bU1@individual.net>
Tintin wrote:
> Vasily Pomuran wrote:
>>
>>/\b((\d|1{0,1}\d{2}|2[01234]\d|25[012345])\.){3}(\d|1{0,1}\d{2}|2[01234]\d|25[012345])\b/
>
> Would be useful if it matched valid IP addresses.
>
> 1.1.1.1.1 is not a valid IP address.
It doesn't match that either.
my $re =
qr/\b((\d|1{0,1}\d{2}|2[01234]\d|25[012345])\.){3}(\d|1{0,1}\d{2}|2[01234]\d|25[012345])\b/;
my $ip = '1.1.1.1.1';
print "$1\n" if $ip =~ /($re)/;
Outputs:
1.1.1.1
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 07 Feb 2005 17:01:29 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: one more IP addr regexp
Message-Id: <5qGdnd4Ne-ukeJrfRVn-pw@comcast.com>
Gunnar Hjalmarsson wrote:
> Tintin wrote:
>> Vasily Pomuran wrote:
>>>
>>>/\b((\d|1{0,1}\d{2}|2[01234]\d|25[012345])\.){3}(\d|1{0,1}\d{2}|
[01234]\d|25[012345])\b/
>>
>> Would be useful if it matched valid IP addresses.
>>
>> 1.1.1.1.1 is not a valid IP address.
>
> It doesn't match that either.
>
> my $re =
> qr/\b((\d|1{0,1}\d{2}|2[01234]\d|25[012345])\.){3}(\d|1{0,1}\d{2}|
[01234]\d|25[012345])\b/;
> my $ip = '1.1.1.1.1';
> print "$1\n" if $ip =~ /($re)/;
>
> Outputs:
> 1.1.1.1
>
You want to try to edit more or less randomly things that aren't valid
IPs so that they'll be valid IPs? NOT a good idea, IMHO.
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: Mon, 07 Feb 2005 23:29:41 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: one more IP addr regexp
Message-Id: <36q8j0F4nipspU1@individual.net>
Chris Mattern wrote:
> Gunnar Hjalmarsson wrote:
>> Tintin wrote:
>>> Would be useful if it matched valid IP addresses.
>>>
>>> 1.1.1.1.1 is not a valid IP address.
>>
>> It doesn't match that either.
>>
>> my $re =
>>qr/\b((\d|1{0,1}\d{2}|2[01234]\d|25[012345])\.){3}(\d|1{0,1}\d{2}|[01234]\d|25[012345])\b/;
>> my $ip = '1.1.1.1.1';
>> print "$1\n" if $ip =~ /($re)/;
>>
>> Outputs:
>> 1.1.1.1
>
> You want to try to edit more or less randomly things that aren't valid
> IPs so that they'll be valid IPs?
Didn't say that. All I said was that it doesn't match '1.1.1.1.1'. :)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 07 Feb 2005 22:47:58 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: one more IP addr regexp
Message-Id: <slrnd0fs0u.g2.abigail@alexandra.abigail.nl>
Vasily Pomuran (pomuran@gmail.com) wrote on MMMMCLXXVIII September
MCMXCIII in <URL:news:697dc2c9.0502070959.122784c6@posting.google.com>:
:) Hi everybody.
:) It seems that this regexp works right.
:)
:) /\b((\d|1{0,1}\d{2}|2[01234]\d|25[012345])\.){3}(\d|1{0,1}\d{2}|2[01234]\d|25[012345])\b/
:)
:) Maybe you'll find it useful.
That will match
"\x{0660}.\x{0661}.\x{0662}.\x{0663}"
Abigail
--
# Perl 5.6.0 broke this.
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi
------------------------------
Date: 7 Feb 2005 17:32:44 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Perl - permute?
Message-Id: <Xns95F67572360F4castleamber@130.133.1.4>
Arndt Jonasson wrote:
>
> John Bokma <postmaster@castleamber.com> writes:
>> A. Sinan Unur wrote:
>>
>> > John Bokma <postmaster@castleamber.com> wrote in
>> > news:Xns95F5B75BF8DA1castleamber@130.133.1.4:
>> >
>> >> A. Sinan Unur wrote:
>
> I think that instead of spending time arguing with Sinan (what does
> the A stand for?), it would have been more helpful to answer the
> original poster,
The OP already got a correct answer. And what I do with my time is none
of your business. If you carefully reread my posting you probably will
get the point.
> if you think there was something missing in the
> answers he got.
> Besides, showing the existence of CPAN _is_ helping, even if you point
> at the wrong module.
Sure, pointing at the hammer in a toolbox and then telling it's wrong is
always a sound way of educating someone.
Imagine everyone posting smart ass replies to every newbie. The world is
already wonderful as it is, let's not make it worse.
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Mon, 07 Feb 2005 18:34:21 +0100
From: phaylon <phaylon@dunkelheit.at>
Subject: Re: Perl - permute?
Message-Id: <pan.2005.02.07.17.34.21.441068@dunkelheit.at>
John Bokma wrote:
> The OP already got a correct answer. And what I do with my time is none of
> your business. If you carefully reread my posting you probably will get
> the point.
Seems to me you're the one still searching for 'the point'.
p
--
http://www.dunkelheit.at/
Thru the darkness of futures past, the magician longs to see.
One chants out between two worlds: Fire, walk with me.
-- Twin Peaks, »Bob«
------------------------------
Date: 07 Feb 2005 17:50:04 GMT
From: xhoster@gmail.com
Subject: Re: Perl - permute?
Message-Id: <20050207125004.974$KS@newsreader.com>
Ej <justsurge@mailcan.com> wrote:
> Hi,
> How can I take an array (a,b,c,d,e) and list ALL possible [3 LETTER]
> combos of these letters, I want the output to look like
>
> abc
> acb
> aab
> aaa
That isn't permutation. 3-deep nested loops should do it.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 7 Feb 2005 19:22:28 GMT
From: greymaus@yahoo.com
Subject: Re: Perl - permute?
Message-Id: <slrnd0ffcq.398.greymaus@maus.org>
On 06 Feb 2005 17:10:59 GMT, Abigail wrote:
> Ej (justsurge@mailcan.com) wrote on MMMMCLXXVII September MCMXCIII in
><URL:news:1107709033.0d15271ffc45f8463e1fcde7dddd2c79@bubbanews>:
> `` Hi,
> `` How can I take an array (a,b,c,d,e) and list ALL possible [3 LETTER] combos
> `` of these letters, I want the output to look like
> ``
> `` abc
> `` acb
> `` aab
> `` aaa
>
>
> foreach my $i (@array) {
> foreach my $j (@array) {
> foreach my $k (@array) {
> print "$i$j$k\n";
> }
> }
> }
>
>
> Abigail
Hmm, dosn't work here, uses some letters more than once.
for qw(a b c d e)
#some long list, of which
aaa
aac
aak
aao
aar
aca
acc
contain more a's.
--
greymaus
97.025% of statistics are wrong
------------------------------
Date: 07 Feb 2005 19:54:25 GMT
From: xhoster@gmail.com
Subject: Re: Perl - permute?
Message-Id: <20050207145425.940$dR@newsreader.com>
greymaus@yahoo.com wrote:
> On 06 Feb 2005 17:10:59 GMT, Abigail wrote:
> > Ej (justsurge@mailcan.com) wrote on MMMMCLXXVII September MCMXCIII in
> ><URL:news:1107709033.0d15271ffc45f8463e1fcde7dddd2c79@bubbanews>:
> > `` Hi,
> > `` How can I take an array (a,b,c,d,e) and list ALL possible [3
> > LETTER] combos `` of these letters, I want the output to look like
> > ``
> > `` abc
> > `` acb
> > `` aab
> > `` aaa
> >
> >
> > foreach my $i (@array) {
> > foreach my $j (@array) {
> > foreach my $k (@array) {
> > print "$i$j$k\n";
> > }
> > }
> > }
> >
> >
> > Abigail
>
> Hmm, dosn't work here, uses some letters more than once.
> for qw(a b c d e)
> #some long list, of which
>
> aaa
> aac
> aak
> aao
> aar
> aca
> acc
>
> contain more a's.
Did you look at the sample output the OP provided?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 7 Feb 2005 20:14:31 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Perl - permute?
Message-Id: <Xns95F690E0AEE41castleamber@130.133.1.4>
phaylon wrote:
> John Bokma wrote:
>
>> The OP already got a correct answer. And what I do with my time is
>> none of your business. If you carefully reread my posting you
>> probably will get the point.
>
> Seems to me you're the one still searching for 'the point'.
At least I don't do it as an anonymous carrion bird.
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Tue, 08 Feb 2005 07:29:19 +1100
From: David Trudgett <dtrudgett@holdthespam_yahoo.com>
Subject: Re: Perl - permute?
Message-Id: <CfQNd.7339$i6.67367@nasal.pacific.net.au>
Abigail wrote:
> Well, that's NOT what the OP wants. So, perhaps you know a combination
> when you see one - this wasn't a combination that was asked for.
>
> For a three element array, and a 2 element answer, the OP wants:
>
> a a
> a b
> a c
> b a
> b b
> b c
> c a
> c b
> c c
>
That'll teach me not to go around seeing things that aren't there! Looks
like the OP has found himself a job writing an enhancement to
Math::Combinatorics to do permutations with repetition and combinations
with repetition (aka variations).
David
------------------------------
Date: 7 Feb 2005 20:31:47 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Perl - permute?
Message-Id: <cu8j7j$ljr$1@mamenchi.zrz.TU-Berlin.DE>
<greymaus@yahoo.com> wrote in comp.lang.perl.misc:
> On 06 Feb 2005 17:10:59 GMT, Abigail wrote:
> > Ej (justsurge@mailcan.com) wrote on MMMMCLXXVII September MCMXCIII in
> ><URL:news:1107709033.0d15271ffc45f8463e1fcde7dddd2c79@bubbanews>:
> > `` Hi,
> > `` How can I take an array (a,b,c,d,e) and list ALL possible [3
> LETTER] combos
> > `` of these letters, I want the output to look like
> > ``
> > `` abc
> > `` acb
> > `` aab
> > `` aaa
> >
> >
> > foreach my $i (@array) {
> > foreach my $j (@array) {
> > foreach my $k (@array) {
> > print "$i$j$k\n";
> > }
> > }
> > }
> >
> >
> > Abigail
>
> Hmm, dosn't work here, uses some letters more than once.
> for qw(a b c d e)
> #some long list, of which
>
>
> aaa
> aac
> aak
> aao
> aar
> aca
> acc
>
> contain more a's.
That wasn't what was asked, but supposing it was, how would you fix
the loops above so that every character is used at most once in each
string?
Anno
------------------------------
Date: Mon, 07 Feb 2005 14:03:23 -0500
From: "John M. Gabriele" <john_sips_teaz@yahooz.com>
Subject: Perl's strengths: How well does Python do them?
Message-Id: <110fermmcka76c7@corp.supernews.com>
I've learned some Perl recently, and also some Python.
I'm curious to know if Python can be a servicable replacement
for Perl, specifically for system administration. To keep this
post on-topic here, my question is: does Perl have any major
strengths that make it a better systems admin programming language
that Python?
I really don't mean this to be a "which lang is better" post. I
realize that Python is a *general purpose* OO programming language
which finds some use in system administration, but what I'm really
trying to get at is, how well does it perform against the workhorse
that is Perl. And if Perl is better at system administration tasks
(and systems programming in general), what specifically makes it
better?
Thanks,
---J
-- if replying via email, remove zees --
------------------------------
Date: 07 Feb 2005 20:18:59 +0100
From: Ulrich Herbst <ulrich.herbst@gmx.de>
Subject: Re: Perl's strengths: How well does Python do them?
Message-Id: <87oeewgov0.fsf@pculi.herbst.fam>
"John M. Gabriele" <john_sips_teaz@yahooz.com> writes:
> I've learned some Perl recently, and also some Python.
> I'm curious to know if Python can be a servicable replacement
> for Perl, specifically for system administration. To keep this
> post on-topic here, my question is: does Perl have any major
> strengths that make it a better systems admin programming language
> that Python?
IMHO, perl has (at least) one major strength in system administration
tasks:
It is installed on all our servers :-)
No joke, it isn't easy, to install a new open source product on a
bunch of production servers.
Uli
--
'''
(0 0)
+------oOO----(_)--------------+
| |
| Ulrich Herbst |
| |
| Ulrich.Herbst@gmx.de |
+-------------------oOO--------+
|__|__|
|| ||
ooO Ooo
------------------------------
Date: 07 Feb 2005 22:49:01 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Perl's strengths: How well does Python do them?
Message-Id: <slrnd0fs2s.g2.abigail@alexandra.abigail.nl>
John M. Gabriele (john_sips_teaz@yahooz.com) wrote on MMMMCLXXVIII
September MCMXCIII in <URL:news:110fermmcka76c7@corp.supernews.com>:
"" I've learned some Perl recently, and also some Python.
"" I'm curious to know if Python can be a servicable replacement
"" for Perl, specifically for system administration. To keep this
"" post on-topic here, my question is: does Perl have any major
"" strengths that make it a better systems admin programming language
"" that Python?
No.
Next!
Abigail
--
($;,$_,$|,$\)=("\@\x7Fy~*kde~box*Zoxf*Bkiaox","X"x25,1,"\r");
s/./ /;{vec($_=>1+$"=>8)=ord($/^substr$;=>$"=int rand 24=>1);
print&&select$,,$,,$,,$|/($|+tr/X//c);redo if y/X//};sleep 1;
------------------------------
Date: 7 Feb 2005 12:23:19 -0800
From: "Bob" <tallstyk@yahoo.com>
Subject: should be simple..but eh Can you help
Message-Id: <1107807799.467282.253120@c13g2000cwb.googlegroups.com>
Hi...
I have a text file that looks like this:
title: fdsfdsfsd fdsfdsf
number: 234234234234324243
animal: pig
title: sf32erweff fwef wef we
number: 456456456
animal: hen
title: cvbvcxvcxvcvvc
number: 340320324032403
animal: horse
...
..
.
I want to 'grep' for a string whose line begins with title (^title) and
if found
automatically print out that line AND the following 2 lines.
I don't want to use SED, but PERL.
Anyone of you gurus able to assist on how to do this in PERL?
thanks
Bob
------------------------------
Date: Mon, 07 Feb 2005 21:29:40 +0100
From: Tore Aursand <toreau@gmail.com>
Subject: Re: should be simple..but eh Can you help
Message-Id: <PcQNd.7604$Sl3.237847@news4.e.nsc.no>
Bob wrote:
> I have a text file that looks like this:
> [...]
> I want to 'grep' for a string whose line begins with title (^title) and
> if found automatically print out that line AND the following 2 lines.
What have you tried so far?
> I don't want to use SED, but PERL.
It's "sed" and "Perl".
--
Tore Aursand <tore@aursand.no>
"It's not so much what you have to learn if you accept weird theories,
it's what you have to unlearn." (Isaac Asimov)
------------------------------
Date: 7 Feb 2005 20:32:30 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: should be simple..but eh Can you help
Message-Id: <Xns95F69E19555ABasu1cornelledu@132.236.56.8>
"Bob" <tallstyk@yahoo.com> wrote in news:1107807799.467282.253120
@c13g2000cwb.googlegroups.com:
> Hi...
>
> I have a text file that looks like this:
>
>
> title: fdsfdsfsd fdsfdsf
> number: 234234234234324243
> animal: pig
>
> title: sf32erweff fwef wef we
> number: 456456456
> animal: hen
>
> title: cvbvcxvcxvcvvc
> number: 340320324032403
> animal: horse
>
> ...
> ..
> .
>
>
> I want to 'grep' for a string whose line begins with title (^title) and
> if found
> automatically print out that line AND the following 2 lines.
>
> I don't want to use SED, but PERL.
That's why you are posting to comp.lang.perl.misc.
I think the functions index and readline would be useful for your
purpose.
perldoc -f index
perldoc -f readline
By the way, minor but important point: The name of the language is Perl
not PERL.
Sinan.
------------------------------
Date: Mon, 07 Feb 2005 20:46:38 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: should be simple..but eh Can you help
Message-Id: <OsQNd.10335$ya6.5104@trndny01>
"Bob" <tallstyk@yahoo.com> wrote in message
news:1107807799.467282.253120@c13g2000cwb.googlegroups.com...
> Hi...
>
> I have a text file that looks like this:
>
>
> title: fdsfdsfsd fdsfdsf
> number: 234234234234324243
> animal: pig
>
> title: sf32erweff fwef wef we
> number: 456456456
> animal: hen
>
> title: cvbvcxvcxvcvvc
> number: 340320324032403
> animal: horse
>
> I want to 'grep' for a string whose line begins with title (^title)
and
> if found
> automatically print out that line AND the following 2 lines.
>
> I don't want to use SED, but PERL.
>
> Anyone of you gurus able to assist on how to do this in PERL?
First, please read:
perldoc -q difference
Thank you.
Second, is this really what your file looks like? Does it contain
nothing but a series of the three lines you want, each 'record'
separated by a blank line? In that case, just set the input record
separator to paragraph mode:
{
open my $file, '<', 'file.txt' or die "Cannot open file: $!";
local $/ = "\n\n";
while (<$file>){
# $_ now contains your entire record
}
}
If your file does contain other lines you don't want, you're likely
better off using the 'flipflop' operator: ..
open my $file, '<', 'file.txt' or die "Cannot open file: $!";
while (<$file>){
print if /^title:/ .. /^animal:/;
}
The flipflop operator is something at which I usually don't have a great
deal of success explaining well, so instead I'll point you at the
documentation: perldoc perlop (search for 'flip-flop')
Hope this helps
Paul Lalli
------------------------------
Date: Mon, 07 Feb 2005 21:51:12 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: should be simple..but eh Can you help
Message-Id: <36q2ocF4v958nU1@individual.net>
[ Please choose a subject line that reflects the subject of your post. ]
Bob wrote:
> I have a text file that looks like this:
>
> title: fdsfdsfsd fdsfdsf
> number: 234234234234324243
> animal: pig
>
> title: sf32erweff fwef wef we
> number: 456456456
> animal: hen
>
> title: cvbvcxvcxvcvvc
> number: 340320324032403
> animal: horse
>
> I want to 'grep' for a string whose line begins with title (^title) and
> if found automatically print out that line AND the following 2 lines.
So, what have you tried, and what difficulties have you encountered?
Please study the posting guidelines for this group:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
There are many ways to do what you want; this is one:
use Tie::File;
tie my @file, 'Tie::File', 'myfile.txt' or die $!;
print map { join("\n", @file[$_..$_+2]), "\n\n" }
grep substr($file[$_], 0, 5) eq 'title', 0..$#file;
untie @file;
> I don't want to use SED, but PERL.
Since you posted here, most people would have guessed so. Why did you
find it worth mentioning?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 7 Feb 2005 13:59:04 -0800
From: clearguy02@yahoo.com
Subject: To compare dates in a script
Message-Id: <1107813544.944788.294170@c13g2000cwb.googlegroups.com>
Hi all,
Below is the scenario.
I have a file that has two entrees (a name and a date) seperated by a
tab. I need to get only all those names in the file if the date on the
each line is greater than a certain date, 12-31-2004.
Script
#######################
$current = "31-Dec-04";
foreach (<DATA>) {
($f, $l) = /(\w+)\t+(\w+)/;
print $f if ($l > $current);
}
__DATA__
5.5.25.50 01-Feb-05
TEST1 22-Jul-04
BSTOP 03-Sep-02
DB00004639 21-Jan-05
DB00004693 25-Jan-05
CDM_3.1.0 27-May-03
############################
I think I am failing on comparing stuff. How can I rectify the above
code?
Thanks,
Rider.
------------------------------
Date: Mon, 07 Feb 2005 15:08:12 -0700
From: Eric Schwartz <emschwar@fc.hp.com>
Subject: Re: To compare dates in a script
Message-Id: <etobrawhvlf.fsf@wilson.emschwar>
clearguy02@yahoo.com writes:
> I have a file that has two entrees (a name and a date) seperated by a
> tab. I need to get only all those names in the file if the date on the
> each line is greater than a certain date, 12-31-2004.
You should probably get in the habit of searching CPAN before posting
here-- that's not an insult, merely an observation that a lot of the
time, you'll find the answer there first, and save time.
In this case, you'd have found Date::Manip and Date::Calc, both of
which will do what you want, more or less.
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: Mon, 07 Feb 2005 22:41:40 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: To compare dates in a script
Message-Id: <Xns95F6B40B964F2asu1cornelledu@127.0.0.1>
clearguy02@yahoo.com wrote in news:1107813544.944788.294170
@c13g2000cwb.googlegroups.com:
> I have a file that has two entrees (a name and a date) seperated by a
Just FYI: ITYM "entries".
> tab. I need to get only all those names in the file if the date on the
> each line is greater than a certain date, 12-31-2004.
>
> Script
> #######################
There is usually no need for this kind of separator. If you put a
shebang line in your scripts, that serves nicely to set the script apart
from the rest of the post, especially if you end your scripts with
__END__.
use strict;
use warnings;
missing. Please read the posting guidelines for this group.
> $current = "31-Dec-04";
my $current = "20041231";
for reasons that will become clear later.
> foreach (<DATA>) {
This first reads the whole file. Better to use
while (<DATA>) {
> ($f, $l) = /(\w+)\t+(\w+)/;
> print $f if ($l > $current);
So, you have two strings and you compare them using the numeric operator
'>'.
Indeed, if you had turned on warnings, perl would have told you:
Argument "31-Dec-04" isn't numeric in numeric gt (>) at a.pl line 9,
<DATA> line 7.
> I think I am failing on comparing stuff. How can I rectify the above
> code?
You could use a module for comparing dates. See CPAN if you want to go
that route. On the other hand, you could also just convert your dates to
the YYYYMMDD format and use string comparison:
#! /usr/bin/perl
use strict;
use warnings;
my $current = '20041231';
my %months = (
Jan => '01', Feb => '02', Mar => '03', Apr => '04',
May => '05', Jun => '06', Jul => '07', Aug => '08',
Sep => '09', Oct => '10', Nov => '11', Dec => '12',
);
while(<DATA>) {
chomp;
last unless $_;
my ($file, $date) = split /\s+/;
my ($day, $month, $year) = split '-', $date;
# You'll need to figure out how far back the dates go
# and adjust the if statement below accordingly
if(0 + $year <= 50) {
$year += 2000;
} else {
$year += 1900;
}
$month = $months{$month};
print "$file\n" if $current le "$year$month$day";
}
__DATA__
5.5.25.50 01-Feb-05
TEST1 22-Jul-04
BSTOP 03-Sep-02
DB00004639 21-Jan-05
DB00004693 25-Jan-05
CDM_3.1.0 27-May-03
__END__
------------------------------
Date: 7 Feb 2005 17:02:38 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Why aren't 'warnings' on by default?
Message-Id: <cu86ve$ef5$2@mamenchi.zrz.TU-Berlin.DE>
Arndt Jonasson <do-not-use@invalid.net> wrote in comp.lang.perl.misc:
>
> Abigail <abigail@abigail.nl> writes:
> > Hendrik Maryns (hendrik_maryns@despammed.com) wrote on MMMMCLXXVII
> > September MCMXCIII in <URL:news:xaydnaJhoYE2PZvfRVnyhg@scarlet.biz>:
> > }} Abigail schreef:
> > }} <something very important>
> > }}
> > }} <-- >
> > }} A perl rose: perl -e '@}>-`-,-`-%-'
> > }}
> > }} This doesn't do anything for me?
> >
> >
> > Do roses ever do something for you? ;-)
>
> They smell nicely, sometimes.
You forgot to plug in your OMC (Olfactory Multimedia Component).
Anno
------------------------------
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 7750
***************************************