Code that makes you say hmmm!

J

John W. Krahn

I downloaded a Perl program recently and encountered this line:


if(exists $_[0]->{"name"} and scalar($_[0]->{"name"}) eq $_[0]->{"name"}){




Comments? Jokes?


John
 
A

A. Sinan Unur

I downloaded a Perl program recently and encountered this line:


if(exists $_[0]->{"name"} and scalar($_[0]->{"name"}) eq
$_[0]->{"name"}){

Sartre must be communicating with the rest of us through the life-form who
put together those lines.

I am speechless.

Sinan
 
A

attn.steven.kuo

John said:
I downloaded a Perl program recently and encountered this line:


if(exists $_[0]->{"name"} and scalar($_[0]->{"name"}) eq $_[0]->{"name"}){




Comments? Jokes?


It's obvious that you're checking for overloaded
operators:

package Foo;
use overload
'""' => sub { shift },
eq => sub { 0 };

package main;

use strict;
use warnings;
my $foo = { name => [ 'Chunky' ] };
my $bar = { name => [ 'Bacon' ] };
bless $foo->{name}, 'Foo';

say_wha($foo);
say_wha($bar);

sub say_wha
{
if(
exists $_[0]->{"name"}
and
scalar($_[0]->{"name"}) eq $_[0]->{"name"})
{
print "Hmmm ... $_[0]->{name}[0]\n";
}
}

# ;)
 
M

Matt Garrish

John W. Krahn said:
I downloaded a Perl program recently and encountered this line:


if(exists $_[0]->{"name"} and scalar($_[0]->{"name"}) eq
$_[0]->{"name"}){


Comments? Jokes?

You're forgetting your Monty Python. Anyone can get past the "what is your
name" question. It's the favourite colour that'll get you in the end... : )

Matt
 
A

A. Sinan Unur

I downloaded a Perl program recently and encountered this line:


if(exists $_[0]->{"name"} and scalar($_[0]->{"name"}) eq
$_[0]->{"name"}){

Maybe we need a

alt.perl-maintainer.recovery

newsgroup.

Sinan
 
I

Ilya Zakharevich

[A complimentary Cc of this posting was sent to
John W. Krahn
I downloaded a Perl program recently and encountered this line:
if(exists $_[0]->{"name"} and scalar($_[0]->{"name"}) eq $_[0]->{"name"}){

The intent is quite clear. This snippet of code will warn the user
when some dark force assigns undef to $_[0]->{"name"}.

Hope this helps,
Ilya
 
R

Rick Scott

(A. Sinan Unur said:
John W. Krahn said:
I downloaded a Perl program recently and encountered this line:

if(exists $_[0]->{"name"} and scalar($_[0]->{"name"}) eq
$_[0]->{"name"}){

Maybe we need a

alt.perl-maintainer.recovery

newsgroup.

Sign me up. I get to interface with plenty of code that looks as
though it may predate Perl4. No strictures, no warnings, and every
package you import dumps a couple of dozen variable and function names
into main whether you like it or not. I really got a kick out of
seeing this in one of the libraries:

$SocAF_INET = 2;
$SocSTREAM = 1;
...

...and then reading in the Camel book:

# One problem with ancient socket code in Perl was that people
# would use hard-coded values for constants passed into socket
# functions, which destroys portability. ... If you ever see code
# that does anything like explicitly setting $AF_INET = 2, you
# know you're in for big trouble.




Rick
 
R

robic0

I downloaded a Perl program recently and encountered this line:


if(exists $_[0]->{"name"} and scalar($_[0]->{"name"}) eq $_[0]->{"name"}){




Comments? Jokes?


John

I'm not suprised this post got 5 replies by the regulars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top