[19291] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1486 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 10 09:10:39 2001

Date: Fri, 10 Aug 2001 06:10:14 -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: <997449014-v10-i1486@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 10 Aug 2001     Volume: 10 Number: 1486

Today's topics:
        This is not a question ... call me slow if you like... <paul@net366.com>
    Re: Update: (Perl) programming contest loosely based on (Yves Orton)
    Re: Useragent Posting help (Helgi Briem)
        Using LWP to traverse site & download file (Richard Lawrence)
    Re: Why is $i so popular? <bart.lateur@skynet.be>
    Re: Why is $i so popular? (Yves Orton)
    Re: Why is $i so popular? (Anno Siegel)
    Re: Why? <paul@net366.com>
    Re: win32::registry help <paul@net366.com>
        Would like some feedback on idea for search-engine <wvijvers@SAYNOTOSPAMscience.uva.nl>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 10 Aug 2001 13:35:01 +0100
From: "Paul Fortescue" <paul@net366.com>
Subject: This is not a question ... call me slow if you like...
Message-Id: <997446825.1634.0.nnrp-13.d4f094e4@news.demon.co.uk>

But I think I've just realised what those funny signatures are at the bottom
of these postings.

@qw=qw(7588881823385188857888880728880386542800888078888878747848888858883
6355846872680811787478611380068288636858212873086248114818131508708
2371805863682088633728043188888082866818205877086718888858888868585
8333831853787448847168001588888584587848711830781268427838888878814
8278556862186842086468176481528482278868520877786658157838242328282
0884370188835588802648647781238385003873888571687578656818888848308
05477507204525052733321126742406643210160004763766012751707
03320623146017026142522157273313541232402205323105067573236
88882488888088810802434876781288874788820822838888858883488
83768286616185283870310877186830687805483838538760068758788
84268388888286854857032888882888883813746883648888858287488
88883088888288367804360803185888887846640887148888868831688
85271180454680837876177856383811687825284848138021048182574
85453388888181287888827845580841684088865840808888838148188
); foreach $qw (@qw) {$qw=~s/[0-79]/_/g; print "$qw\n";}






------------------------------

Date: 10 Aug 2001 04:59:16 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: Update: (Perl) programming contest loosely based on the prisoners' dilemma
Message-Id: <74f348f7.0108100359.2b7908f4@posting.google.com>

"Steffen M?ler" <tsee@gmx.net> wrote in message news:<9kuoa0$cqc$00$1@news.t-online.com>...
> Here's the follow-up I promised to translate:
> 
> This is just an idea, not the finished task description:
> 
> For every (contest) entry, an entity in a two-dimensional matrix that is
> limited in size but border-less (picture a sphere's surface area). Every
> entity can 'see' / analyse only thus far - say 2 units in each direction. If
> there are opponents within its vicinity (sp?), the entry will see them. (A
> matrix of 1's and 0's is passed to the function/object/module/package, you
> name it.)
> Each turn, each entry can move one space in any direction. Each entry has a
> certain 'size' to begin with. Call it life points or population. If two
> entries meet, they confront each other by the rules of the iterated PD (or
> similar rules). Say 50 iterations. The winner grows, the looser shrinks.
> This has something of an evolution.
> 
> More interesting would be if there weren't 'health points', but rather a
> number of separated entities for each entry that are randomly distributed in
> the matrix. If an entity looses a confrontation, it gets assimilated by the
> winning strategy. If two instances of the same entry meet, nothing happens
> (they are allies). In this modification, the entries would be able to
> distinguish between allies and hostiles.
> 
> Problem: What happens when three entities meet at one place & time?
> 
> Anyway, as I stated before, this is just an idea for a task. I already feel
> bad for posting so much off-topic that I am not going to continue ranting
> about my ideas for an implementation.
> 
> That's why eMails are still very welcome.
> 
> Interested? Let me know, please.
> 
> Thanks,
> Steffen

This sounds like Core-Wars or Core-Bots.

Yves
Im interested in hearing more though. Sounds neat.


------------------------------

Date: Fri, 10 Aug 2001 12:59:01 GMT
From: helgi@NOSPAMdecode.is (Helgi Briem)
Subject: Re: Useragent Posting help
Message-Id: <3b73d9b9.1571158957@news.isholf.is>

On 9 Aug 2001 15:41:39 -0700, benz@op.net (greg) wrote:

>How could i simulate the form below and get the result to display on
>my page.  What would the code look like using useragent?  I must be
>doing this wrong, because when I try it gives me hertz's error page
>instead of the search results.
<SNIP>

Try florking your googlefetz or maybe 
upfleebling your XP3 norklestinger.  

If that doesn't work, asking for help in
comp.infosystems.www.authoring.cgi
might be the way to go or the author
of ISNIWEBB.EXE might know how his 
program works.

Regards,
Helgi Briem


------------------------------

Date: 10 Aug 2001 03:14:26 -0700
From: ralawrence@my-deja.com (Richard Lawrence)
Subject: Using LWP to traverse site & download file
Message-Id: <b1b8a8d6.0108100214.7a8cfbf9@posting.google.com>

Hi all,

I have to be honest in the fact that I'm a little uncertain which NG
this should go to because I don't know whether its my lack of
understanding about perl or how HTTP works thats causing the problem.

I've written a perl script which attempts to download MAME ROM's
automatically from www.mame.dk. Following examination of the site I
have concluded that the method to download a ROM is the following:

 1. Assuming the rom name is "foo" go to
         http://www.mame.dk/download/rom/foo/
 2. Here you will find a disclaimer with a link to
         http://www.mame.dk/download/rom/foo/?[lots of numbers and
letters]
 3. Visiting that page you'll find a link to
         http://roms.mame.dk/[random numbers and letters]/[more random
numbers]/cur/foo.zip
 4. After that page you'll find a link to the actual location of the
rom which can then be downloaded

I noticed that the pages are not session, cookie or site dependent and
only GET is used. For example, I can do all the steps up to 4 in one
browser from lynx telnetting to somewhere in the US and then put the
final url into IE here in the UK and it will happily download the rom.

However, I'm stuck. My code outputs the following:

$ getrom.pl rampage       
Checking for availability of rampage ...
[debug] http://www.mame.dk/download/rom/rampage/
Getting rom size and location ...
[debug] http://www.mame.dk/download/rom/rampage/997438011|43a739631f742d5f615e762865372972
Failed! (couldn't read size of file)

The reason it can't read the size of the file is because after
following the last link, it ends back at the disclaimer again.

The code for this can be found at
http://www.spod.org/~richard/getrom.pl and I've included it below:

#!/usr/bin/perl

# getrom v1.1 (24 July 2001)
# Simple perl script to download a MAME ROM from www.mame.dk
# Copyright (c) Richard Lawrence 2001
#
# Released under the GNU GPL and all that.
#

use strict;
use LWP;
use URI::Escape;

my $referer;  # where we came from
my $source;  # source code downloaded

#
# download_page(url, args)
# returns source code
#
sub download_page
{
  my $url = $_[0];
  $url .= "?$_[1]" if ($_[1]);

  my $ua = new LWP::UserAgent;  
  $ua->agent("Mozilla/4.0 (compatible; MSIE 5.01; Windows 98;
DigExt)");

  print "[debug] $url\n";

  my $req = new HTTP::Request GET => "$url";
  $req->referer($referer);

  my $res = $ua->request($req);
  my $retval = $res->content;

  $referer = $url;

  return $retval if ($res->is_success);

  die "Unable to connect to: $url";
}

#
# Download a binary file to the hard drive
# download_file (url_to_file, filename)
#

sub download_file
{
  my $url = $_[0];
  my $filename = $_[1];

  my $ua = new LWP::UserAgent;
  
  $ua->agent("Mozilla/4.0 (compatible; MSIE 5.01; Windows 98;
DigExt)");
  my $req = new HTTP::Request GET => "$url";
  $req->referer($referer);
  my $res = $ua->request($req, $filename);

  $referer = $url;

  return 1 if ($res->is_success);
  return 0;
}

#
# main code
#

my $rom = $ARGV[0];

unless ($rom)
{
  print "Usage: $0 <rom name>\n";
  exit;
}

# remove .zip ending and lower-case
$rom =~ tr/A-Z/a-z/;
$rom =~ s/^(.+)\.zip$/$1/gi;

# set the referer and then try to get the disclaimer page for this rom

$referer = "http://www.mame.dk/gameinfo/$rom/";
print "Checking for availability of $rom ...\n";

$source = download_page("http://www.mame.dk/download/rom/$rom/", "");
unless ($source =~ /<b style=\"bigstdtext\"><a href=\"\?(.+?)\">/)
{
  print "Failed! (ROM does not exist or couldn't find 'I agree'
url)\n";
  exit(0);
}
my $url = $1;

# use the url on the disclaimer page to get the final download page
# this tells us what the file size is and the actual location of the
rom

print "Getting rom size and location ...\n";

$source = download_page("http://www.mame.dk/download/rom/$rom/",
"$url");
unless ($source =~ / +(\d.+? kb)/)
{
  print "Failed! (couldn't read size of file)\n";
  exit(0);
}
my $size = $1;

# get the rom!

print "Downloading $rom.zip ($size), please wait ...\n";

unless ($source =~ /http:\/\/roms.mame.dk\/.+?\/$rom.zip/)
{
  print "Failed! (could not find location to rom)\n";
  exit(0);
}
my $file = $1;

if (download_file($file, "$rom.zip"))
{
  print "Finished!\n";
  exit(0);
}
else
{
  print "Failed! (could not download rom)\n";
  exit(0);
}

Can anyone advise on what I'm doing wrong? If I have posted to the
wrong newsgroup, please could someone point me to the right one? As
you can see from the date i've been working on it for some time now
and totally stuck!

Many thanks in advance!

Rich


------------------------------

Date: Fri, 10 Aug 2001 12:05:47 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Why is $i so popular?
Message-Id: <dhj7nt4qtjor3ucnpj332plcahb00ibaa0@4ax.com>

Paul Fortescue wrote:

>I don't however, know why foo and bar exist, I was already past it by then!

There appears to be an RFC about it.

	<ftp://ftp.rfc-editor.org/in-notes/rfc3092.txt>

But do note the date.

-- 
	Bart.


------------------------------

Date: 10 Aug 2001 05:15:15 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: Why is $i so popular?
Message-Id: <74f348f7.0108100415.41ba0b07@posting.google.com>

Uri Guttman <uri@sysarch.com> wrote in message news:<x74rrh9fpz.fsf@home.sysarch.com>...
> >>>>> "LM" == Lou Moran <lmoran@wtsg.com> writes:
> 
>   LM> Why is $i such a popular variable?
>   LM> Is there any significance to it, or is it a foo bar sort of thing?
>   LM> Just wondering.
> 
> sorta like foo but with a real technical origin. i stands for integer
> and also iterator and was used way back in '57 with the first fortran as
> loop variables. fortran has a bizarre feature, if you didn't declare a
> variable, its type (integer or float) would be determined by the first
> letter of the variable name. so it if began with I-N (IIRC) it was an
> integer, otherwise a float. this led to the common use of I, J, K,
> etc. as iterator or coordinate vars which lives on today.

Also there is an interesting point for those that do hungarian
notation.  i is the prefix for an integer.  Hngarian says that it is
acceptable to use _just_ the type letter in a varname.  The rule is
something like
Mandatory_type_Prefix.Optional_User_Name.Optional_Postfix (cantremeber
what the Postfix is, not a big fan of hungarian)
So ultimately 'i' is one of the few single letter vars that are
'legal' in hungarian notation. (There are obviously a couple more, but
not so many, d,i,l,r,f *I think*)

Also its so much easier to type than $index or $iterator.

But I agree unless its used _as_ an index I wouldnt use it for much
either.

Yves
Ps Slighlty different question, what the origin of @_ and $_?  Is
there a story to it or did it just happen?


------------------------------

Date: 10 Aug 2001 13:00:49 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Why is $i so popular?
Message-Id: <9l0lu1$mqh$1@mamenchi.zrz.TU-Berlin.DE>

According to Uri Guttman  <uri@sysarch.com>:
> >>>>> "LM" == Lou Moran <lmoran@wtsg.com> writes:
> 
>   LM> Why is $i such a popular variable?
>   LM> Is there any significance to it, or is it a foo bar sort of thing?
>   LM> Just wondering.
> 
> sorta like foo but with a real technical origin. i stands for integer
> and also iterator and was used way back in '57 with the first fortran as
> loop variables. fortran has a bizarre feature, if you didn't declare a
> variable, its type (integer or float) would be determined by the first
> letter of the variable name. so it if began with I-N (IIRC) it was an
> integer, otherwise a float. this led to the common use of I, J, K,
> etc. as iterator or coordinate vars which lives on today.
> 
> and before that, it was commonly used in math for coordinates (i,j),
> etc. so it is a very ancient usage.
 
Quite.  For a long time mathematicians have used i (and j, k, ...)
for *i*ndexes and n (and m, since o was avoided) for *n*atural numbers.
This tradition was followed even more strictly in applied mathematics,
where it got so that you could use any of the variables i, j, ... n
to mean "this is an integer" without explicitly saying so. (In pure
mathematics all variables are usually defined.)

I don't have a cite to prove it, but it seems more than plausible
that the designers of FORTRAN had this convention in mind when they
decided about the default types of variables depending on their
first letter.  After all, they were writing a FORmula TRANslator
for people who were used to the convention.

> but i doubt i will ever write code with $i. i just like more realistic
> iterator names and i don't do much matrix math where it would be ok IMO.

I use $i, $j, ... $n happily when I want a generic index or just
any integer.  In a larger context, there often is a more descriptive
name for these, but in general-purpose subroutines, what else is there?

Anno


------------------------------

Date: Fri, 10 Aug 2001 13:40:13 +0100
From: "Paul Fortescue" <paul@net366.com>
Subject: Re: Why?
Message-Id: <997447137.1796.0.nnrp-13.d4f094e4@news.demon.co.uk>


"Bart Lateur" <bart.lateur@skynet.be> wrote in message
news:v295ntg5cosv7nhqj0mmal2d5m8e5ta0ep@4ax.com...
> Paul Fortescue wrote:
>
> >Thanks, Bart. I did RTFM but it is not easy for me to understand. I did
not
> >understand that while ($line=<HTML>) is the same thing as
> >$line=readlne(*HTML). I think I will recode it like you say, but I still
> >don't understand the difference between HTML and *HTML. I think it is
> >something to do with referencing or typeglobs but I am new to Perl so I
will
> >struggle!
>
> "New to perl"? Yet, typeglobs etc. are pretty advanced topics in my
> view. I would have stayed away from them for at least the first few
> months.
>
> But, anyway, filehandles look like barewords. Ordinarily (unless
> "strict" forbids it), if barewords are not keywords or (already defined)
> user defined subs, Perl treats these as strings. I think that is what
> happens. Only some built-ins expect a file handle for a parameter, and
> recognize file handles as such. I think readline() is not amonst them,
> but <...> is. In fact, I'm a bit surprised that readline() is even in
> perlfunc (the keyword glossary), as I would have thought it is actually
> a method belonging to the IO::Handle module. Er... which it isn't...?
> Anyway: treating a bareword (string) as a handle actually often works as
> a form of symbolic reference. So I do think
>
> readline HTML
>
> is interpreted as
>
> readline "HTML"
>
> which may succeed, or fail, depending on, er, the phases of the moon or
> something. It's all pretty vague and unchartered territory. I wouldn't
> go there. Anyway, it WILL fail if you try to use it in another package.
>
> But a typeglob, or even a reference to a typeglob ( \*HTML ) can always
> be used, passed, and interpreted as a filehandle. I think.
>
> BTW the "<HANDLE>" syntax instead of the function call is invented as a
> handy shortcut, because I/O is used so very often. It may look a bit
> weird at first, but it is indeed very handy.
>
> >If the manual was like Windows instead of like UNIX :) ...
>
> If you have a perl for Windows, then the docs are on your disk as html
> as well. Now, search for a HTML file in perl's file tree, whose bare
> name is "perlop" (perl operators), and go to the section on
> IO-operators.  Skip the paragraph on backticks (I wonder why *that* is
> there upfront?), and start reading.
>
> --
> Bart.

Thanks again. I have ordered several books including Mastering Regular
Expressions so I will do some geeky reading this weekend! I take your point
about typeglobs being a bit advanced, trouble is, I don't know they're
advanced until I get into trouble. I also did read things as you have
suggested, but as you say, when it starts off with backticks (I don't even
know what that means, nor bareword, nor several other terms) I panic and
look for something else. What I was looking for was a nice index which shows
me what it is that I need to read next :). Anyway, this user group is
excellent.




------------------------------

Date: Fri, 10 Aug 2001 13:44:36 +0100
From: "Paul Fortescue" <paul@net366.com>
Subject: Re: win32::registry help
Message-Id: <997447400.1958.0.nnrp-13.d4f094e4@news.demon.co.uk>


"Joseph" <boogiemonster@usa.net> wrote in message
news:9kc7m0$d90$1@usenet01.srv.cis.pitt.edu...
> I'm trying to connect to a remote machine using Win32::Registry.  I want
to
> delete key and all its sub key.  Is there way to do this without expanding
> each individual trees and delete one at a time then finally to the root?
is
> there a easier method?  following is my code....any help would be
> appreciated...
>
> use Win32::Registry;
>
> %KeyName =
>
>      SoftwareRoot => 'Software\Microsoft',
>      LaunchPath  => 'Windows\CurrentVersion\Run',
> );
>
> $Root = $HKEY_LOCAL_MACHINE;
>
> if ($Machine = $ARGV[0])
> {
>      $HKEY_LOCAL_MACHINE->Connect ($Machine, $Root ) || die "Could not
> connect to the Registry on '$Machine'\n;"
> }
>
> if ( $Root->Open ($KeyName{SoftwareRoot}, $Links))
> {
>
>           $Links->DeleteKey("test1"); #there are sub keys in both of these
> keys....
>           $Links->DeleteKey("test");
>
>      if ($Links->Open ($KeyName{LaunchPath}, $Links2))
>      {
>           $Links2->DeleteValue("SMS Application Launcher");
>      }
>      $Links2->Close;
> }
> $Links->Close;
>
>
Deleting a key in Windows Registry deletes all of its subkeys.




