![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| perl -write values in a file to @array in perl | meghana | Shell Programming and Scripting | 27 | 06-07-2009 06:05 PM |
| how to get last value in an array in perl | meghana | Shell Programming and Scripting | 7 | 02-04-2008 05:12 PM |
| grep in array -perl | zedex | Shell Programming and Scripting | 1 | 12-06-2007 03:49 AM |
| multidimensional arrays | leslie02 | Shell Programming and Scripting | 2 | 07-13-2007 12:39 PM |
| join 2 array in perl? | gusla | Shell Programming and Scripting | 2 | 09-03-2004 10:59 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
multidimensional array in perl
i'm trying to open a file with three or more columns and an undetermined, but finite number of rows. I want to define an array for each row with each element of the row as a sub array. The columns are separated by tabs or spaces. Here's the file: 12x3.12z34b.342sd3.sds 454.23.23.232 aSDGgsOds 4z3x3.134b.332sSSsd3.Ccsds 354.23.2113.232 aSDffGgds 12x333.123ww4b.342sed3.sdsO 22454.23.23.20032 BSDGgds ... i'm trying it like this: Code:
#!/usr/bin/perl -w
use warnings;
use strict;
open (FILE, xyz.txt) or die " $!";
our @lines<FILE>;
chomp @lines;
close (FILE);
for (@lines) {
$/="\t|' '"; # field sperator is either tab or ' '
our @lines=([split / /, $_]);
}
print "First element \'$lines[0][0]\'\n";
print "Second element \'$lines[0][1]\'\n";
print "Third element \'$lines[0][2]\'\n";
print "First element \'$lines[1][0]\'\n";
...
or somehow make a hash reference to each element of the row Code:
...
print "First element \'$lines{0}->{first]\'\n";
print "Second element \'$lines{0}->{second}\'\n";
print "Third element \'$lines{0}->third}\'\n";
print "First element \'$lines{1}->{first}\'\n";
...
any ideas? thanks Last edited by prkfriryce; 11-27-2007 at 05:53 PM.. |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|