Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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 test_object_creation.pl QUERY: [utf8] QUERY2: [euc-jp] Done

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://785400]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2016-09-29 08:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (550 votes). Check out past polls.