[32005] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3269 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 28 00:09:28 2011

Date: Thu, 27 Jan 2011 21:09:09 -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           Thu, 27 Jan 2011     Volume: 11 Number: 3269

Today's topics:
    Re: Extracting html urls on a webpage using linktext <nomail2me@suddenlink.net>
    Re: Learning Object Oriented Programming (newbie) <skye.shaw@gmail.com>
    Re: Learning Object Oriented Programming (newbie) <tzz@lifelogs.com>
    Re: Learning Object Oriented Programming (newbie) <tzz@lifelogs.com>
    Re: Learning Object Oriented Programming (newbie) <tzz@lifelogs.com>
    Re: Learning Object Oriented Programming (newbie) <Peter@PSDT.com>
    Re: Please help me understand this expression <jlconlin@gmail.com>
    Re: Please help me understand this expression <rvtol+usenet@xs4all.nl>
    Re: TIOBE language of the year <n0nb.DO.NOT.SPAM@ME.n0nb.us>
    Re: TIOBE language of the year <bugbear@trim_papermule.co.uk_trim>
    Re: TIOBE language of the year <cartercc@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 27 Jan 2011 00:00:43 -0500
From: Jim <nomail2me@suddenlink.net>
Subject: Re: Extracting html urls on a webpage using linktext
Message-Id: <7nu1k6pdianm441jbkpo9puvv0b9jbpm3a@4ax.com>

On Wed, 26 Jan 2011 12:24:29 -0800 (PST), shankar_perl_rookie
<mulshankar@gmail.com> wrote:

>Hello All,
>
>I am using win32::IEAutomation to do some data extraction. I am
>encountering a minor issue with extracting html urls on a page using
>linktext. I generally use
>
>$ie ->getLink('linktext:', $mytext) ->linkUrl();
>
>The above line of code gives me the url corresponding $mytext. But my
>problem now is there are multiple instances of the same $mytext on the
>web page. Is there a way I can extract all the different urls
>corresponding to the same linktext and store it in an array ?

An array, as you have found, is not the proper data structure to store
this repeated information.  You want to use a hash, or an associative
array (two different names for the same structure)  -- this is the
third most useful structure in Perl, after scalars and simple arrays,
and one of the most powerful and useful structures in the language.


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

Date: Wed, 26 Jan 2011 17:04:43 -0800 (PST)
From: "Skye Shaw!@#$" <skye.shaw@gmail.com>
Subject: Re: Learning Object Oriented Programming (newbie)
Message-Id: <bc74d7f6-9c80-4c18-82d0-6b6f4487bc63@d1g2000pra.googlegroups.com>

On Jan 26, 6:14=A0am, Ted Zlatanov <t...@lifelogs.com> wrote:
> On Tue, 25 Jan 2011 09:57:50 -0800 (PST) "Skye Shaw!@#$" <skye.s...@gmail=
 .com> wrote:
>
> >> On Mon, 24 Jan 2011 12:29:54 -0500 "Uri Guttman" <u...@StemSystems.com=
> wrote:
>
> >> >>>>>> "SS" =3D=3D Skye Shaw!@#$ <skye.s...@gmail.com> writes:
>
> SS> On Jan 24, 12:02 am, "Skye Shaw!@#$" <skye.s...@gmail.com> wrote:
>
> >> >>> On Jan 23, 10:45 pm, "Uri Guttman" <u...@StemSystems.com> wrote:
>
> >> >>> > have you tested that? really tested it? it will not do what you =
think it
> >> >>> > does. classic abuse of ?:.
>
> >> >>> What do I think it does?
>
> SS> Well, aside from my typo: =A0@_ ? $self->{farm} =3D shift : $self->{f=
arm};
> SS> how is it abuse?
>
> UG> well, it doesn't WORK. try it. really try it out. and it is abuse for
> UG> that reason.
>
>
>
> >> This line is near the top of my list for misguided
> >> almost-getting-it-but-not-quite use of Perl. =A0It's a mess of techniq=
ues
> >> that may have made sense separately[1] but joined they create an unhol=
y
> >> union that will burn in my retinas for a while.
>
> SS> Please elaborate.
>
> I gave the right way (if I understand correctly) to do what you're
> trying to do. =A0

I suggested that it would be more Perl-ish to rewrite:

sub get_farm {
  my $learn_oop =3D shift;
  return $learn_oop->{farm};

}

sub set_port {
  my $learn_oop =3D shift;
  my $port =3D shift;
  $learn_oop->{port} =3D $port;

}

As:

sub farm {
  my $self =3D shift;
  @_ ? $self->{farm} =3D shift : $self->{farm};
}

> You're mixing the ternary operator and assignments.=A0You should not
> assign *inside* a ternary operator (unless you want to confuse people),

Out of all the things one can pull off in Perl *that's* near the *top*
of your "...list for misguided
almost-getting-it-but-not-quite use of Perl."





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

Date: Thu, 27 Jan 2011 09:52:52 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Learning Object Oriented Programming (newbie)
Message-Id: <87r5bywdgr.fsf@lifelogs.com>

On Wed, 26 Jan 2011 15:42:47 GMT Peter Scott <Peter@PSDT.com> wrote: 

PS> On Wed, 26 Jan 2011 08:14:25 -0600, Ted Zlatanov wrote:
>> So you can just say
>> 
>> $self->{farm} = shift if @_;

PS> Stylistic concerns aside, the original poster's statement returns the 
PS> value of the attribute if no argument is passed to the method, a common 
PS> mixed getter/setter pattern.  You'd need to add a return statement and 
PS> repeat the hash key anyway to get that behavior.

Yeah, I wasn't trying to fix all the code, just the part that hurt my
eyes :) 

I'd suggest Moose in general for this kind of drudgery, unless
performance was a concern.  Writing your own setters and getters is kind
of a pain to do *right*, and quite a few book chapters have been devoted
to it, with varying degrees of success.  Once you add validation,
optional and compound parameters, initializers, and so on, it's quickly
obvious that you're reinventing Moose.

Ted


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

Date: Thu, 27 Jan 2011 09:55:19 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Learning Object Oriented Programming (newbie)
Message-Id: <87mxmmwdco.fsf@lifelogs.com>

On Wed, 26 Jan 2011 16:38:31 +0000 RedGrittyBrick <RedGrittyBrick@spamweary.invalid> wrote: 

R> "If no return is found and if the last statement is an expression, its
R> value is returned. "

R> Perldoc perlsub

Unless you're writing Lisp, I'd avoid that idiom.  It's usually better
in imperative languages like Perl to return explicitly.  It will work,
but you run the risk that a) you'll add another statement afterwards
accidentally, and b) a maintainer 10 years later will miss it.  I've
seen both happen :)

Ted


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

Date: Thu, 27 Jan 2011 10:44:35 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Learning Object Oriented Programming (newbie)
Message-Id: <877hdqwb2k.fsf@lifelogs.com>

On Wed, 26 Jan 2011 17:04:43 -0800 (PST) "Skye Shaw!@#$" <skye.shaw@gmail.com> wrote: 

SS> On Jan 26, 6:14 am, Ted Zlatanov <t...@lifelogs.com> wrote:

>> You're mixing the ternary operator and assignments. You should not
>> assign *inside* a ternary operator (unless you want to confuse people),

SS> Out of all the things one can pull off in Perl *that's* near the *top*
SS> of your "...list for misguided
SS> almost-getting-it-but-not-quite use of Perl."

I thought it was clear I was using hyperbole and humor (hence "otherwise
it was OK"), but just in case: no, this is not that close to the top.

I should have added a "return" statement as others mentioned; sorry
about that.

Ted


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

Date: Fri, 28 Jan 2011 04:27:20 GMT
From: Peter Scott <Peter@PSDT.com>
Subject: Re: Learning Object Oriented Programming (newbie)
Message-Id: <IAr0p.20669$TZ4.6528@newsfe20.iad>

On Thu, 27 Jan 2011 09:52:52 -0600, Ted Zlatanov wrote:
> On Wed, 26 Jan 2011 15:42:47 GMT Peter Scott <Peter@PSDT.com> wrote:
> 
> PS> On Wed, 26 Jan 2011 08:14:25 -0600, Ted Zlatanov wrote:
>>> So you can just say
>>> 
>>> $self->{farm} = shift if @_;
> 
> PS> Stylistic concerns aside, the original poster's statement returns
> the PS> value of the attribute if no argument is passed to the method, a
> common PS> mixed getter/setter pattern.  You'd need to add a return
> statement and PS> repeat the hash key anyway to get that behavior.
> 
> Yeah, I wasn't trying to fix all the code, just the part that hurt my
> eyes :)
> 
> I'd suggest Moose in general for this kind of drudgery, unless
> performance was a concern.  Writing your own setters and getters is kind
> of a pain to do *right*, and quite a few book chapters have been devoted
> to it, with varying degrees of success.  Once you add validation,
> optional and compound parameters, initializers, and so on, it's quickly
> obvious that you're reinventing Moose.

Well yes.  But in fairness, there *is* a narrow window of acceptability 
for writing this code, if you've been expanding a procedural script to 
the point where there's more than a couple of parameters being passed 
around to multiple places and you realize that a very small object would 
make it easier to maintain and you don't yet have Moose installed.

-- 
Peter Scott
http://www.perlmedic.com/     http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/


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

Date: Wed, 26 Jan 2011 13:43:10 -0800 (PST)
From: Jeremy <jlconlin@gmail.com>
Subject: Re: Please help me understand this expression
Message-Id: <0ccc282d-0a40-4473-a04a-b14b1abd17be@glegroupsg2000goo.googlegroups.com>

On Wednesday, January 26, 2011 1:11:32 PM UTC-7, Dr.Ruud wrote:

>=20
> Comment out any other line, and put "echo " (without the quotes) in=20
> front of the line, run the script and if you then still have doubts,=20
> report here what was echoed.


The original script attempts to convert from one database type to another. =
 The relevant lines are below.  The file menu.db is copied below the bash s=
cript lines.

Thanks,
Jeremy

#-----------------
    cat menu.db |=20
  perl -pe '
  if (/^(INSERT.+?)\(/) {
     $a=3D$1;
     s/\\'\''/'\'\''/g;
     s/\\n/\n/g;
     s/\),\(/\);\n$a\(/g;
  }
'
# --------------



# menu.db
/*!40101 SET @saved_cs_client     =3D @@character_set_client */;
/*!40101 SET character_set_client =3D utf8 */;
CREATE TABLE "fish" (
  "ID" int(11) NOT NULL AUTO_INCREMENT,
  "NAME" varchar(30) NOT NULL DEFAULT '',
  "PRICE" decimal(5,2) NOT NULL DEFAULT '0.00',
  PRIMARY KEY ("ID")
);
/*!40101 SET character_set_client =3D @saved_cs_client */;
INSERT INTO "fish" VALUES (1,'catfish','8.50'),(2,'catf ish','8.50'),(3,'tu=
na','8.00'),(4,'catfish','5.00'),(5,'bass','6.75'),(6,'haddock','6.50'),(7,=
'salmon','9.50'),(8,'trout','6.00'),(9,'tuna','7.50'),(10,'yellowfin tuna',=
'12.00'),(11,'yellowfin tuna','13.00'),(12,'tuna','7.50');



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

Date: Thu, 27 Jan 2011 12:44:15 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: Please help me understand this expression
Message-Id: <4d415a8f$0$81473$e4fe514c@news.xs4all.nl>

On 2011-01-26 22:43, Jeremy wrote:
> On Wednesday, January 26, 2011 1:11:32 PM UTC-7, Dr.Ruud wrote:

>> Comment out any other line, and put "echo " (without the quotes) in
>> front of the line, run the script and if you then still have doubts,
>> report here what was echoed.
>
> The original script attempts to convert from one database type to another.  The relevant lines are below.  The file menu.db is copied below the bash script lines.

That was a stupid reply, so now you have to find somebody else to parse 
your echo output.

-- 
Ruud


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

Date: Thu, 27 Jan 2011 02:39:32 +0000 (UTC)
From: Nate Bargmann <n0nb.DO.NOT.SPAM@ME.n0nb.us>
Subject: Re: TIOBE language of the year
Message-Id: <ihqlt4$cu5$1@speranza.aioe.org>

Like you I find that Perl fits my personality and way of thinking.  I 
also get along well with C and some Bash shell.  I've spent time self-
studying Python in the past but have never managed to get my head around 
the almost required full dive into OOP that using a lot of the third 
party packages requires.  I have no formal training in programming and I 
am strictly a self-taught hobbyist--I do it for fun and my own 
edification not for profit.

I find Perl's regular expressions an integrated part of the language.  My 
impression of RE in Python is that it's something they needed to add to 
play in the same space as Perl and somehow seems to be an extra.  Also, I 
have found old Perl 5 scripts that run perfectly well on later Perl 5 
versions.  This is as it should be, IMO.  I recently tried to get a 
Python module working on a Linux distribution that has standardized on 
Python 3 and the script failed.  That was almost to be expected as the 
script was shown as being tested on Python 2.4 and 2.5.  As it turned out 
the distribution had Python 2.7 installed as its Python 2 version and the 
module threw an exception for some reason that I couldn't spend a lot of 
time trying to figure it out so I gave up and ran the script on another 
box where the module was packaged with the packaged Python interpreter.  

It just seems to me that in a major version series that backward 
compatibility should be a given.  A script written for Python 2.0  should 
not be broken by Python 2.7 even with its features and bug fixes.  
Jumping to 3.0 is another story, of course.  So that has become my 
biggest gripe about Python--the need to continually update a script for 
point releases.  I kept wanting to like Python and it kept getting snaky 
on me.  ;-)

The fact is that different programming languages exist to solve different 
problems.  Also, they appeal to different mindsets and problem solving 
approaches.  I enjoy the freedom to use what suits me best.  Long live 
Perl.

- Nate >>

-- 

"The optimist proclaims that we live in the best of all possible worlds,
the pessimist fears this is true."


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

Date: Thu, 27 Jan 2011 10:02:41 +0000
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: TIOBE language of the year
Message-Id: <vsSdnVbRs5xf39zQnZ2dnUVZ8iSdnZ2d@brightview.co.uk>

ccc31807 wrote:
> TIOBE has awarded its 'language of the year' designation to Python.

http://blog.timbunce.org/2008/04/12/tiobe-or-not-tiobe-lies-damned-lies-and-statistics/

whatever.

   BugBear


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

Date: Thu, 27 Jan 2011 06:48:06 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: TIOBE language of the year
Message-Id: <5e7b75d1-9fc9-4ac2-a161-7f54fe1c536d@f18g2000yqd.googlegroups.com>

On Jan 27, 5:02=A0am, bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
> whatever.

If you google 'programming language popularity' you get about 2.4M
hits. If you look at the first ten hits, you get about the same kind
of thing, with roughly the same ranking. TIOBE is the most recognized,
but that's probably due to more to longevity than anything else.

What does 'programming language popularity' mean? Is the fact that one
language is more widely used than another mean that it's 'better' in
some sense? Many more people use Basic and PHP than use Erlang, yet
Erickson has used Erlang for years to do things that Basic and PHP
couldn't even dream about.

Last year, Go was the TIOBE LOTY. Python has been the TIOBE LOTY
multiple times. Perl has never been the TUOBE LOTY, but Perl has made
the top ten TIOBE list much longer and consistently than Python or Go.

Another thing. Using dice.com, 'perl' returns 4576 results, 'python'
returns 2209 results, and 'ruby' returns 1231 results. Obviously, this
is a gross measure (in both senses of 'gross' when you look at the
actual job postings), but it /IS/ a measure. Does this mean that Perl
is twice as 'better' than Python or four times 'better' than Ruby?

One last point. IMO, vi (vim) is the most powerful and most effective
editor in use today, but in my Windows shop, people have either never
heard of vi or if they have consider it as they would some loathsome
disease. Perl is old, fat, and ugly, but it cooks your meals, cleans
your house, does your laundry, and loves you more for it. As they say,
beauty is only skin deep, but ugly goes all the way through. Maybe the
'popularity' of Python is a strike against it.

(This isn't a slam against Python, which probably deserves its
popularity -- I agree with you that we shouldn't read too much in to
the TIOBE LOTY prize, but IMO it's profitable to discuss.)

CC.


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

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:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 V11 Issue 3269
***************************************


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