Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

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]
[jedikaiti]: 'ello Monks

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (14)
As of 2017-06-27 15:11 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (609 votes). Check out past polls.