CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [rushadrena] A file parsing and 2D array/matrix problem.: Edit Log



Laurent_R
Veteran / Moderator

Aug 28, 2012, 4:40 AM


Views: 7360
Re: [rushadrena] A file parsing and 2D array/matrix problem.

Hi,

to access the individual elements:

Code
 use strict;   
use warnings;

my $matrix = "matrix.txt";
open my $fh, "<", $matrix or die "unable to open $matrix $! \n";
chomp( my @lines = <DATA> );
foreach my $line (@lines) {
my @fields = split / /, $line;
print "$_\n" foreach @fields;
}


With your data:


Code
1 2 3 4  
1 5 6 8
1 7 8 0


this prints:


Code
 perl matrix.pl  
1
2
3
4
1
5
6
8
1
7
8
0



(This post was edited by Laurent_R on Aug 28, 2012, 4:41 AM)


Edit Log:
Post edited by Laurent_R (Veteran) on Aug 28, 2012, 4:41 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives