Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: reading input into a number of arrays

by BillKSmith (Monsignor)
on Feb 26, 2020 at 22:46 UTC ( [id://11113463]=note: print w/replies, xml ) Need Help??


in reply to reading input into a number of arrays

Strictly speaking, Perl does not support multidimensional arrays. There are at least two ways that they can be simulated. tobyink has demonstrated the hash method documented in perldata. The other is documented in the "Arrays of Arrays" section of perldsc. The first has the advantage that the source code looks more the way we expect. The other, works the way we come to expect Perl to work. Here is a solution to your problem using slices (only available in the second method ref perldata).
use strict; use warnings; my $infile = \do{my $chars = "1111111\n2222222\n3333333\n"}; open my $FH, '<', $infile or die "Cannot open input"; my @a; for my $i (1..3) { my $ingang = <$FH>; chomp $ingang; $a[$i] = [undef, split //, $ingang]; } for my $p (1..3) { print @{$a[$p]}[1..7], "\n"; }
OUTPUT: 1111111 2222222 3333333
Bill

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-03-28 21:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found