[15738] in Perl-Users-Digest
Perl-Users Digest, Issue: 3151 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 24 18:10:52 2000
Date: Wed, 24 May 2000 15:10:30 -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: <959206229-v9-i3151@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 24 May 2000 Volume: 9 Number: 3151
Today's topics:
Re: Copy A File? <lr@hpl.hp.com>
Re: Copy A File? (Gwyn Judd)
Re: Copy A File? (brian d foy)
Re: creating graphs with perl..? <jraff@home.com>
Re: email poser (Clinton A. Pierce)
Re: Finding IP addresses+ <lr@hpl.hp.com>
Re: Finding IP addresses+ (Abigail)
Re: Finding IP addresses+ (Abigail)
Re: Finding IP addresses+ (Sweth Chandramouli)
Re: Finding IP addresses+ (Brandon Metcalf)
Finding repeating patterns inside arrays <makarand_kulkarni@My-Deja.com>
Finding repeating patterns inside arrays <makarand_kulkarni@My-Deja.com>
Re: Finding repeating patterns inside arrays <tony_curtis32@yahoo.com>
Re: Finding repeating patterns inside arrays <aqumsieh@hyperchip.com>
Re: Finding repeating patterns inside arrays <Tbone@pimpdaddy.com>
Re: Finding repeating patterns inside arrays <makarand_kulkarni@My-Deja.com>
Re: Finding repeating patterns inside arrays <thepoet1@arcormail.de>
Re: Finding repeating patterns inside arrays <jeff@vpservices.com>
Re: Finding repeating patterns inside arrays <aqumsieh@hyperchip.com>
Re: Finding repeating patterns inside arrays <tony_curtis32@yahoo.com>
Re: Finding repeating patterns inside arrays <Tbone@pimpdaddy.com>
Getting HTML source nfsite@my-deja.com
Re: Getting HTML source <jeff@vpservices.com>
Re: Getting HTML source <rootbeer@redcat.com>
Re: Getting HTML source (Clinton A. Pierce)
Re: Getting HTML source <Jonathan.L.Ericson@jpl.nasa.gov>
Re: Getting HTML source <jeff@vpservices.com>
Re: Global variables to apply to multiple Perl scripts <thepoet1@arcormail.de>
Re: Global variables to apply to multiple Perl scripts <apietro@my-deja.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 24 May 2000 10:57:18 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Copy A File?
Message-Id: <MPG.1395b7dacff180fb98aaca@nntp.hpl.hp.com>
In article <slrn8iqekd.be8.tjla@thislove.dyndns.org> on Wed, 24 May 2000
14:34:50 GMT, Gwyn Judd <tjla@guvfybir.qlaqaf.bet> says...
> I was shocked! How could NoSpam <nospam@nospam.com>
> say such a terrible thing:
> >Does this allow variables?
> >
> >e.g.
> >
> >system 'cp $sourcefile $destfile';
>
> no you'll need double quotes for that. Oh and you should always check
> the return value:
>
> system "cp $sourcefile $destfile" || die "could not copy: $!";
Hey, three errors on one line. Not bad at all (even overlooking the
very dubious choice of using a non-portable external command to do
something that the File::Copy module can do portably and efficiently).
Oh, the errors:
1. Incorrect precedence (the error message cannot be triggered).
2. Incorrect logic (the system() function reports FALSE on
success).
3. Incorrect diagnostic. $! reports errors on system calls, not
execution status return codes.
system "cp $sourcefile $destfile" and die "could not copy: $?";
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 24 May 2000 21:51:13 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Copy A File?
Message-Id: <slrn8ir86j.c6l.tjla@thislove.dyndns.org>
I was shocked! How could Peter J. Acklam <jacklam@math.uio.no>
say such a terrible thing:
>NoSpam <nospam@nospam.com>:
>Hmm...according to my memory, system() returns 0 upon success, so it
>should rather be something along the lines of
>
> system("cp $sourcefile $destfile") == 0 or die "...";
correct.
--
Gwyn Judd (tjla@guvfybir.qlaqaf.bet)
My return address is rot13'ed
An Italian is COMBING his hair in suburban DES MOINES!
------------------------------
Date: Wed, 24 May 2000 17:58:39 -0400
From: brian@smithrenaud.com (brian d foy)
Subject: Re: Copy A File?
Message-Id: <brian-ya02408000R2405001758390001@news.panix.com>
In article <slrn8ir86j.c6l.tjla@thislove.dyndns.org>, tjla@guvfybir.qlaqaf.bet (Gwyn Judd) posted:
> I was shocked! How could Peter J. Acklam <jacklam@math.uio.no>
> say such a terrible thing:
> >NoSpam <nospam@nospam.com>:
> >Hmm...according to my memory, system() returns 0 upon success, so it
> >should rather be something along the lines of
> >
> > system("cp $sourcefile $destfile") == 0 or die "...";
>
> correct.
why rely on memory when you can look it up?
=item system LIST
Does exactly the same thing as "exec LIST" except that a fork is done
first, and the parent process waits for the child process to complete.
Note that argument processing varies depending on the number of
arguments. The return value is the exit status of the program as
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
returned by the wait() call.
[snip]
in this case, however, cp returns 0 on success, but not every
program may do that.
--
brian d foy
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Mongers <URL:http://www.perl.org/>
------------------------------
Date: Wed, 24 May 2000 19:08:05 GMT
From: "jraff" <jraff@home.com>
Subject: Re: creating graphs with perl..?
Message-Id: <pMVW4.83211$R4.508520@news1.rdc1.nj.home.com>
There is a cute way to generate bar charts in HTML.
Create a 1x1 image and use the height and width command to stretch it.
The following creates an 8 pixel high by "width" wide image for the bar
chart.
<table>
<tr>
<td align=left><img src="images/blue.png"width="14" height="8"></td>
</tr>
<tr>
<td align=left><img src="images/l-green.png"width="12" height="8"></td>
</tr>
<tr>
<td align=left><img src="images/l-blue.png"width="6" height="8"></td>
</tr>
<tr>
<td align=left><img src="images/violet.png"width="78" height="8"></td>
</tr>
Very easy to create with perl or any scripting language.
----------------------------------------------------------------------------
------
<suot@iobox.com> wrote in message news:8gg4is$u4f$1@nnrp1.deja.com...
> Hey, my purpose was to create simple scientific graphs with Perl via
> HTML-pages. We are running
> NT-server.
> I've found only couple of UNIX-modules for Perl to create those graphs
> but none for NT. Could anyone give
> a hand..?
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
------------------------------
Date: Wed, 24 May 2000 19:43:09 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: email poser
Message-Id: <hhWW4.86486$h01.625659@news1.rdc1.mi.home.com>
[Posted and mailed]
In article <392bbac3.0@nnrp1.news.uk.psi.net>,
"David Fleet" <dfleet@avaterra.com> writes:
> Anyone know why only 300 or so emails get through when I do a mass email to
> myself?
Probably because your system administrator as set up limits to the amount
of mail you can send or receive at any one time. Or there are disk quota
limits on the mail spool.
You have no delays in this code at all. Keep in mind too that sendmail
will queue but not send mail if the system gets too busy.
To find out more about sendmail configuration, read the fine manual or
ask in a more appropriate group.
> The code is as below:--
> [repulsive code deleted]
BTW, if you're a spammer: I hate you and you can die a slow, miserable death
and your unburied corpse can rot in a tropical sunshine while being eaten by
mongrel rabid dogs with tapeworms.
Otherwise, I hope this helps! :)
--
Clinton A. Pierce Teach Yourself Perl in 24 Hours!
clintp@geeksalad.org for details see http://www.geeksalad.org
"If you rush a Miracle Man,
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: Wed, 24 May 2000 11:58:00 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Finding IP addresses+
Message-Id: <MPG.1395c614af69692598aacd@nntp.hpl.hp.com>
In article <Pine.GSO.4.10.10005240846240.23375-
100000@user2.teleport.com> on Wed, 24 May 2000 09:08:09 -0700, Tom
Phoenix <rootbeer@redcat.com> says...
...
> I can generally find something interesting at this URL, although some
> browsers don't work properly with it.
>
> http://3427256387/
My browsers insist on filling in my local domain. But they work on the
dotted-quad 204.71.200.67 .
perl -lwe "print join '.' => unpack C4 => pack N => 3427256387"
> > I've actually got a fairly robust set of perl functions
> > for matching/parsing IPv4 addresses and netmasks in a variety of formats,
> > that I was thinking of posting to CPAN; does anyone know if something like
> > that already exists?
>
> Does Net::DNS do what you want? Although maybe all you need is part of
> this long line:
>
> perl -MSocket -lwe 'print +(gethostbyaddr inet_aton(3427256387), AF_INET)[0]'
But the reverse DNS on two of my systems (HP-UX and Windows NT, but on
the same intranet) didn't resolve either this form or the dotted-quad
form. Hmmm...
Mini-crusade, probably doomed ab initio:
When the one-liner Perl command doesn't include shell metacharacters,
why not use double-quotes instead of single-quotes, for portability to
DOS shells, as I did in my example above? It makes it easier to copy-
and-paste, instead of having to edit the quotes.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 24 May 2000 20:00:51 GMT
From: abigail@arena-i.com (Abigail)
Subject: Re: Finding IP addresses+
Message-Id: <8ghcdj$81n$1@news.panix.com>
On 24 May 2000 16:56:58 GMT, I R A Darth Aggie <sy_nttvr@gurcragntba.pbz> wrote:
++ On Wed, 24 May 2000 09:08:09 -0700,
++ Tom Phoenix <rootbeer@redcat.com>, in
++ <Pine.GSO.4.10.10005240846240.23375-100000@user2.teleport.com> wrote:
++ + On Wed, 24 May 2000, Sweth Chandramouli wrote:
++ +
++ + > Here's the version I whacked together a while ago
++ + > to match in perl; I'm fairly certain that it matches all of the cases
++ + > and no invalid cases:
++ + >
++ + > chomp ($_[0]);
++ + > my $dq_regex = "([01]?[0-9][0-9]?|2([0-4][0-9]|5[0-5]))";
++ + > ($_[0] =~ m/^(${dq_regex}\.){3}${dq_regex}$/);
++ +
++ + Does it match 2130706433? I can telnet to that address; can you? :-)
++
++ localhost?
++
++ + I can generally find something interesting at this URL, although some
++ + browsers don't work properly with it.
++ +
++ + http://3427256387/
++
++ Yahoo!
++
++ There's nothing that sez IP #'s have to be quad.dotted in the 0-255 range.
No, but the RFC for URLs says that if a numerical address is used, it
shall have exactly 3 dots.
http://3427256387/ doesn't match the grammar of the RFC.
Abigail
------------------------------
Date: 24 May 2000 20:05:00 GMT
From: abigail@arena-i.com (Abigail)
Subject: Re: Finding IP addresses+
Message-Id: <8ghclc$81n$2@news.panix.com>
On Wed, 24 May 2000 11:58:00 -0700, Larry Rosler <lr@hpl.hp.com> wrote:
++ In article <Pine.GSO.4.10.10005240846240.23375-
++ 100000@user2.teleport.com> on Wed, 24 May 2000 09:08:09 -0700, Tom
++ Phoenix <rootbeer@redcat.com> says...
++
++>perl -MSocket -lwe 'print +(gethostbyaddr inet_aton(3427256387), AF_INET)[0]'
++
++ Mini-crusade, probably doomed ab initio:
++
++ When the one-liner Perl command doesn't include shell metacharacters,
++ why not use double-quotes instead of single-quotes, for portability to
++ DOS shells, as I did in my example above? It makes it easier to copy-
++ and-paste, instead of having to edit the quotes.
That would require to know what the all the different shell
metacharacters are, from all different shells, and in which
circumstances they are meta or not. In the one-liner above, () and []
are, under the appropriate conditions, shell meta characters.
Abigail
------------------------------
Date: Wed, 24 May 2000 20:59:10 GMT
From: sweth@home.com (Sweth Chandramouli)
Subject: Re: Finding IP addresses+
Message-Id: <yoXW4.98252$E85.1962955@news1.rdc1.md.home.com>
In article <8ghcdj$81n$1@news.panix.com>, Abigail <abigail@arena-i.com> wrote:
>On 24 May 2000 16:56:58 GMT, I R A Darth Aggie <sy_nttvr@gurcragntba.pbz> wrote:
>++ On Wed, 24 May 2000 09:08:09 -0700,
>++ Tom Phoenix <rootbeer@redcat.com>, in
>++ <Pine.GSO.4.10.10005240846240.23375-100000@user2.teleport.com> wrote:
>++ + On Wed, 24 May 2000, Sweth Chandramouli wrote:
>++ +
>++ + > Here's the version I whacked together a while ago
>++ + > to match in perl; I'm fairly certain that it matches all of the cases
>++ + > and no invalid cases:
>++ + >
>++ + > chomp ($_[0]);
>++ + > my $dq_regex = "([01]?[0-9][0-9]?|2([0-4][0-9]|5[0-5]))";
>++ + > ($_[0] =~ m/^(${dq_regex}\.){3}${dq_regex}$/);
>++ +
>++ + Does it match 2130706433? I can telnet to that address; can you? :-)
[snip]
>No, but the RFC for URLs says that if a numerical address is used, it
>shall have exactly 3 dots.
>
>http://3427256387/ doesn't match the grammar of the RFC.
True, but many people still use decimal addresses (although
from what I can tell "many people" is almost entirely composed of spammers).
The module I have has a series of subroutines like "IsValidIP" that take as
their arguments a potential IP address and an optional address format, so
that addresses can be specified as dotted quad, binary, hex, decimal, octal,
or (for the subnet-mask routines) CIDR, with dotted quad being the assumed
default; the regex above was just the one from the dotted quad portion (hence
the name "dq_regex"). I started it while trying to parse a list of IP nets
of the form
10.2.1.0/24
10.4.5.128/25
10.10.1.0/23
that I needed to turn into enumerated lists of IPs that
were included; I ended up doing some one-offs for that particular task, but
it occurred to me that it would be really convenient to be able to do things
like
while ($line =~ <NET_LIST>) {
my ($net_number,$mask) = split (/\//,$line);
if (IsValidNet ($net_number,'dq',$mask,'cidr')) {
EnumerateNet ($net_number,'dq',$mask,'cidr', 'no-net', 'no-broadcast');
}
}
.
With regards to the original question of matching strings
that are valid IP addresses, I don't think gethostbyaddr fits the bill,
since (AFAIK) it always actually tries to resolve the address; the routines
I was looking for and eventually wrote simply check that the address is
syntactically valid. It isn't meant to allow for things like "localhost"
(which another poster suggested as a counterexample--sorry, by the way, for
responding to all of the posts at once, but this is the only response that
has shown up locally so far), since that is a DNS name (usually resolved
through local host tables, of course), and not an actual IPv4 address in the
strict sense of the term.
On a mildly-related note, what exactly is the proper protocol
for proposing new modules? I registered with CPAN and noted the namespace
that I've been using (Net::Address::IPv4.pm), but I wasn't sure if I should
just post the module to CPAN, or what.
-- Sweth.
--
Sweth Chandramouli ; <sweth@sweth.net>
<a href="http://www.sweth.net/legal/disc.html">*</a>
------------------------------
Date: 24 May 2000 22:01:57 GMT
From: bmetcalf@baynetworks.com (Brandon Metcalf)
Subject: Re: Finding IP addresses+
Message-Id: <8ghjgl$k4l$1@spinner.corpeast.baynetworks.com>
rootbeer@redcat.com writes:
> Does it match 2130706433? I can telnet to that address; can you? :-)
>
> I can generally find something interesting at this URL, although some
> browsers don't work properly with it.
>
> http://3427256387/
I tried searching a few places but didn't come up with anything. How
do these purely numerical addresses translate to the octet addresses?
Thanks,
-brandon
------------------------------
Date: Wed, 24 May 2000 11:54:20 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Finding repeating patterns inside arrays
Message-Id: <392C255C.30024DBB@My-Deja.com>
I have an array @array or english words contaning atmost one repeating
pattern.
How do I find what that is ?
eg.
If I had ( 'hello', 'hello1', 'hello2', 'hello3', 'hello1', 'hello2',
'hello3', 'hello1')
I want to get 'hello1', 'hello2', 'hello3' as the answer.
==
------------------------------
Date: Wed, 24 May 2000 11:59:31 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Finding repeating patterns inside arrays
Message-Id: <392C2693.3FA84818@My-Deja.com>
I have an array of english words containing a repeating pattern.
How do I find what that is ?
eg.
If I had ( 'hello', 'hello1', 'hello2', 'hello3', 'hello1', 'hello2',
'hello3', 'hello1')
I want to get ( 'hello1', 'hello2', 'hello3') as the answer.
==
------------------------------
Date: 24 May 2000 14:13:40 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Finding repeating patterns inside arrays
Message-Id: <87aehfiwwr.fsf@limey.hpcc.uh.edu>
>> On Wed, 24 May 2000 11:54:20 -0700,
>> Makarand Kulkarni <makarand_kulkarni@My-Deja.com> said:
> I have an array @array or english words contaning atmost
> one repeating pattern. How do I find what that is ?
> eg. If I had ( 'hello', 'hello1', 'hello2', 'hello3',
> 'hello1', 'hello2', 'hello3', 'hello1') I want to get
> 'hello1', 'hello2', 'hello3' as the answer. ==
I think what you want is to iterate the array and build a
hash of the number of occurrences of each element.
Then extract those which have a count of 2 (= 1 repeat) or
more.
my @data = ( 'hello', 'hello1', 'hello2', 'hello3',
'hello1', 'hello2', 'hello3', 'hello1');
my %ox; # element occurrences
++$ox{$_} for @data;
for (sort keys %ox) {
print "$_\n" if $ox{$_} > 1;
}
Or did you want exactly 2 occurrences? I wasn't sure
which it was from your specification. Either way, the
count test in the 2nd loop is trivially modifiable.
hth
t
------------------------------
Date: Wed, 24 May 2000 19:24:23 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: Finding repeating patterns inside arrays
Message-Id: <7aya4zwy3d.fsf@Merlin.i-did-not-set--mail-host-address--so-shoot-me>
Makarand Kulkarni <makarand_kulkarni@My-Deja.com> writes:
> I have an array of english words containing a repeating pattern.
> How do I find what that is ?
>
> eg.
> If I had ( 'hello', 'hello1', 'hello2', 'hello3', 'hello1', 'hello2',
> 'hello3', 'hello1')
> I want to get ( 'hello1', 'hello2', 'hello3') as the answer.
my %hash;
$hash{$_}++ for @array;
my @repeats = grep {$hash{$_} > 1} keys %hash;
--Ala
------------------------------
Date: 24 May 2000 19:42:24 GMT
From: Tushar Samant <Tbone@pimpdaddy.com>
Subject: Re: Finding repeating patterns inside arrays
Message-Id: <8ghbb0$i3t$1@news.enteract.com>
aqumsieh@hyperchip.com writes:
>Makarand Kulkarni <makarand_kulkarni@My-Deja.com> writes:
>
>> I have an array of english words containing a repeating pattern.
>> How do I find what that is ?
>>
>> eg.
>> If I had ( 'hello', 'hello1', 'hello2', 'hello3', 'hello1', 'hello2',
>> 'hello3', 'hello1')
>> I want to get ( 'hello1', 'hello2', 'hello3') as the answer.
>
> my %hash;
> $hash{$_}++ for @array;
>
> my @repeats = grep {$hash{$_} > 1} keys %hash;
I think you may have misunderstood the question. To answer what I think it
means:
You will have to specify which repeating pattern you want. The first one,
longest one, something else. Suppose you want the longest non-overlapping
pattern. Brute force way is to do a linear search: start with a span of
$#a/2, and see if that repeats. Else try with $#a/2 -1, etc.
A weird way would be to assign 'characters' to each element in the array,
make a string out of them and match /(.+)\1/.
However, I think it's worth putting a little more thought into this and
get a clean, quick algorithm.
------------------------------
Date: Wed, 24 May 2000 12:45:47 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Re: Finding repeating patterns inside arrays
Message-Id: <392C316B.754E4570@My-Deja.com>
> I think what you want is to iterate the array and build a
> hash of the number of occurrences of each element.
>
> Then extract those which have a count of 2 (= 1 repeat) or
> more.
I think I did not make myself clear. Using this technique I will be
able to find the number of occurences only. But want I want
to know is if the items 'hello1' followed by 'hello2' and
followed by 'hello3' ( in that order) appears again and again in
the array.
A count of the number of occurences is not really indicative
of the presence or absence of those items in that order.
The array I am using is an array of function names from a
stack trace. The repeating pattern is a situation of a recursive
call in a loop
eg. f1->f2->f3->f5->f6->f7->f5->f6->f7->f5->f6->f7... etc
The pattern f5, f6 and then f7 is what I want. The number
of times the function was called is irrelevant.
--
------------------------------
Date: Wed, 24 May 2000 21:15:38 +0200
From: Christian Winter <thepoet1@arcormail.de>
Subject: Re: Finding repeating patterns inside arrays
Message-Id: <qo9hg8.ufi.ln@usenet-autoren.de>
Makarand Kulkarni <makarand_kulkarni@My-Deja.com> schrob:
> I have an array @array or english words contaning atmost one repeating
> pattern.
> How do I find what that is ?
> eg.
> If I had ( 'hello', 'hello1', 'hello2', 'hello3', 'hello1', 'hello2',
> 'hello3', 'hello1')
> I want to get 'hello1', 'hello2', 'hello3' as the answer.
my %occurance;
foreach( @array ) {
$occurance{$_} = 0 unless defined $occurance{$_};
$occurance{$_}++;
}
foreach( keys %occurance ) {
print $_,"\n" if( $occurance{$_} > 1 );
}
HTH
Christian
------------------------------
Date: Wed, 24 May 2000 13:17:37 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Finding repeating patterns inside arrays
Message-Id: <392C38E1.17BB5A43@vpservices.com>
Makarand Kulkarni wrote:
>
> I think I did not make myself clear. Using this technique I will be
> able to find the number of occurences only. But want I want
> to know is if the items 'hello1' followed by 'hello2' and
> followed by 'hello3' ( in that order) appears again and again in
> the array.
>
> A count of the number of occurences is not really indicative
> of the presence or absence of those items in that order.
In that case, you need to specify what size pattern you want, don't
you? Is hello1 a pattern? It occurs three times in your original set.
Is hello1-hello2 a pattern? It occurs twice in your set. Is
hello2-hello3 a pattern? It occurs twice in your set. Yet you don't
seem to want to capture any of those patterns. So what exactly is it
that you do want to capture?
--
Jeff
------------------------------
Date: Wed, 24 May 2000 20:30:09 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: Finding repeating patterns inside arrays
Message-Id: <7asnv7wv1p.fsf@Merlin.i-did-not-set--mail-host-address--so-shoot-me>
Makarand Kulkarni <makarand_kulkarni@My-Deja.com> writes:
> I think I did not make myself clear. Using this technique I will be
> able to find the number of occurences only. But want I want
> to know is if the items 'hello1' followed by 'hello2' and
> followed by 'hello3' ( in that order) appears again and again in
> the array.
Ok. Now I see. What comes to mind is this:
my @array = qw/hello hello1 hello2 hello3
hello1 hello2 hello3 hello/;
# Assuming the elements of @array contain no spaces.
# I think this is a valid assumption since the elements
# are function names.
my $pat = join ' ' => @array; # in case you mucked with $"
my @x = $pat =~ /(\b\w.*)\1+/g;
print join(' AND ', @x), ".\n";
my @repeat = grep { $_ } split ' ' => join ' ' => @x;
print join(' xx ', @repeat), ".\n";
__END__
hello1 hello2 hello3 .
hello1 xx hello2 xx hello3.
But I have serious speed considerations. It's not bad for a few
elements, but for many elements it could get really slow. I can't think
of anything else though.
--Ala
------------------------------
Date: 24 May 2000 15:46:03 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Finding repeating patterns inside arrays
Message-Id: <8766s3isms.fsf@limey.hpcc.uh.edu>
>> On Wed, 24 May 2000 12:45:47 -0700,
>> Makarand Kulkarni <makarand_kulkarni@My-Deja.com> said:
> I think I did not make myself clear. Using this
> technique I will be able to find the number of
> occurences only. But want I want to know is if the items
> 'hello1' followed by 'hello2' and followed by 'hello3' (
> in that order) appears again and again in the array.
> A count of the number of occurences is not really
> indicative of the presence or absence of those items in
> that order.
> The array I am using is an array of function names from
> a stack trace. The repeating pattern is a situation of a
> recursive call in a loop
> eg. f1->f2->f3->f5->f6->f7->f5->f6->f7->f5->f6->f7... etc
> The pattern f5, f6 and then f7 is what I want. The
> number of times the function was called is irrelevant.
Hmmm, it sounds like you want to find cycles in a directed
graph, then.
I'd suggest boning up on Graph Theory and its associated
algorithms. I'm sure a good introductory book will have
suitable algorithms for such problems.
hth
t
------------------------------
Date: 24 May 2000 21:28:39 GMT
From: Tushar Samant <Tbone@pimpdaddy.com>
Subject: Re: Finding repeating patterns inside arrays
Message-Id: <8ghhi7$sbb$1@news.enteract.com>
Tbone@pimpdaddy.com writes:
>A weird way would be to assign 'characters' to each element in the array,
>make a string out of them and match /(.+)\1/.
Forgot to add: this is "weird" only in that it does a kludgey thing to
exploit an algorithm which you would otherwise have to write yourself.
------------------------------
Date: Wed, 24 May 2000 19:07:24 GMT
From: nfsite@my-deja.com
Subject: Getting HTML source
Message-Id: <8gh990$pd9$1@nnrp1.deja.com>
Hi
I only need to get the source of an HTML page into an var.
FOr example:
$source = &get("www.yahoo.com");
Can someone help me?
I would like it to work in both Unix Perl and WinPerl...
Thanks in advance
Nuno.Felicio@bigfoot.com
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 24 May 2000 12:32:55 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Getting HTML source
Message-Id: <392C2E67.50A73E69@vpservices.com>
nfsite@my-deja.com wrote:
>
> I only need to get the source of an HTML page into an var.
> FOr example:
>
> $source = &get("www.yahoo.com");
You need to use the LWP (libnet) modules.
#!perl -w
use strict;
use LWP::Simple;
my $source = &get("http://www.yahoo.com/");
> I would like it to work in both Unix Perl and WinPerl...
Yes it does, get the libnet modules for Unix from CPAN and for windoze
from activeState.
--
Jeff
------------------------------
Date: Wed, 24 May 2000 12:35:57 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Getting HTML source
Message-Id: <Pine.GSO.4.10.10005241229470.14618-100000@user2.teleport.com>
On Wed, 24 May 2000 nfsite@my-deja.com wrote:
> I only need to get the source of an HTML page into an var.
Use LWP::Simple, or another part of LWP. You can get LWP from CPAN.
> I would like it to work in both Unix Perl and WinPerl...
You may need to get LWP for Windows from ActiveState.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 24 May 2000 19:35:53 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: Getting HTML source
Message-Id: <taWW4.86484$h01.625659@news1.rdc1.mi.home.com>
[Posted and mailed]
In article <8gh990$pd9$1@nnrp1.deja.com>,
nfsite@my-deja.com writes:
> Hi
>
> I only need to get the source of an HTML page into an var.
> FOr example:
>
> $source = &get("www.yahoo.com");
>
> Can someone help me?
>
> I would like it to work in both Unix Perl and WinPerl...
use LWP::Simple;
$content=get("http://www.yahoo.com");
All you get is the source. Did you expect Perl to parse and render
the HMTL for you or something?
(Doesn't mean it can't given the right modules... :)
--
Clinton A. Pierce Teach Yourself Perl in 24 Hours!
clintp@geeksalad.org for details see http://www.geeksalad.org
"If you rush a Miracle Man,
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: Wed, 24 May 2000 12:52:21 -0700
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: Getting HTML source
Message-Id: <392C32F5.17438BD5@jpl.nasa.gov>
nfsite@my-deja.com wrote:
> I only need to get the source of an HTML page into an var.
> FOr example:
>
> $source = &get("www.yahoo.com");
>
> Can someone help me?
>
> I would like it to work in both Unix Perl and WinPerl...
Do you have the libwww-perl bundle which includes LWP::Simple from
CPAN? Your code snippet comes tantalizingly close to being correct, but
read the LWP::Simple documentation to do the job right. (This bundle
has been tested on Windows and several flavors of UNIX.)
Jon
--
Knowledge is that which remains when what is
learned is forgotten. - Mr. King
------------------------------
Date: Wed, 24 May 2000 13:01:59 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Getting HTML source
Message-Id: <392C3537.97B0B5@vpservices.com>
Jeff Zucker wrote:
>
> nfsite@my-deja.com wrote:
> >
> > I only need to get the source of an HTML page into an var.
> > FOr example:
> >
> > $source = &get("www.yahoo.com");
>
> You need to use the LWP (libnet) modules.
Sorry, I did not mean libnet, I meant libwww.
--
Jeff
------------------------------
Date: Wed, 24 May 2000 21:07:58 +0200
From: Christian Winter <thepoet1@arcormail.de>
Subject: Re: Global variables to apply to multiple Perl scripts
Message-Id: <ea9hg8.ufi.ln@usenet-autoren.de>
A Pietro <apietro@my-deja.com> schrob:
> What I want to do: user unzips, then types install, enters the required
> install directory, then files are copied to correct locations, *along with
> correct permissions (important)*
> Maybe I can just extend this existing script...after all, I don't need a
> full-blown "make install" type install script as I am just slotting in a few
> Perl scripts -- its finding where to slot them that is the difficult part.
Well, it would be just asking for the two path with
print "Enter cgi-bin directory: ";
my $cgidir = <STDIN>;
chomp $cgidir;
(Maybe in a loop until $cgidir has a sensible value).
Then copying the files to those directories using File::Copy and,
depending on $^O (Operating System type), adding the chmod routine
for the cgi scripts and data files and unlink'ing the old files.
HTH
Christian
------------------------------
Date: Wed, 24 May 2000 21:33:09 +0100
From: "A Pietro" <apietro@my-deja.com>
Subject: Re: Global variables to apply to multiple Perl scripts
Message-Id: <8gheaa$b0p$1@sshuraab-i-1.production.compuserve.com>
Thanks for your reply. I'll look into this...
Anyone know of any web resources covering install scripts for Linux?
AP
------------------------------
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 3151
**************************************