Visit Our UNIX and Linux User Community


Array manipulation in perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Array manipulation in perl
# 1  
Old 06-21-2009
Array manipulation in perl

hi all,

i am trying to append the output of a find command (for different paths)in an array as below...

my $res_array;
$i=0;
$dir="/orn/ops/regs";
foreach $block("am","xb"){

$bdir="$dir/$block";

$res_array[$i]=`find $bdir ! -user mainuser -printf \"\%u \%h\\n\"`;

$i++;

}


i tried this but it is not saving anything in the array.i want the result of find command to be saved in the array for both "am" and "xb".

i also tried to push one array into the master array, but its also not appending but overwriting.

need help here,,
thanks in advance
# 2  
Old 06-21-2009
Quote:
Originally Posted by saapa
...
$res_array[$i]=`find $bdir ! -user mainuser -printf \"\%u \%h\\n\"`;
...
Code:
$res_array[$i]=`find $bdir ! -user mainuser -printf "%u %h\n"`;

tyler_durden
# 3  
Old 06-21-2009
your not defining your array as an array.

Code:
my $res_array;

you need to define it something like

Code:
my @res_array =  ();

# 4  
Old 06-21-2009
this aside, try to use Perl's own File::Find module.
# 5  
Old 06-21-2009
Quote:
Originally Posted by BubbaJoe
your not defining your array as an array.

Code:
my $res_array;

you need to define it something like

Code:
my @res_array =  ();

Unless they are using strict that will not matter. Perl will create the array @res_array automatically. Of course they should be using strict. Smilie
# 6  
Old 06-22-2009
By mistake i wrote in this thread $res_array, in the script i had declared it as
@res_array only. but then also its not working....

is there any other way to do this..
# 7  
Old 06-22-2009
Does the "find" command return anything when run at the prompt, without the escape characters, for the values of $bdir as set in the loop ?

tyler_durden

Previous Thread | Next Thread
Test Your Knowledge in Computers #837
Difficulty: Medium
SOAP was designed as an object-addressing protocol in 1998,
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Array manipulation with awk?

Dear friends, I'm wondering if we could do some simple math on two arrays with the same size? a1 Fe -0.21886700 -0.01417600 -0.24390300 C 2.20529400 0.89434100 -0.61061000 C -1.89657700 -0.74793000 -0.07778200 C ... (8 Replies)
Discussion started by: liuzhencc
8 Replies

2. Shell Programming and Scripting

Bash array manipulation

seeking assistance on comparing two arrays using bash: array1=(disk1, disk2, disk3, disk5, disk7, vol1, vol2, vol3, vol4, vol5) array2=(disk2, disk5 vol2, vol4 ) 1) if two arrays have same elements; EXIT else populate array3 & array4 with elements that are different between array1 & array2 as:... (3 Replies)
Discussion started by: solaix14
3 Replies

3. Shell Programming and Scripting

PERL : Read an array and write to another array with intial string pattern checks

I have an array and two variables as below, I need to check if $datevar is present in $filename. If so, i need to replace $filename with the values in the array. I need the output inside an ARRAY How can this be done. Any help will be appreciated. Thanks in advance. (2 Replies)
Discussion started by: irudayaraj
2 Replies

4. Shell Programming and Scripting

Array in Perl - Detect several file to be in one array

Hi everyone I have one question about using array in perl. let say I have several log file in one folder.. example test1.log test2.log test3.log and the list goes on.. how to make an array for this file? It suppose to detect log file in the current directory and all the log file will... (3 Replies)
Discussion started by: sayachop
3 Replies

5. Shell Programming and Scripting

perl, put one array into many array when field is equal to sth

Hi Everyone, #!/usr/bin/perl use strict; use warnings; my @test=("a;b;qqq;c;d","a;b;ggg;c;d","a;b;qqq;c;d"); would like to split the @test array into two array: @test1=(("a;b;qqq;c;d","a;b;qqq;c;d"); and @test2=("a;b;ggg;c;d"); means search for 3rd filed. Thanks find the... (0 Replies)
Discussion started by: jimmy_y
0 Replies

6. Shell Programming and Scripting

Perl Text Manipulation

I'm in need of help for a project that I'm working on. I believe Perl would be the best way of handling the string manipulation, however, I've barely used perl, and I'm used to BASH scripting. Another note is, this project is in a Windows environment, so I can use Perl, but I do not have shell... (1 Reply)
Discussion started by: drewrockshard
1 Replies

7. Shell Programming and Scripting

Perl Text manipulation

Hello All, I have been working on a great script to remotely gather server info and store it in a .txt that can be imported to .xls I have been reading the hostnames that are in the /.shh/known_hosts file so I don't have to mess with passing a password - via ssh (not easy to do , by the... (1 Reply)
Discussion started by: dfezz1
1 Replies

8. Shell Programming and Scripting

Perl, string manipulation

Hi all, Supposing the following string: XXXXXXXXXXNEAXXXXXX How can I check if this string has the substring NEA? Best regards Chris (3 Replies)
Discussion started by: chriss_58
3 Replies

9. Shell Programming and Scripting

perl script file manipulation

Please let me know.. How to manipulate the data from two files..? I have two files, file1 has two columns one is variable and second is description. file2 has five columns first column is variable and last one is description..Appreciate the help I need to overwrite the description from file1... (5 Replies)
Discussion started by: ddk2oo5
5 Replies

10. Shell Programming and Scripting

Data manipulation in perl

Hello guys.. I have the following question. lets have that i have the following variable: $field=werfiurd383nd93bc93 c93 d93 d9e3 ddd or array=werfiurd383nd93bc93 c93 d93 d9e3 ddd what i would like to do is to store the first 4 characters of gthe aboce variable in variable... (1 Reply)
Discussion started by: chriss_58
1 Replies

Featured Tech Videos