Kris Gaethofs wrote: > Hi, > > I could use some help with the following problem: > > I have this input file that looks like this (after some processing): > > %1%MO%1s%.0000%-.0003%.0000%.0003%.0002%.0006%-.0005%.0020%-.0035%.0006 > %2%MO%1s%-.0001%-.0021%-.0003%.0018%.0015%.0042%-.0034%.0136%-.0234%.0042 > %3%MO%1s%-.0005%-.0085%-.0010%.0071%.0060%.0161%-.0139%.0556%-.0953%.0166 > %4%MO%1s%-.0020%-.0341%-.0037%.0280%.0249%.0435%-.0658%.2286%-.3871%.0593 > %5%MO%1s%.0182%-.0592%.1039%-.0179%.0960%-.0550%-.4774%.7751%-1.2943%.0993 > %6%MO%1s%-.0027%-.0202%.0121%.0205%.0281%-.0688%-.0198%.3710%-.4371%.0543 > %7%MO%1s%-.0004%-.0059%.0042%.0057%.0090%-.0206%-.0058%.1229%-.1377%.0221 > %8%MO%1s%.0001%-.0010%.0008%.0010%.0017%-.0055%-.0006%.0260%-.0273%.0057 > %9%MO%2px%.0000%-.0001%.0000%.0000%-.0001%-.0003%.0001%-.0004%-.0002%.0005 > > I need to read this input into a multidimensional array. Since there are no real >multidimensional arrays in perl I need to use references. The way I thought it would >work was like this: > > my @input; > my $i = 0; > while(<INFILE>){ > $input[$i] = \split(/%/,$_);
perldoc -f split perldoc -q 'What is the difference between a list and an array?' split returns a list and a reference of a list will give you the reference of the last element of the list. (due to the comma operator) my $ref = \('a', 'b', 'c', 'd', 'e'); print "$$ref\n"; Will print 'e'. What you need is a reference to an array, this should work while (<INFILE>) { chomp; push (@input, [split (/%/)]); } The '[' and ']' around split will create an anonymous array and push it's reference into the @input array. > > $i = $i+1; > } > > But it doesn't work. The references in $input[$i] all point to a scalar value (the >last one of each input line actually). > > Does anyone know how I should do it? > > Greets, > > Kris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]