[26830] in Perl-Users-Digest
Perl-Users Digest, Issue: 8859 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 17 09:05:25 2006
Date: Tue, 17 Jan 2006 06:05:06 -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 Tue, 17 Jan 2006 Volume: 10 Number: 8859
Today's topics:
Re: Creating and outputting a generic data structure? (Anno Siegel)
Re: Creating and outputting a generic data structure? <ithinkiam@gmail.com>
Re: Script execution blocked when reading from a socket (Anno Siegel)
Re: wget Question <noreply@gunnar.cc>
Re: wget Question <noreply@gunnar.cc>
Re: wget Question <kigar@gmx.net>
Re: wget Question <jurgenex@hotmail.com>
Re: wget Question <1usa@llenroc.ude.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 17 Jan 2006 11:53:03 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Creating and outputting a generic data structure?
Message-Id: <dqilqv$l3h$1@mamenchi.zrz.TU-Berlin.DE>
Chris <ithinkiam@gmail.com> wrote in comp.lang.perl.misc:
> Hi all,
>
> I'm having difficulty trying to genericise this problem and
> am looking for suggestions to point me in the right direction:
>
> Take the following string:
> LVFSGVLPLGTDTQNADI(SF)LWAKSFGAVIASKINM(KNA)TTHLVAGRNRT(DAGV)KVREATRYPKVKIVTTQWLLDCLTQWKRLAEEPYLLP
Your example is exquisitely opaque. Why does it have to be a super-long
string in all upper case? I'll use
'XXX(sf)YYY(kna)ZZZ(dgav)UUU'
instead, which is a lot easier to follow.
> The letters in brackets are ambiguous positions where any of
> the letters are allowed in that position. I want output all
> the allowed combinations of the ambiguous positions e.g.
I had to resort to your code to see that "any of the letters" are the
letters inside the parentheses (not any letter). It is also not clear
at this point that each group of parentheses stands for a single letter
in the final string.
> LVFSGVLPLGTDTQNADISLWAKSFGAVIASKINMKTTHLVAGRNRTDKVREATRYPKVKIVTTQWLLDCLTQWKRLAEEPYLLP
> LVFSGVLPLGTDTQNADISLWAKSFGAVIASKINMNTTHLVAGRNRTAKVREATRYPKVKIVTTQWLLDCLTQWKRLAEEPYLLP
> etc. ^ ^ ^
>
> There can be any number of ambiguous positions with upto 4
> allowed letters per position.
>
> The code below correctly outputs all the combinations for
> the above example, but I want to make this more generic for
> more or less ambiguous positions. I would appreciate any
> pointers as this has been bugging me for days now :-(
> It only outputs the ambiguous letters - I can add in the
> rest easily enough later.
[code snipped]
Here is a recursive solution:
sub expand {
my $template = shift;
return $template unless $template =~ /\(([[:alpha:]]*)\)/;
my @expanded;
for my $char ( split //, $1 ) {
push @expanded, $template;
substr( $expanded[ -1], $-[ 0], $+[ 0] - $-[ 0]) = $char;
}
return map expand( $_), @expanded;
}
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: Tue, 17 Jan 2006 14:03:17 +0000
From: Chris <ithinkiam@gmail.com>
Subject: Re: Creating and outputting a generic data structure?
Message-Id: <dqitf5$1p9i$1@godfrey.mcc.ac.uk>
Anno Siegel wrote:
> Chris <ithinkiam@gmail.com> wrote in comp.lang.perl.misc:
>> Hi all,
>>
>> I'm having difficulty trying to genericise this problem and
>> am looking for suggestions to point me in the right direction:
>>
>> Take the following string:
>> LVFSGVLPLGTDTQNADI(SF)LWAKSFGAVIASKINM(KNA)TTHLVAGRNRT(DAGV)KVREATRYPKVKIVTTQWLLDCLTQWKRLAEEPYLLP
>
> Your example is exquisitely opaque. Why does it have to be a super-long
> string in all upper case? I'll use
>
> 'XXX(sf)YYY(kna)ZZZ(dgav)UUU'
>
> instead, which is a lot easier to follow.
I can see that your generic example is clearer, but I
thought it better to use a real world example. BTW it needs
to be all upper case and my example is short in my context.
>
>> The letters in brackets are ambiguous positions where any of
>> the letters are allowed in that position. I want output all
>> the allowed combinations of the ambiguous positions e.g.
>
> I had to resort to your code to see that "any of the letters" are the
> letters inside the parentheses (not any letter). It is also not clear
> at this point that each group of parentheses stands for a single letter
> in the final string.
Apologies for the lack of clarity, hence why I prefer
explaining things with examples.
>> LVFSGVLPLGTDTQNADISLWAKSFGAVIASKINMKTTHLVAGRNRTDKVREATRYPKVKIVTTQWLLDCLTQWKRLAEEPYLLP
>> LVFSGVLPLGTDTQNADISLWAKSFGAVIASKINMNTTHLVAGRNRTAKVREATRYPKVKIVTTQWLLDCLTQWKRLAEEPYLLP
>> etc. ^ ^ ^
>>
>> There can be any number of ambiguous positions with upto 4
>> allowed letters per position.
>>
>> The code below correctly outputs all the combinations for
>> the above example, but I want to make this more generic for
>> more or less ambiguous positions. I would appreciate any
>> pointers as this has been bugging me for days now :-(
>> It only outputs the ambiguous letters - I can add in the
>> rest easily enough later.
>
> [code snipped]
>
> Here is a recursive solution:
>
> sub expand {
> my $template = shift;
> return $template unless $template =~ /\(([[:alpha:]]*)\)/;
> my @expanded;
> for my $char ( split //, $1 ) {
> push @expanded, $template;
> substr( $expanded[ -1], $-[ 0], $+[ 0] - $-[ 0]) = $char;
> }
> return map expand( $_), @expanded;
> }
>
> Anno
Thanks very much for your reply and very succinct answer :-)
I did think recursion was a way to do it, but it screws with
my head ;-)
I did not know about the @- and @+ variables; I'm sure I'll
use them again. One question though, is there any reason why
you used this:
substr( $expanded[ -1], $-[ 0], $+[ 0] - $-[ 0]) = $char;
instead of:
substr( $expanded[ -1], $-[ 0], $+[ 0] - $-[ 0], $char);
?
------------------------------
Date: 17 Jan 2006 12:13:49 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Script execution blocked when reading from a socket
Message-Id: <dqin1t$l3h$3@mamenchi.zrz.TU-Berlin.DE>
Mark <nospam@thanksanyway.org> wrote in comp.lang.perl.misc:
> Hello. I am attempting to write a simple program to scan ports to look for
> Quake 3
> servers. I adapted the code from the O'Reilly "Programming Perl" book.
>
> The script is invoked with a starting and ending IP address and a port, as
> follows:
>
> perl q3_search.pl 207.210.230.5 207.210.230.10 27960
>
> The script will usually scan a few addresses, and then it will hang.
> The hangup occurs when attempting to read from the socket. This happens
> whether
> I treat the socket as a file handle (as in this example), or if I use the
> recv() function.
>
> Suggestions?
>
> Thanks
> -Mark
>
> =======================================
> #!/usr/bin/perl -w
>
> # Q3_SEARCH.PL
> #
> # Based on "Programming Perl" p349
>
> require 5.002;
> use strict;
> use Socket;
> use Socket qw(:DEFAULT :crlf);
>
> my ($ipfirst, $iplast, $remote, $port, $iaddr, $paddr, $proto, $line);
>
> $ipfirst = shift;
> if ($ipfirst !~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/) {die "Invalid IP
> address as param #1";}
>
> $iplast = shift;
> if ($iplast !~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/) {die "Invalid IP
> address as param #1";}
> $port = shift || 27960; #Default Quake 3 Port
>
> if ($port =~ /\D/) { $port = getserverbyname($port, 'udp')}
> die "No port" unless $port;
>
> $remote = $ipfirst;
> my $exit_flag = 0;
>
> while (1)
> {
> print "Testing $remote\.\.\.\n";
> $iaddr = inet_aton($remote) or die "no host: $remote";
>
> $paddr = sockaddr_in($port, $iaddr);
> $proto = getprotobyname('udp');
> socket(SOCK, PF_INET, SOCK_DGRAM, $proto) or die "socket: $~";
> connect(SOCK, $paddr) or die "connect: $~";
>
> # Setting autoflush is supposed to help prevent blocking
> # when attempting to read from the socket. . .
> my $oldh = select(SOCK);$|=1;select($oldh);$|=1;
>
> defined(send SOCK, "\xff\xff\xff\xffgetstatus", 0) || goto NEXT_IP;
>
> # Select() is supposed to succeed if the socket has data,
> # or else timeout and return FALSE.
> if (!(select (SOCK, undef, undef, 10.0))) {goto NEXT_IP;}
Select guarantees that at least on character is available. You
are trying to read an entire line. Try reading a single character.
> # Script will eventually hang on the following line
> if (!defined($line = <SOCK>)) {goto NEXT_IP;}
> if ($line =~ "statusResponse")
> {print " $remote:$port is active\n";
> }
>
> close (SOCK) or die "close: $~";
> if ($exit_flag > 0) {last;}
[snip]
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: Tue, 17 Jan 2006 12:21:26 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: wget Question
Message-Id: <43425qF1l5tekU1@individual.net>
Reinhard Glauber wrote:
> Gunnar Hjalmarsson schrieb:
>>What did you do to find out before posting here? Did you possibly read
>>the docs for the functioh you are using?
>>
>> perldoc -f system
>
> Not installed on my system .. I'm lucky .. no one can blame me ;-))
> You need to install the perl-doc package to use this program.
No, you are not lucky, and anybody can blame you for not reading the
docs of the programming language you are using.
A few options:
- Install perldoc
- Install Perl on your PC. Since you seem to be on a Windows box, I'd
recommend the bundle at http://www.indigostar.com/indigoperl.htm, which
would give you the docs conveniently available as HTML documents.
http://www.activestate.com/ offers a similar bundle.
- Download the docs from http://www.activestate.com/
- Browse the docs on the web; in this case:
http://perldoc.perl.org/functions/system.html
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 17 Jan 2006 12:22:56 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: wget Question
Message-Id: <43428kF1l5tekU2@individual.net>
Gunnar Hjalmarsson wrote:
> - Download the docs from http://www.activestate.com/
Typo: I meant http://perldoc.perl.org/
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 17 Jan 2006 13:08:13 +0100
From: "Reinhard Glauber" <kigar@gmx.net>
Subject: Re: wget Question
Message-Id: <43ccde22$0$20779$9b4e6d93@newsread4.arcor-online.net>
DQoiR3VubmFyIEhqYWxtYXJzc29uIiA8bm9yZXBseUBndW5uYXIuY2M+IHNjaHJpZWIgaW0gTmV3
c2JlaXRyYWcgbmV3czo0MzQyOGtGMWw1dGVrVTJAaW5kaXZpZHVhbC5uZXQuLi4NCj4gR3VubmFy
IEhqYWxtYXJzc29uIHdyb3RlOg0KPiA+IC0gRG93bmxvYWQgdGhlIGRvY3MgZnJvbSBodHRwOi8v
d3d3LmFjdGl2ZXN0YXRlLmNvbS8NCj4gDQo+IFR5cG86IEkgbWVhbnQgaHR0cDovL3Blcmxkb2Mu
cGVybC5vcmcvDQoNCg0KYWFhYWgsIHZlcnkgbmljZSA6KQ0KdGhhbmtz
------------------------------
Date: Tue, 17 Jan 2006 12:18:10 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: wget Question
Message-Id: <6g5zf.14903$sq.14194@trnddc01>
Reinhard Glauber wrote:
> "Gunnar Hjalmarsson" <noreply@gunnar.cc> schrieb im Newsbeitrag
> news:433traF1llei7U2@individual.net...
>> Reinhard Glauber wrote:
>
>> What did you do to find out before posting here? Did you possibly
>> read the docs for the functioh you are using?
>>
>> perldoc -f system
>
>
> Not installed on my system .. I'm lucky .. no one can blame me ;-))
> You need to install the perl-doc package to use this program.
Well, then why don't you fix your broken Perl installation? Then you can
read the documentation yourself and don't have to ask someone else to read
them for you.
Oh, and to answer your original question: See perldoc -f system, third
paragraph, fourth sentence.
Not to mention that this Question is Asked very Frequently, too.
jue
------------------------------
Date: Tue, 17 Jan 2006 12:51:40 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: wget Question
Message-Id: <Xns974E5007EB976asu1cornelledu@127.0.0.1>
"Reinhard Glauber" <kigar@gmx.net> wrote in news:43ccbf22$0$21021$9b4e6d93
@newsread2.arcor-online.net:
> $answer = system("wget http://www.bla.de/bla/blaDetail.aspx?ID=$i");
>
> How can i push the content of a single html site into $answer ?
>
> This line doesn't work
Have you read the posting guidelines for this group?
In addition to Gunnar and Jurgen's comments, I suggest you take a look at
<URL:http://search.cpan.org/~gaas/libwww-perl-5.805/lib/LWP/Simple.pm>
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 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 8859
***************************************