[21836] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4040 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 28 21:17:01 2002

Date: Mon, 28 Oct 2002 18:11:38 -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, 28 Oct 2002     Volume: 10 Number: 4040

Today's topics:
        Pass by reference in OO (kit)
    Re: Pass by reference in OO <uri@stemsystems.com>
    Re: Pass by reference in OO <goldbb2@earthlink.net>
        Perl DBI - Multiple Databases on a single database serv <usenet@bens-house.org.uk>
    Re: Perl LDAP help, how to authenticate simple username (Kenneth Graves)
        Perl, Packages, Solaris and such things (David)
    Re: PERL, WIN32, and the Registry (John)
    Re: RegExpr <goldbb2@earthlink.net>
    Re: RegExpr PROTOTYPE-1@webtv.net
        regular expression <srikanth@unlserve.unl.edu>
    Re: regular expression <nobull@mail.com>
    Re: regular expression <nobull@mail.com>
    Re: regular expression <ak@freeshell.org.REMOVE>
    Re: significance of 42 for perl, any?!? <djberge@qwest.com>
    Re: Sub: how to access the internet programatically acr <goldbb2@earthlink.net>
    Re: Value in array with loop <reggie_nospam@reggieband.com>
    Re: Value in array with loop (Alan Barclay)
    Re: Win32: Hiding console window <minsc_tdp@hotmail.com>
    Re: Working out if string A is related to string B <pinyaj@rpi.edu>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 28 Oct 2002 13:54:17 -0800
From: manutd_kit@yahoo.com (kit)
Subject: Pass by reference in OO
Message-Id: <1751b2b5.0210281354.6befe962@posting.google.com>

I've been trying to use different methods to work on this mainscreen
class in perl, but I still couldn't make it. Could you plz take a look
at it?

I have a problem working with pass by reference from the constructor
to the member functions. It seems that the variable "myarray" isn't
not access by the redrawScreen function. I have tried to fix all the
syntax errors that I had before, and this is what I come up with.


#! /usr/bin/perl -w
package MainScreen;
# use strict;
use warnings;

sub new {        #default constructor
    my $proto = shift;
    my $class  =  ref($proto) || $proto;
    my $self  = {
       myarray => (' ' x 51) x 21,
       row => qw{ 1 1 1 1 1 1 1 2 4 6 8 10 12 14 15 15 15 15 15
               15 15 14 12 10 8 6 4 2 7 6 5 4 7 6 5 4 9 10 11
               12 9 10 11 12 1 2 3 4 12 13 14 15 15 14 13 12
               4 3 2 1 },
       col => qw{ 12 15 18 21 24 27 30 32 32 32 32 32 32 32 30
               27 24 21 18 15 12 10 10 10 10 10 10 10 19 17
               15 13 23 25 27 29 19 17 15 13 23 25 27 29 6 5
               4 3 3 4 5 6 36 37 38 39 39 38 37 36 },
    };
    bless ($self, $class);
    return $class;
}
 
sub init {      #explicit constructor
    my $self = shift;
    for my $k (0..59) {
        substr ($self->{myarray}[$self->{row}[$k]],
                                 $self->{col}[$k], 1)='O';
    }
}

sub redrawScreen {
    my $self = shift;
    for my $r (0..20) {
        print $self->{myarray}[$r], "\n"; #pass by ref. problem, line
45
    }
}
1;

the reason why I comment out "use strict", is because the compiler
gives me this
>> Can't use string ("MainScreen") as a HASH ref while "strict refs"
in use at MainScreen.pm

However, after I've commented out "use strict", I have this
>> Use of uninitialized value in print at MainScreen.pm line 45.

I am think if I have "pass by ref" problems in the redrawScreen, then
I should have the same problem in my explicit constructor, init.

When I call the problem, I use this:
 use MainScreen;
 my $display = MainScreen->new(); #Didn't go to the init constructor??
 $display->redrawScreen();

I have been trying so hard on this, but I should couldn't make it,
could you please help me out and solve my problems?

Thanks and have a nice day,
Kit


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

Date: Mon, 28 Oct 2002 23:22:00 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Pass by reference in OO
Message-Id: <x7elaaw3mv.fsf@mail.sysarch.com>

>>>>> "k" == kit  <manutd_kit@yahoo.com> writes:

  k>     my $self  = {
  k>        myarray => (' ' x 51) x 21,

that is not the way to make an array element in a data structure. you
need to use an anon array [] and stuff the data in there.

read perlreftut, perlref, perllol and perldsc for more info.

  k>        row => qw{ 1 1 1 1 1 1 1 2 4 6 8 10 12 14 15 15 15 15 15
  k>                15 15 14 12 10 8 6 4 2 7 6 5 4 7 6 5 4 9 10 11
  k>                12 9 10 11 12 1 2 3 4 12 13 14 15 15 14 13 12
  k>                4 3 2 1 },

same here and with col

  k>        col => qw{ 12 15 18 21 24 27 30 32 32 32 32 32 32 32 30
  k>                27 24 21 18 15 12 10 10 10 10 10 10 10 19 17
  k>                15 13 23 25 27 29 19 17 15 13 23 25 27 29 6 5
  k>                4 3 3 4 5 6 36 37 38 39 39 38 37 36 },
  k>     };
  k>     bless ($self, $class);
  k>     return $class;


why are you returning $class and not $self?

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Mon, 28 Oct 2002 18:31:01 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Pass by reference in OO
Message-Id: <3DBDC8B5.7EE69695@earthlink.net>

kit wrote:
[snip]
>     my $self  = {

Remember that the syntax for anonymous hashref constructor is {LIST}.

>        myarray => (' ' x 51) x 21,

This is like saying:
   "myarray", " ", " ", " ", # repeated many times.

Perl has no way of knowing that "myarray" is meant to be a key with all
of those spaces as it's data.  You have to explicitly turn that list of
spaces into an anonymous array.

         myarray => [ (' ' x 51) x 21 ],


>        row => qw{ 1 1 1 1 1 1 1 2 4 6 8 10 12 14 15 15 15 15 15
>                15 15 14 12 10 8 6 4 2 7 6 5 4 7 6 5 4 9 10 11
>                12 9 10 11 12 1 2 3 4 12 13 14 15 15 14 13 12
>                4 3 2 1 },

Same here:

         row => [ qw{ 1 1 1 1 ...blahblahblah...
                 4 3 2 1 } ],

>        col => qw{ 12 15 18 21 24 27 30 32 32 32 32 32 32 32 30
>                27 24 21 18 15 12 10 10 10 10 10 10 10 19 17
>                15 13 23 25 27 29 19 17 15 13 23 25 27 29 6 5
>                4 3 3 4 5 6 36 37 38 39 39 38 37 36 },

And here:

         col => [ qw{ 12 15 18 ...blahblahblah...
                 ...blahblahblah... 36 } ],

>     };
>     bless ($self, $class);
>     return $class;

Err, no.
      bless ($self, $class);
      return $self;

> }
> 
> sub init {      #explicit constructor
>     my $self = shift;
>     for my $k (0..59) {
>         substr ($self->{myarray}[$self->{row}[$k]],
>                                  $self->{col}[$k], 1)='O';
>     }
> }
> 
> sub redrawScreen {
>     my $self = shift;
>     for my $r (0..20) {
>         print $self->{myarray}[$r], "\n"; #pass by ref. problem, line
> 45
>     }
> }
> 1;
> 
> the reason why I comment out "use strict", is because

is because you have a bug in your program somewhere, and 'use strict'
exposes that bug.

> the compiler gives me this
> >> Can't use string ("MainScreen") as a HASH ref while "strict refs"
> in use at MainScreen.pm

That's because you returned "MainScreen" from your "new" method, instead
of returning a hashref.

> However, after I've commented out "use strict", I have this
> >> Use of uninitialized value in print at MainScreen.pm line 45.

That's because you try and use the string "MainScreen" as a hashref, and
when you try and get data out of it, you get an undef.  Printing out
that undef gives you "Use of uninitialized...."

> I am think if I have "pass by ref" problems in the redrawScreen, then
> I should have the same problem in my explicit constructor, init.
> 
> When I call the problem, I use this:
>  use MainScreen;
>  my $display = MainScreen->new(); #Didn't go to the init constructor??

If you want "init", you have to call "init".  What are you asking, here?

>  $display->redrawScreen();
> 
> I have been trying so hard on this, but I should couldn't make it,
> could you please help me out and solve my problems?

package MainScreen;
use strict;
use warnings;

use constant COORDINATES => do {
   my @rows = qw/ 1 1 1 1 1 1 1 2 4 6 8 10 12 14 15 15
      15 15 15 15 15 14 12 10 8 6 4 2 7 6 5 4 7 6 5 4
      9 10 11 12 9 10 11 12 1 2 3 4 12 13 14 15 15 14
      13 12 4 3 2 1 /;
   my @cols = qw/ 12 15 18 21 24 27 30 32 32 32 32 32
      32 32 30 27 24 21 18 15 12 10 10 10 10 10 10 10
      19 17 15 13 23 25 27 29 19 17 15 13 23 25 27 29
      6 5 4 3 3 4 5 6 36 37 38 39 39 38 37 36 /;
   map [ shift(@rows), shift(@cols) ], 0 .. $#rows;
};

sub new {
   my $class = shift;
   my $self = bless [ ("-" x 50 . "\n") x 20 ], $class;
   $self->init;
   $self;
}

sub init {
   my $self = shift;
   for my $row_col (COORDINATES) {
      my ($row, $col) = @$row_col;
      substr( $self->[$row], $col, 1 ) = "O";
   }
}

sub redrawScreen {
   print @{ +shift };
}

1;
__END__
[untested]

There isn't here anything *new* ... it's all the same parts as you had,
just rearranged a bit.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Mon, 28 Oct 2002 22:29:36 +0000
From: "Ben Holness" <usenet@bens-house.org.uk>
Subject: Perl DBI - Multiple Databases on a single database server
Message-Id: <3dbdb9d9$0$28311$fa0fcedb@lovejoy.zen.co.uk>

Hi all,

I have a MySQL database server, with a number of databases defined it.

I currently have a number of scripts, each of which maintain a connection
to the various databases (there is a many to one script to database
relation at the moment). These scripts poll the database every 4-15 seconds

As I am generating more and more of these scripts, I want to build a
framework, so that one perl process handles all of the polling from one
central place. The individual scripts then register callback functions.

What I would like to know is if I would be best off creating 5 or 6
database handles, one for each script, or a single database handle that
changes database 5 or 6 times every 4 seconds.

Many thanks,

Ben



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

Date: Mon, 28 Oct 2002 20:37:38 GMT
From: kag@kag.citysource.com (Kenneth Graves)
Subject: Re: Perl LDAP help, how to authenticate simple username and password in LDAP
Message-Id: <slrnarr80j.n9.kag@localhost.citysource.com>

In article <dd37cdb4.0210280813.c71bcfc@posting.google.com>,
Nozer Damania wrote:
>I have a simple LDAP structure, i am trying to authenticate usernames
>and passwords against LDAP.
>
>Unfortunately the passwords in LDAP are crypted. I use Mozilla::LDAP
>package., so how do i check a valid combination of usernames and
>passwords??
>
>I tried the search string with
>"(uid=$username,userPassword=$password)", i tried crypting it adding
>{crypt} b4 the passwords, NOTHING works

Two approaches:
Assuming you know the encryption routine, apply it to the claimed
password, then compare to what's in the directory.

Alternatively, try to bind to the directory with the claimed password.
If the bind succeeds, the password was correct.

--kag


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

Date: 28 Oct 2002 16:11:54 -0800
From: david444williams@yahoo.com (David)
Subject: Perl, Packages, Solaris and such things
Message-Id: <cdca58e3.0210281611.480feda1@posting.google.com>

For the past week, I have been trying to get working the following
perl setup:
- apache + mod_perl + perl + solaris 9

Is there a recommended combination of versions???
eg.
- solaris 9 (core install, developer install, etc)
- perl (5.6, 5.8, 32/64 bit)
- mod_perl (1.0 or 2.0)
- apache (1.3 or 2.x)

I have been running in many problems including:
- installed solaris with perl, then had problems compiling mod_perl
- installed solaris core install, then had problems with gcc
- compiling DBI-Oracle but errors between 32bit and 64bit oracle oci
- compiling with gcc 3.2 when gcc 2.95 may be better

