looks like you are accessing your array (argument to new()) at the second 
element ($_[1])
instead of first ($_[0]).

On Friday, March 29, 2002, at 07:33  AM, Paul Tremblay wrote:

> On Wed, Mar 27, 2002 at 09:05:02PM -0800, bob ackerman wrote:
>
>> i copied the code as is, and got no error.
>> are you sure  line #29 is where you are calling $_incr_count->()?
>> are you sure the code you are executing is what you posted?
>>
>
> No apparently this is not the code that gives me the error
> message!
>
> Below is the code that gives me the same error message.
>
> #!/usr/bin/perl -w
>
> my $cd = CD::Music->new(              "Canon in D", "Pachelbel",
>                                               "Boering Mussak GmbH", 
>"1729-67836847-1",
>                                               1,
>                                               8,8,
>                                               5.0);
>
>
>
>
>
> # How many CDs in the entire collection?
> print "The number of CDs is ",CD::Music->get_count, "\n";
>
> package CD::Music;
> use strict;
>
> {
>       my $_count = 0;
>       sub get_count           {$_count}
>       my $_incr_count = sub {++$_count};#create an anonymous subroutine
>
>       
>
>       sub new{
>               $_incr_count->();#call anonymous subroutine
>
> #############################################
> # Instead I could put this code?:
> # my $_incr_count = sub {++$_count};
> #$_incr_count->();
> ###############################################
>
>       $_incr_count->();       #call the anonymous subroutine
>                                       #Gives me an error message shown below
>
>               my ($class) = @_;
>               bless {
>                       _name   =>      $_[1],  #second value passed to subroutine
>                       _artist =>      $_[2],  #third value passed to subroutine
>                       _publisher =>   $_[3],  #and so on
>                       _ISBN   =>      $_[4],
>                       _tracks =>      $_[5],
>                       _room   =>      $_[6],
>                       _shelf  =>      $_[7],
>                       _rating =>      $_[8],
>                       }, $class;
>       }
> }
>
>
> ########################################################
> #ERROR MESSAGE WITH 'use strict' COMMENTED:
> #
> #Use of uninitialized value in subroutine entry at
> #/home/paul/bin/test16.pl line 27.
> #Undefined subroutine &main:: called at /home/paul/bin/test16.pl
> #line 27.
> ########################################################
>
> ########################################################
> #ERROR MESSAGE WITH 'use strict'
> #Use of uninitialized value in subroutine entry at
> #/home/paul/bin/test16.pl line 27.
> #Can't use string ("") as a subroutine ref while "strict refs"
> #in use at /home/paul/bin/test16.pl line 27.
> ########################################################
>
>
> Again, I believe that the reference to the anonymous subroutine
> expires once I start the 'new' subroutine. If I put the anonymous
> subroutine within the 'new' subroutine block, then the script
> executes correctly, and I still make sure that you can't
> increment the value of the number of CDs directly.
>
> Thanks!
>
> Paul
>
> --
>
> ************************
> *Paul Tremblay         *
> *[EMAIL PROTECTED]*
> ************************
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to