05-02-2004
Reading data into muti-dimentional array - in perl
Just want to learn how these are read into array but I don't seem to get it right what do I go wrong?
Below is the sample
Thanks
input
1 2 3 4
5 6 7 8
9 1 2 3
4 5 6 7
#!/usr/bin/perl
open (InFILE,"input");
while (<InFILE>) {
@ar = split ;
$arref = \@ar;
push(@multiarray,$arref);
}
for ($i=0;$i<=4;$i++){
for ($j=0;$j<=4;$j++){
print " $multiarray[$i][$j] ";
}
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I am trying to read in a 2 column data file into Perl Hash array index. Here is my code.
#!/usr/bin/perl -w
use strict;
use warnings;
my $file = "file_a";
my @line = ();
my $index = 0;
my %ind_file = ();
open(FILE, $file) or die($!);
while(<FILE>) {
chomp($_);
if ($_ eq '')
{
... (1 Reply)
Discussion started by: subhap
1 Replies
2. Shell Programming and Scripting
Hi, I am writting some perl scripts for daily backup process. In which I want to pass some data/referance from another txt file. Text file contains only one column and multiple rows. I want to pass this data to variables of another perl script.
e.g.
Refdoc.txt file contains data as:
perl1... (3 Replies)
Discussion started by: n.dba
3 Replies
3. Shell Programming and Scripting
Respected All,
Kindly help me out.
I have got file listings in a directory like this:
-rw-r--r-- 1 root root 115149 2011-11-17 07:15 file1.stat.log
-rw-r--r-- 1 root root 115149 2011-11-18 08:15 file2.stat.log
-rw-r--r-- 1 root root 115149 2011-11-19 09:15 file3.stat.log
-rw-r--r-- 1... (2 Replies)
Discussion started by: teknokid1
2 Replies
4. Shell Programming and Scripting
Hi,
i need a perl script which reads the file, content is given below. and output in new file.
TARGET DRIVE IO1 IO2 IO3 IO4 IO5
------------ --------- --------- --------- --------- ---------
0a.1.8 266 236 ... (3 Replies)
Discussion started by: asak
3 Replies
5. Shell Programming and Scripting
I wrote a simply perl that searched a file for a particualr value and if it found it, rite it and the next three lines to a file. Now I have been asked to check those next three lines for a different value and only write those lines if it finds the second value.
I was thinking the best way to... (1 Reply)
Discussion started by: billprice13
1 Replies
6. Shell Programming and Scripting
I need some help with this code below, i doesnt know why it will run twice with my function, but my function only got if else, any other way that can read line and put into array?
while read line; do
read -A array <<<$line
n=${#array}
for ((i=1;i<$n;i++)); do
print... (1 Reply)
Discussion started by: gavin_L
1 Replies
7. Shell Programming and Scripting
This basic code works.
I have a very long list, almost 10000 lines that I am building into the array. Each line has either 2 or 3 fields as shown in the code snippit. The array elements are static (for a few reasons that out of scope of this question) the list has to be "built in".
It... (5 Replies)
Discussion started by: sumguy
5 Replies
8. Shell Programming and Scripting
Hi all,
I have written a perl code and stored the data into Data structure using Data::Dumper module.
But not sure how to retreive the data from the Data::Dumper.
Eg.
Based on the key value( Here CRYPTO-6-IKMP_MODE_FAILURE I should be able to access the internal hash elements(keys) ... (1 Reply)
Discussion started by: scriptscript
1 Replies
9. Shell Programming and Scripting
Hi team,
# PERL
I have Dumper variable in perl and containing the below data and trying to fetch value and name from the reference variable.
$VAR1 = {
'retainSysIds' => 'true',
'variables' => ,
'name' => ,
... (4 Replies)
Discussion started by: giridhar276
4 Replies
10. Shell Programming and Scripting
Hello,
I am running under ubuntu1 14.04 and I have a script which is sending given process names to vanish so that I'd see less output when I run most popular tools like top etc in terminal window. In usual method it works.
Whenever I restart the system, I have to enter the same data from... (2 Replies)
Discussion started by: baris35
2 Replies
LEARN ABOUT XFREE86
rawtopgm
rawtopgm(1) General Commands Manual rawtopgm(1)
NAME
rawtopgm - convert raw grayscale bytes into a portable graymap
SYNOPSIS
rawtopgm [-bpp [1|2]] [-littleendian] [-maxval N] [-headerskip N] [-rowskip N] [-tb|-topbottom] [width height] [imagefile]
DESCRIPTION
Reads raw grayscale values as input. Produces a PGM file as output. The input file is just a sequence of pure binary numbers, either one
or two bytes each, either bigendian or littleendian, representing gray values. They may be arranged either top to bottom, left to right or
bottom to top, left to right. There may be arbitrary header information at the start of the file (to which rawtopgm pays no attention at
all other than the header's size).
Arguments to rawtopgm tell how to interpret the pixels (a function that is served by a header in a regular graphics format).
The width and height parameters tell the dimensions of the image. If you omit these parameters, rawtopgm assumes it is a quadratic image
and bases the dimensions on the size of the input stream. If this size is not a perfect square, rawtopgm fails.
When you don't specify width and height, rawtopgm reads the entire input stream into storage at once, which may take a lot of storage.
Otherwise, rawtopgm ordinarily stores only one row at a time.
If you don't specify imagefile, or specify -, the input is from Standard Input.
The PGM output is to Standard Output.
OPTIONS
-maxval N
N is the maxval for the gray values in the input, and is also the maxval of the PGM output image. The default is the maximum value
that can be represented in the number of bytes used for each sample (i.e. 255 or 65535).
-bpp [1|2]
tells the number of bytes that represent each sample in the input. If the value is 2, The most significant byte is first in the
stream.
The default is 1 byte per sample.
-littleendian
says that the bytes of each input sample are ordered with the least significant byte first. Without this option, rawtopgm assumes
MSB first. This obviously has no effect when there is only one byte per sample.
-headerskip N
rawtopgm skips over N bytes at the beginning of the stream and reads the image immediately after. The default is 0.
This is useful when the input is actually some graphics format that has a descriptive header followed by an ordinary raster, and you
don't have a program that understands the header or you want to ignore the header.
-rowskip N
If there is padding at the ends of the rows, you can skip it with this option. Note that rowskip need not be an integer. Amaz-
ingly, I once had an image with 0.376 bytes of padding per row. This turned out to be due to a file-transfer problem, but I was
still able to read the image.
Skipping a fractional byte per row means skipping one byte per multiple rows.
-bt -bottomfirst
By default, rawtopgm assumes the pixels in the input go top to bottom, left to right. If you specify -bt or -bottomfirst, rawtopgm
assumes the pixels go bottom to top, left to right. The Molecular Dynamics and Leica confocal format, for example, use the latter
arrangement.
If you don't specify -bt when you should or vice versa, the resulting image is upside down, which you can correct with pnmflip .
This option causes rawtopgm to read the entire input stream into storage at once, which may take a lot of storage. Ordinarly, raw-
topgm stores only one row at a time.
For backwards compatibility, rawtopgm also accepts -tb and -topbottom to mean exactly the same thing. The reasons these are named
backwards is that the original author thought of it as specifying that the wrong results of assuming the data is top to bottom
should be corrected by flipping the result top for bottom. Today, we think of it as simply specifying the format of the input data
so that there are no wrong results.
SEE ALSO
pgm(5), rawtoppm(1), pnmflip(1)
AUTHORS
Copyright (C) 1989 by Jef Poskanzer.
Modified June 1993 by Oliver Trepte, oliver@fysik4.kth.se
14 September 2000 rawtopgm(1)