in reply to Re^2: Nested Data Structures, OOP
in thread Nested Data Structures, OOP
Firstly, "isn't working" is a totally inadequate error report: you need to post the error messages you are getting. If you're not getting any error messages, add use strict; and use warnings; near the start of your code. If you don't understand the messages, also add use diagnostics; for more verbose messages.
Here's the basic syntax for pushing onto a simple and a complex array:
# simple array push @simple_array, $array_element; my $simple_arrayref = \@simple_array; push @{ $simple_arrayref }, $array_element; # complex array push @{ $complex_arrayref }, $array_element;
You'll note the absence of any ->[] in the above code.
You have another problem in your push line above. Compare how you've written $self{"Course(s)"} here with how you've written it everywhere else.
I hope that's enough for you to resolve the problem yourself. If not, post your error messages and describe what parts you're having difficulty with.
Finally, there's all sorts of problems with your example push:
$self->{"Course(s)"}=[<STDIN>]
- It's an assignment, not a push.
- You'd probably need [scalar <STDIN>] instead of [<STDIN>]
- Your data will contain all the newlines that the user entered.
Something like the following skeleton code would be better:
while (<>) { chomp; push @array, $_; }
-- Ken
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Nested Data Structures, OOP
by programmer.perl (Beadle) on Jul 23, 2012 at 14:18 UTC | |
by kcott (Archbishop) on Jul 24, 2012 at 00:07 UTC | |
Re^4: Nested Data Structures, OOP
by programmer.perl (Beadle) on Jul 24, 2012 at 14:30 UTC |