in reply to (Ovid) Re: Unable to put default value in object hash
in thread Unable to put default value in object hash

After some modifications, the code now looks like this:
package Games::QuizTaker; use strict; use Data::Dumper; use Carp; sub new{ my($class,%args)=@_; bless{ _FileName => $args{FileName}||croak"No FileName given", _Delimiter => $args{Delimiter}|| "|", _FileLength => "0", },$class; } sub Print_Object{ my $self=shift; print Dumper($self); } 1;
And my testing program is as follows:
#!/opt/perl5/bin/perl -w use strict; use Games::QuizTaker; my $Q=Quiz->new("FileName"=>"File"); $Q->Print_Object();
However, when I do run the above script, the Print_Object shows only the _FileName parameter within the object. I am trying to get the _Delimiter parameter to be set to a pipe character if the Delimiter isn't passed in.

TStanley
--------
There's an infinite number of monkeys outside who want to talk to us
about this script for Hamlet they've worked out
-- Douglas Adams/Hitchhiker's Guide to the Galaxy

Replies are listed 'Best First'.
(Ovid) Re(3): Unable to put default value in object hash
by Ovid (Cardinal) on Nov 15, 2001 at 04:33 UTC

    Your code works fine for me if I make the following change:

    #my $Q=Quiz->new("FileName"=>"File"); my $Q=Games::QuizTaker->new("FileName"=>"File");

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.