Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > V 5.8 specific problem?

Reply
Thread Tools

V 5.8 specific problem?

 
 
Marty Landman
Guest
Posts: n/a
 
      02-03-2004
I'm running the same software on three different servers. All 3 are
FBSD running Perl v5.005_03. Recently I ported to a RH9 Linux server
which runs Perl v5.8.0. One part of the software is causing the
following in my Apache error log:

"Attempt to bless into a reference at..."

the referenced line contains

my $quiz = bless { _q => $_q, _a => $_a },$Quiz;

I've compared the copy on this machine and one of the 3 where it
works. Also if I just comment out the call that caused this package to
be used everything works just fine.

While it may obviously be something just not thought of by me (imagine
that) given the difference in Perl versions I'm wondering if this is a
feature or bug of the 5.8 release. Since the Linux box belongs to me
and is a sandbox I could just rpm -e Perl 5.8 and install 5.0x from a
cpan distro. But then again maybe it's something I need to pay better
attention to.

Any help, ideas etc.. most appreciated.

Thanks in advance,


Marty Landman Face 2 Interface Inc 845-679-9387
This Month's New Quiz --- Past Superbowl Winners
Make a Website: http://face2interface.com/Home/Demo.shtml
 
Reply With Quote
 
 
 
 
Eric Schwartz
Guest
Posts: n/a
 
      02-03-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (Marty Landman) writes:
> I'm running the same software on three different servers. All 3 are
> FBSD running Perl v5.005_03.


This is truly ancient (nearly 5 years old), and has all sorts of nasty
bugs (security-related and otherwise). It's a good thing you're
upgrading.

> Recently I ported to a RH9 Linux server which runs Perl v5.8.0. One
> part of the software is causing the following in my Apache error
> log:
>
> "Attempt to bless into a reference at..."
>
> the referenced line contains
>
> my $quiz = bless { _q => $_q, _a => $_a },$Quiz;


Check the documentation on Perl diagnostics with 'perldoc perldiag'
and read the entry your message refers to. If you don't understand
something about that answer, please let us know what it is, and we'll
try to help.

$Quiz (as a personal aside, I hate it when a line of code includes two
variables named identically except for case) is probably not what you
think it is. You probably should print it out and see what you're
trying to bless that anon hashref into.

-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
 
Reply With Quote
 
 
 
 
Marty Landman
Guest
Posts: n/a
 
      02-04-2004
Eric Schwartz <(E-Mail Removed)> wrote:

> Check the documentation on Perl diagnostics with 'perldoc perldiag'
> and read the entry your message refers to.


Got it. You can see I'm new to OOPing and apparently owing to the Perl
versions was able to get away with an incorrect way of doing things.

I have been blessing into either the package string, or if the package
had already been instantiated with a hash ref would use that. But by
just changing the line of code to bless into the package name the hash
ref is automagically associated. Guess that's part of the point,
right?

> $Quiz (as a personal aside, I hate it when a line of code includes two
> variables named identically except for case) is probably not what you
> think it is.


No, I knew exactly what it was and hope I explained clearly above.
Just that I didn't realize this was the wrong way to do this.

TMTOWTDI aside, I wonder how bad my variable naming style is. Although
what I do privately is obviously my own business, I don't want to
develop habits that are unfriendly to others, y'know?

To me it makes more sense to have e.g.

my ($quiz, @quiz, %quiz)

than to have

my ($quiz_sca, @quiz_ary, %quiz_hsh);

Well ok, not more sense but just easier for me to read the code.


Marty Landman Face 2 Interface Inc 845-679-9387
This Month's New Quiz --- Past Superbowl Winners
Make a Website: http://face2interface.com/Home/Demo.shtml
 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      02-04-2004

(E-Mail Removed) (Marty Landman) wrote:
> Eric Schwartz <(E-Mail Removed)> wrote:
>
> > Check the documentation on Perl diagnostics with 'perldoc perldiag'
> > and read the entry your message refers to.

>
> Got it. You can see I'm new to OOPing and apparently owing to the Perl
> versions was able to get away with an incorrect way of doing things.
>
> I have been blessing into either the package string, or if the package
> had already been instantiated with a hash ref would use that. But by
> just changing the line of code to bless into the package name the hash
> ref is automagically associated. Guess that's part of the point,
> right?


I'm not sure I follow you here... blessing an object associates it
with a package. ref $obj will return that package. So if $obj has been
blessed into package Package, the code

my $newobj = bless {...}, ref $obj;

will also bless $newobj into package Package. There is no association
between $obj and $newobj beyond the fact they are both blessed into
the same package.

> > $Quiz (as a personal aside, I hate it when a line of code includes two
> > variables named identically except for case) is probably not what you
> > think it is.

>
> TMTOWTDI aside, I wonder how bad my variable naming style is. Although
> what I do privately is obviously my own business, I don't want to
> develop habits that are unfriendly to others, y'know?
>
> To me it makes more sense to have e.g.
>
> my ($quiz, @quiz, %quiz)


My 2d:

Temporary variables should be in a small enough scope that essentialy
it doesn't matter what they're called, as you can see all uses of the
variable at once; thus they should have short, concise names. I do
sometimes use $foo and @foo; though there are often better names, like
@quizzes and $curquiz.

Globals (in which class I include lexicals whose scope covers more
than one sub, as well as package globals) should be meaningfully
named, and clearly rather than concisely. They are as much a part of
the interface to a given section of code as its sub names are. I tend
to name globals with an initial cap, just to distinguish them.

The only time I would use two variables with the same name in
different cases is where I have a scalar naming a file and a FH open
on that file, e.g.

my $config = $ENV{MY_CONFIG} || "$ENV{HOME}/.myconfig";
open my $CONFIG, '<', $config or die 'horribly';

Ben

--
$.=1;*g=sub{print@_};sub r($$\$){my($w,$x,$y)=@_;for(keys%$x){/main/&&next;*p=$
$x{$_};/(\w)::$/&&(r($w.$1,$x.$_,$y),next);$y eq\$p&&&g("$w$_")}};sub t{for(@_)
{$f&&($_||&g(" "));$f=1;r"","::",$_;$_&&&g(chr(0012))}};t # (E-Mail Removed)
$J::u::t, $a::n:::t::h::e::r, $P::e::r::l, $h::a::c::k::e::r, $.
 
Reply With Quote
 
Eric Schwartz
Guest
Posts: n/a
 
      02-04-2004
(E-Mail Removed) (Marty Landman) writes:
> Eric Schwartz <(E-Mail Removed)> wrote:
> To me it makes more sense to have e.g.
>
> my ($quiz, @quiz, %quiz)
>
> than to have
>
> my ($quiz_sca, @quiz_ary, %quiz_hsh);
>
> Well ok, not more sense but just easier for me to read the code.


I'm not suggesting Hungarian notation, heaven forfend (though I've
been known to suffix scalar refs with _ref to remind myself that it's
not a real scalar), but just that you pick maybe more useful variable
names.

For instance, you have a data structure that is a quiz. Well, it's
unlikely to be a scalar, but could be an array or hash, depending on
how you build it. So instead of $quiz, pick something more useful,
like $question or $entry or some such. And you shouldn't need @quiz
and %quiz both. I have no idea how you structure your code, but
here's how I might dynamically build a quiz:

my %quiz = (title => "Countries in Europe",
creator => "Eric",
entries => []);

my @questions =( { q => "Is France in Europe?", a => "yes" },
{ q => "Is China in Europe?", a => "no" } );

foreach my $question (@questions) {
push @{$quiz{entries}}, $question
}

Of course, there are good reasons to use $foo and %foo and @foo in the
same program, and I'm not saying you should always avoid it. But I
find programs are easier to maintain if I don't do that very much.
Mostly I do things like above, where I have the aggregate @questions,
and alias $question to each member of it.

-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XML parsing problem finding a specific element in a specific place mazdotnet ASP .Net 2 10-02-2009 10:07 AM
Parsing DOM to search specific tags with specific custom attribute William FERRERES Javascript 7 07-09-2007 08:11 PM
Is ViwState Page-Specific or UserControl-Specific =?Utf-8?B?SmF2?= ASP .Net 2 08-16-2006 09:30 PM
redirect traffic on specific ip to specific interface mimiseh Cisco 3 06-05-2005 09:14 PM
How do you make sure a frameset is loaded? I'm trying to open a frameset in a new window which shows a specific html page in a specific frame ck388 Javascript 1 09-24-2003 08:32 PM



Advertisments