Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Array definition error

by sasikumar (Monk)
on Apr 15, 2005 at 15:32 UTC ( [id://448224]=note: print w/replies, xml ) Need Help??


in reply to Array definition error

Hi,
If i had understood the question right. Perl has no clue in finding the datatype of ur @outputs and @inputs. Give it some clue to find it out. It would do what u were asking for.
Try this
use strict; use warnings; use Data::Dumper; my @trainset = (); while (my $pattern = <DATA>) { chomp $pattern; next if $pattern =~ /^\s*$/; next if ($pattern =~ /#/); my ($inputs,$outputs) = split(/=>/,$pattern); my @inputs = split(/,/,$inputs); my @outputs = split(/,/,$outputs); for(my $i=0;$i<@outputs;$i++) { $outputs[$i]=$outputs[$i]+1-1; } for(my $i=0;$i<@inputs;$i++) { $inputs[$i]=$inputs[$i]+1-1; } $trainset[scalar(@trainset)] = \@inputs; $trainset[scalar(@trainset)] = \@outputs; } print Dumper(\@trainset); my @set = ( [0,0] => [0], [0,1] => [1], ); print Dumper(\@set); __DATA__ 0,0=>0 0,1=>1 #not used
Thanks
SasiKumar

Replies are listed 'Best First'.
Re^2: Array definition error
by RazorbladeBidet (Friar) on Apr 15, 2005 at 15:47 UTC
    That works... or...(if this is even a necessary step)
    use strict; use warnings; use Data::Dumper; my @trainset = (); while (my $pattern = <DATA>) { chomp $pattern; next if ($pattern =~ /#/); my ($inputs,$outputs) = split(/=>/,$pattern); my @inputs = split(/,/,$inputs); my @outputs = split(/,/,$outputs); $_+0 foreach @outputs; # added $_+0 foreach @inputs; # added $trainset[scalar(@trainset)] = \@inputs; $trainset[scalar(@trainset)] = \@outputs; } print Dumper(\@trainset); my @set = ( [0,0] => [0], [0,1] => [1], ); print Dumper(\@set); __DATA__ 0,0=>0 0,1=>1 #not used
    --------------
    "But what of all those sweet words you spoke in private?"
    "Oh that's just what we call pillow talk, baby, that's all."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://448224]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-24 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found