Sponsored Content
Top Forums Shell Programming and Scripting Reference two dimensional array in Perl sub Post 35516 by WIntellect on Wednesday 16th of April 2003 04:52:57 AM
Old 04-16-2003
Quote:
snip of sample code
FOR I := 1 TO DIM DO
weights[1][I] := I;
END
If you want to keep your Perl code similar to the original, I believe you can do things like the above, in this way:
Quote:
foreach $I (1..DIM) {
# process $I here
}
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help for record (2 dimensional array.)

I am going to develop a address book using the shell scripting commands without sed, awk, .... I am thinking to apply the concept of 2 dimenstional array. Can I create a two dimensional array for the insertion/updation/deletion of record in unix. If yes then tell me plz or recommend me some... (1 Reply)
Discussion started by: murtaza
1 Replies

2. Shell Programming and Scripting

2 dimensional array in unix

I am trying to implementing two dimensinal array in ksh script.Would you pls help me out. I have a large size of file, File contains looks like ID SID VLAUE1 VALUE2 TOTALVALUE 1 a1 01 02 03 1 b1 02 05 07 ... (2 Replies)
Discussion started by: pritish.sas
2 Replies

3. Shell Programming and Scripting

PHP: Search Multi-Dimensional(nested) array and export values of currenly worked on array.

Hi All, I'm writing a nagios check that will see if our ldap servers are in sync... I got the status data into a nested array, I would like to search key of each array and if "OK" is NOT present, echo other key=>values in the current array to a variable so...eg...let take the single array... (1 Reply)
Discussion started by: zeekblack
1 Replies

4. Shell Programming and Scripting

sorting multi dimensional array

Hi there, Can someone let me know how to sort the 2 dimensional array below by column 1 then by column 2? 22 55 2222 2230 33 66 44 58 222 240 11 25 22 60 33 45 output: 11 25 22 55 22 60 33 45 33 66 44 58 (6 Replies)
Discussion started by: phoeberunner
6 Replies

5. Programming

Return two dimensional array in c++

I am writing matrix multiplication and trying to return a two dimensional array from a function but I keep getting errors. Can someone please help me? here is my code (it is just the skeleton of my program): void main () { ... int *matmultiply (int, int, int, int , int , int ) ... } ... (4 Replies)
Discussion started by: saboture88
4 Replies

6. Shell Programming and Scripting

Manipulating a list into a two-dimensional array

hi, total newbie to shell scripting and wondering if some of you guru's can give me a hand on a problem I'm trying to solve. The tmplsnr.a file contains LSNR_51526 db1 db2 LSNR_51527 db3 db4 db5 Summary - depending on which db is set, the script will start the relevant listener... (5 Replies)
Discussion started by: mingy10
5 Replies

7. Shell Programming and Scripting

Store in a 2 dimensional array - Perl

Hey guyz. Here is my sample input file following by first part of my code: * A B C D E reg1 1 0 1 1 0 reg2 0 1 0 0 1 reg3 1 0 0 1 0 reg4 0 0 1 0 1 reg5 1 1 0 0 1 use strict; use warnings; open (IN, "test_input.txt") or die ("Can't open file.txt: $!\n"); my $line = <IN>; ... (2 Replies)
Discussion started by: @man
2 Replies

8. Shell Programming and Scripting

How to reference 2 dimensional array in awk?

Hello, all For a 1-dimensional array, such as myarr_1=1 myarr_1=2 myarr_1=3I know I can write a loop as below to show the array member one by one: for (i in myarr_1){print i, myarr_1}Now, suppose I have a two dimensional array such as: myarray_2=1 myarray_2=2 myarray_2=10 myarray_2=20My... (3 Replies)
Discussion started by: littlewenwen
3 Replies

9. Shell Programming and Scripting

Multi Dimensional array