I know this is all very generalized, but I feel that although I can
work through each problem, I think the combinations of versions I am
using are causing more problems than I probably need to address.

Any help, flames, anything appreciated
David

PS. The solaris box I am using is a development server, so I have
complete control over it and can start with a complete fresh OS
install if need be.


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

Date: 28 Oct 2002 13:09:01 -0800
From: tkd-texan@attbi.com (John)
Subject: Re: PERL, WIN32, and the Registry
Message-Id: <d73d8f.0210281309.67e4ebdf@posting.google.com>

Mr. McCauley,

  Thank you for your assistance. :-)

Brian McCauley <nobull@mail.com> wrote in message news:<u9smyq3esb.fsf@wcl-l.bham.ac.uk>...
> tkd-texan@attbi.com (John) writes:
> 
> > use Win32::TieRegistry ( Delimiter=>"/" );
> > use strict;
> > my $Registry;
> > my $tips;
> > $tips=
> > $Registry->{"HKEY_LOCAL_MACHINE/Software/Microsoft
> > /"}->
> >          {"Windows/CurrentVersion/Explorer/Tips/"}
> >       or  die "Can't find the Windows tips:
> > $^E\n";
> 
> In the above code the lexical varible $Registry does not contain
> anything special - it's just a plain undefined scalar.
> 
> You probably wanted to use the package variable $Registry that is
> exported by Win32::TieRegistry.


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

Date: Mon, 28 Oct 2002 16:11:02 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: RegExpr
Message-Id: <3DBDA7E6.206F520E@earthlink.net>

Mary Wong wrote:
[snip]
> to find words have their letters in
> alphabetical order
> 
> /a?b?c?d?e?f?g?h?i?j?k?l?m?n?o?p?q?r?s?t?u?v?w?x?y?z?/

To get this regex to work right, you need an anchor at the beginning
(^), an anchor at the end (either $ or \z), and you need to change the
?s into *s.  And you probably want a /i flag.

   /^a*b*c*d*e*f*g*h*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z*\z/i

But even so, it's not the most elegant way of doing it.

Perhaps this:

   sub in_alphabetical_order {
      my @sorted = sort my @letters = split //, uc shift;
      local $" = "";
      "@sorted" eq "@letters";
   }
   [untested]

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Mon, 28 Oct 2002 19:55:53 -0500 (EST)
From: PROTOTYPE-1@webtv.net
Subject: Re: RegExpr
Message-Id: <1984-3DBDDC99-485@storefull-2178.public.lawson.webtv.net>

Mary Wong wrote: 
>Hi,
>
>I am searching some words
>Is there any better way to do that?
>to find words contain 3 or more pairs of double letters ([a-z][a-z]){3}

Need more info than that, but try this:

$x="&aazaaa bbb www.perl.com cc"; 
print "$1\n" while $x =~
/(?:^|\s)((?:[a-z]*)([a-z])\2{2,}(?:[a-z]*))(?:\s|\.?$)/g;

>to find words have their letters in alphabetical order

$x="aazaaax abx &abc cc zxy";
while( $x =~ /(?:^|\s)([a-z]{2,})(?:\s|\.?$)/g ) { 
print "$1\n" if $1 eq join("",sort(split("",$1))) }



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

Date: Mon, 28 Oct 2002 13:45:11 -0600
From: "unlnews.unl.edu" <srikanth@unlserve.unl.edu>
Subject: regular expression
Message-Id: <apk48q$74b$1@unlnews.unl.edu>

How can I write a regular expression to extract a number at the end of a
string in a perl program.

Thanks
Srikanth




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

Date: 28 Oct 2002 19:53:43 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: regular expression
Message-Id: <u9iszmcpbs.fsf@wcl-l.bham.ac.uk>

"unlnews.unl.edu" <srikanth@unlserve.unl.edu> writes:

> How can I write a regular expression to extract a number at the end of a
> string in a perl program.

/.*(d+)/


-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 28 Oct 2002 19:56:58 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: regular expression
Message-Id: <u9elaacp6d.fsf@wcl-l.bham.ac.uk>

Brian McCauley <nobull@mail.com> writes:

> "unlnews.unl.edu" <srikanth@unlserve.unl.edu> writes:
> 
> > How can I write a regular expression to extract a number at the end of a
> > string in a perl program.
> 
> /.*(d+)/

Er, no.

I meant to say

  /(\d+)$/

Of course this assumes that when you say "number" you mean "string of
digits".

It won't capture "three", or "1E+10" or "5.7".

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 29 Oct 2002 00:06:41 -0000
From: Andreas =?iso-8859-1?Q?K=E4h=E4ri?= <ak@freeshell.org.REMOVE>
Subject: Re: regular expression
Message-Id: <slrnarrk7s.hqa.ak@otaku.freeshell.org>

Submitted by "unlnews.unl.edu" to comp.lang.perl.misc:
> How can I write a regular expression to extract a number at the end of a
> string in a perl program.
> 
> Thanks
> Srikanth
> 
> 

$string ~= /(\d+)$/;
$number = $1;

-- 
(                  )
 ) Andreas Kähäri (
(                  )


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

Date: Mon, 28 Oct 2002 15:48:26 -0700
From: Daniel Berger <djberge@qwest.com>
Subject: Re: significance of 42 for perl, any?!?
Message-Id: <3DBDBEBA.741A879D@qwest.com>

Bob Dover wrote:

> "Michele Dondi" wrote...
> > Is there any particular significance of 42 for perl or is it just my impression?
>
> Its the answer to the question about Life, the Universe, and Everything.  We
> don't know what the question is, but when we do, its answer will be 42.

I thought the question was, 'What is 8x7?'

:)

Dan



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

Date: Mon, 28 Oct 2002 17:36:40 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Sub: how to access the internet programatically across(via) an ISA firewall
Message-Id: <3DBDBBF8.49B473A3@earthlink.net>

R.Padmakumar wrote:
[snip]
> I am trying to write a program that uses the following APIs for
> accessing the internet and download a page..
[snip]
> I am in extreme need to obtain a good optimum solution for this.. if
> possible by using WinInet API. Please let me know your suggestion.

Use the module Win32::Internet.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Mon, 28 Oct 2002 19:31:35 GMT
From: "reggie" <reggie_nospam@reggieband.com>
Subject: Re: Value in array with loop
Message-Id: <rggv9.633806$f05.26193557@news1.calgary.shaw.ca>

"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnarqjcr.2k8.tadmc@magna.augustmail.com...
> reggie <reggie_nospam@reggieband.com> wrote:
>
> > I need to find whether a value exists inside an array.
>
> But your code below does not try to find whether a value
> exists inside an array.

My second post did not make it to the group.  What I've shown in the
original post is result of reading the FAQ you've mentioned below.  The
original code should have been posted minutes after the original post.

> > Please, before you refer me to an FAQ consider the whole problem.
>
>
> I figure this is the FAQ you're talking about:
>
>    "How can I tell whether a list or array contains a certain element?

Yeah - that FAQ was the one which indicated how to turn an array into a hash
and then check to see if a certain key existed.  In fact, almost all FAQ's
on the matter suggested that the data should most likely be in a hash from
the begining.  Hence, this cat's pants of a post.

> > I am getting the contents of a url then regexp for urls.
>                                           ^^^^^^^^^^^^^^^
>
> There are modules that will do that for you already, as
> mentioned in the answer to this FAQ:

Yeah - my URL extraction is primative.  I have a list of things to do, and
that would be next.  The regexp I have works on my data set just fine, but I
will definately need to get a better one for the future.

> > my $base = 'http://www.server.com'; # base site
>
> Note no slash at the end.
>
> Is this your real code?

No sir.  A mistype when I removed the real server address.  Base should
indeed contain a trailing slash.

> > Any ideas on an eloquent solution?
>
> If you are working on nothing more than a "learning exercise",
> then continue rolling your own.

That is exactly what I'm doing (a learning exercise).  Well, what I am doing
is trying to get the contents of a dynamicly generated site to try and store
a static copy.  Eventually I'll rewrite all local links, try and ignore
external links, etc.  I've been using PHP heavily the last few months and
wanted to get back onto the Perl wagon with something I knew would be a
little more challenging.

> Use an array as a queue of "links to follow" an a hash that
> records "links already followed". Something like (untested):
>
>    while ( my $page = shift @todo ) {
>       # fetch the web page...
>       foreach my $link ( something_that_finds_links($content) ) {
>          push @todo, $link unless $seen{$link}++;
>       }
>    }

What I was actually using was:

 # add uris (unless already there)
 for (@new_uris) {

  undef %seen;
  for (@uris) { $seen{$_} = 1; }

  push @uris, $_ unless $seen{$_};
 }

See - my original beef with this method was that as the list gets big, I am
constantly redefining my hash.  It worked, but I knew there would be a
pretty way.  Your solution:
push @todo, $link unless $seen{$link}++;
this will add new urls to the array and hash if they don't exist.

I've tested and verified this as my solution.  However, it is still
frustrating that I need 2 data structures to do the job of one.

Now ... I need a semi-reliable way to determine what is a local url ....

regards,
reggie.

p.s. feel free to critique my code for style -- as I said this is an attempt
to move from beginner Perl guy to intermediate Perl guy.

#!/usr/bin/perl -w

use strict;
use LWP::Simple;       # for get url

my $base = "http://www.someserver.com/"; # base site
my @new_uris;          # newly found urls
my $content;           # body of HTTP result
my @uris;              # array of uris to search
my %uris;              # hash of unique uris

# add index as first page to search
push @uris, 'index.php';

for (@uris) {

 $content = get ($base . $_);    # get is from LWP::Simple

 @new_uris = ($content =~ /<a href=['"](.*?)['"]/g);

 # add uris (unless already there)
 for (@new_uris) {
  push @uris, $_ unless $uris{$_}++;
 }
}

for (@uris) {
 print "$_\n";
}




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

Date: 28 Oct 2002 22:59:38 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: Value in array with loop
Message-Id: <1035845978.911214@elaine.furryape.com>

In article <dh6v9.618963$Ag2.23820374@news2.calgary.shaw.ca>,
reggie <reggie_nospam@reggieband.com> wrote:
>Problem is, if I do it with a hash, it only loops through values existant in
>the hash when the for loop is entered.

That's correct behaviour. 

What you should probably do is to place a loop around your foreach, and 
exit the outer loop once you have processed each page.

This means you want to have two states for your %urls, one value says
you've identified it as a page which needs to be handled, and another
which says it's a page which has been processed. Your exit state is
to have no pages left which need to be handled.

You should also look at HTML::Parser. Regex's can't reliably
parse HTML.


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

Date: Mon, 28 Oct 2002 13:35:02 -0800
From: Erik Knepfler <minsc_tdp@hotmail.com>
Subject: Re: Win32: Hiding console window
Message-Id: <3dbdad86$0$19474$4c41069e@reader1.ash.ops.us.uu.net>

I've seen window-hiding utilities before.  Sure you could find one 
easily in a search.  They're quite fun, useful for getting command-line 
stuff out of the tray so it doesn't distract you from your work, and 
would work fine for this.

Erik



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

Date: Mon, 28 Oct 2002 14:07:41 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Richard Lawrence <ralawrence@my-deja.com>
Subject: Re: Working out if string A is related to string B
Message-Id: <Pine.A41.3.96.1021028135441.53206A-100000@vcmr-104.server.rpi.edu>

[posted & mailed]

On 28 Oct 2002, Richard Lawrence wrote:

>I have two string, A and B, and want to figure out how "similar" they
>are to each other. I've looked in CPAN and can't find anything so I
>figured that I'd roll my own. Here is one suggestion I have:

So you're basing it on whether they have (big) words in common.

  sub how_similar {
    my ($str_a, $str_b) = @_;
    my (%in_a, @in_both, $score);

    @in_a{ grep length > 3, split /\W+/, $str_a } = ();
    @in_both = grep length > 3 && exists $in_a{$_}, split /\W+/, $str_b;
    $score += length for @in_both;
    return ($score, \@in_both);
  }

Used like so:

  my ($score, $words_ref) = how_similar($x, $y);

$words_ref is an array reference to the words making up the sum in $score.

-- 
Jeff "japhy" Pinyan      RPI Acacia Brother #734      2002 Acacia Senior Dean
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



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

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


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