V 5.8 specific problem?

Discussion in 'Perl Misc' started by Marty Landman, Feb 3, 2004.

  1. 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
    Marty Landman, Feb 3, 2004
    #1
    1. Advertising

  2. (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.
    Eric Schwartz, Feb 3, 2004
    #2
    1. Advertising

  3. Eric Schwartz <> 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
    Marty Landman, Feb 4, 2004
    #3
  4. Marty Landman

    Ben Morrow Guest

    (Marty Landman) wrote:
    > Eric Schwartz <> 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 #
    $J::u::s::t, $a::n::eek:::t::h::e::r, $P::e::r::l, $h::a::c::k::e::r, $.
    Ben Morrow, Feb 4, 2004
    #4
  5. (Marty Landman) writes:
    > Eric Schwartz <> 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.
    Eric Schwartz, Feb 4, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leslie McGann
    Replies:
    0
    Views:
    2,073
    Leslie McGann
    Jul 3, 2003
  2. Hrvoje Vrbanc
    Replies:
    0
    Views:
    334
    Hrvoje Vrbanc
    Feb 25, 2004
  3. =?Utf-8?B?SmF2?=

    Is ViwState Page-Specific or UserControl-Specific

    =?Utf-8?B?SmF2?=, Aug 16, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    520
    =?Utf-8?B?SmF2?=
    Aug 16, 2006
  4. mazdotnet
    Replies:
    2
    Views:
    387
    Alexey Smirnov
    Oct 2, 2009
  5. William FERRERES
    Replies:
    7
    Views:
    202
    William FERRERES
    Jul 9, 2007
Loading...

Share This Page