I have an array of names. Each one of the name, has a number represented to it. For example A has an ID 8, B has an ID 2. What I am after is a for loop that when the array is in position 1, a particular variable is set to the value of position 1 in array 2 declare -a arr=("A" "B" "C"... (6 Replies)
Discussion started by: nms
6 Replies

10. Shell Programming and Scripting

Assign Two Dimensional Array In Bash At Once

Hi, I have a 10*10 two dimensional array. How do I assign value to all it's 100 elements at once? I don't want to open two for loops and assign one by one. Thanks, Shuri (1 Reply)
Discussion started by: shurimano
1 Replies
Flow(3pm)						User Contributed Perl Documentation						 Flow(3pm)

NAME
Data::Flow - Perl extension for simple-minded recipe-controlled build of data. SYNOPSIS
use Data::Flow; $recipes = { path => { default => './MANIFEST'}, contents => { prerequisites => ['path', 'x'] , process => sub { my $data = shift; $data->{ shift() } = `cat $data->{'path'}` x $data->{'x'}; } }, }; $request = new Data::Flow $recipes; $request->set( x => 1); print $request->get('contents'); tie %request, Data::Flow, $recipes; $request{x} = 1; print $request{contents}; DESCRIPTION
The module Data::Flow provides its services via objects. The objects may be obtained by the usual $request = new Data::Flow $recipes; paradigm. The argument $recipes is a hash reference, which provides the rules for request processing. The objects support three methods, set(), get(), aget(), and already_set(). The first one is used to provide input data for processing, the second one to obtain the output. The third one to obtain a reference to an array with results of repeated get(), and the last one to query whether a field is already known. The unit of requested information is a field. The method set() takes a pair "field => value", the methods get() and already_set() take one argument: the "field", and the method aget() takes multiple fields. Every object is created without any fields filled, but it knows how to construct fields basing on other fields or some global into. This knowledge is provided in the argument $recipe of the new() function. This is a reference to a hash, keyed by fields. The values of this hash are hash references themselves, which describe how to acquire the field which is the corresponding key of the initial hash. The internal hashes may have the following keys: "default" describes the default value for the key, if none is provided by set(). The value becomes the value of the field of the object. No additional processing is performed. Example: default => $Config{installdir} "prerequisites" gives the fields which are needed for the construction of the given field. The corresponding value is an array references. The array contains the required fields. If "defaults" did not satisfy the request for a field, but "$recipe->{field}{prerequisites}" exists, the required fields are build before any further processing is done. Example: prerequisites => [ qw(prefix arch) ] "process" contains the rule to build the field. The value is a reference to a subroutine taking 2 arguments: the reference to a hash with all the fields which have been set, and the name of the required field. It is up to the subroutine to actually fill the corresponding field of the hash, an error condition is raised if it did not. Example: process => sub { my $data = shift; $data->{time} = localtime(time) } } "oo_process" contains the rule to build the field. The value is a reference to a subroutine taking 2 arguments: the object $request, and the name of the required field. It is up to the subroutine to actually fill the corresponding field of $request, an error condition is raised if it did not. Example: oo_process => sub { my $data = shift; $data->set( time => localtime(time) ) } "output" the corresponing value has the same meaning as for "process", but the return value of the subroutine is used as the value of the field. Example: output => sub { localtime(time) } "oo_output" the corresponing value has the same meaning as for "process", but the return value of the method is used as the value of the field. Example: output => sub { my $self = shift; $self->get('r') . localtime(time) } "filter" contains the rule to build the field basing on other fields. The value is a reference to an array. The first element of the array is a reference to a subroutine, the rest contains names of the fields. When the subroutine is called, the arguments are the values of fields of the object $request which appear in the array (in the same order). The return value of the subroutine is used as the value of the field. Example: filter => [ sub { shift + shift }, 'first_half', 'second_half' ] Note that the mentioned field will be automatically marked as prerequisites. "self_filter" is similar to "filter", but an extra argument, the object itself, is put in front of the list of arguments. Example: self_filter => [ sub { my ($self, $first_half = (shift, shift); $first_half *= -$self->get('total')*100 if $first_half < 0; # negative means percentage $first_half + shift }, 'first_half', 'second_half' ] "class_filter" is similar to "filter", but the first argument is the name of the method to call, second one is the name of the package to use for the method invocation. The rest contains names of field to provide as method arguments. Example: class_filter => [ 'new', 'FileHandle', 'filename' ] "method_filter" is similar to "class_filter", but the second argument is the name of the field which is used to call the method upon. Example: method_filter => [ 'show', 'widget_name', 'current_display' ] Tied interface The access to the same functionality is available via tied hash interface. AUTHOR
Ilya Zakharevich, cpan@ilyaz.org, with multiple additions from Terrence Monroe Brannon and Radoslav Nedyalkov. SEE ALSO
perl(1), make(1). perl v5.10.0 2008-05-11 Flow(3pm)
All times are GMT -4. The time now is 08:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy