Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
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


Comment on Re: Overwritten instance variables
Select or Download Code

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 taking refuge in the Monastery: (4)
As of 2015-07-29 07:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls