Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Overwritten instance variables

by tokpela (Chaplain)
on Aug 03, 2009 at 09:14 UTC ( #785400=note: print w/replies, xml ) Need Help??

in reply to Overwritten instance variables

I tried to run your code and it didn't work.

Try using strict and you will see that you are not instantiating $self correctly.

Try something like this:

use strict; use warnings; my $query = new MyPackage::Query("utf8"); my $query2 = new MyPackage::Query("euc-jp"); print "QUERY: [$query->{input_enc}]\n"; print "QUERY2: [$query2->{input_enc}]\n"; print "Done\n"; package MyPackage::Query; sub new { my $class = shift; my $self = {}; bless($self, $class); $self->{input_enc} = shift; unless (defined $self->{input_enc}) { $self->{input_enc} = "euc-jp"; } #... return $self; }

This returns the correct result on my system:

F:\>perl QUERY: [utf8] QUERY2: [euc-jp] Done

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://785400]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2017-04-30 04:49 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (534 votes). Check out past polls.