------------------------------

Date: Fri, 10 Aug 2001 13:39:20 +0200
From: "W.A.J. Vijvers" <wvijvers@SAYNOTOSPAMscience.uva.nl>
Subject: Would like some feedback on idea for search-engine
Message-Id: <3B73C7E8.FD197564@SAYNOTOSPAMscience.uva.nl>

Hi fellow perlers,
I'm writing a CGI application that manages an online archiving system.
I'm now starting to implement a search-engine for the archive and I
would like some feedback on the idea I have for it. Maybe you're
thinking I should use a RDBMS or a fancy module, but I would like to
impose as little as possible on the systems that this will run on (I
want to sell it as a self-contained package), so I want to go with a
textfile-based database. All the info about the documents in the archive
is contained in its filename (format:
Title_of_doc.yyyymmdd.author.kenmerk.ext (dunno a translation of
kenmerk)). I want the users to be able to search for either title, date
or kenmerk within a certain date-range. For the search I would like to
create an index of the following form:

===============
search_title.db
===============
20010809|Title of doc
:Title of doc|Name
Surname|09-08-2001|kenmerk|ext|category/sub-cat|maybe.full.filename.here
(...repeat for every document...)

===============
search_author.db
===============
20010809|Name Surname
:Title of doc|Name
Surname|09-08-2001|kenmerk|ext|category/sub-cat|maybe.full.filename.here

and a similar file for "kenmerk" and three more for hidden documents
(non-public ones, to be accesed with password). This would allow me to
run through the file pretty quickly (skipping all the lines that start
with ":" unless the previous line matched). Another opion would be to
only have "Title_of_doc" on the first line and then check the date-range
in the second line if the title matched. The fact that I have to build 3
different databases doesn't bother me that much.

What do you guys think of this idea? Can it be easier? Should I use
DB_File and a different format instead? I should note that it has to run
on both Windows and UNIX. I think that the maximum number of files in
the archive will be about 1000 (probably along the lines of 400-500).
I'm also open to completely different solutions.

Thanks a lot, regards,
Wouter

--
The right half of the brain controls the left half of the body.
This means that only left handed people are in their right mind.


------------------------------

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.  

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 1486
***************************************


home help back first fref pref prev next nref lref last post