Arrays in perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Arrays in perl
# 1  
Old 08-31-2011
Arrays in perl

Hi all,

I have a log file which has logs. I am reading logs line by line into perl arrays. I want to print all the arrays elements starting from 8(word) to end of the line.

print array[8]......array[end of log] to a new file. and I have to do it in perl as res of the program in perl.

Please help me on this.
# 2  
Old 08-31-2011
What do you have so far?
# 3  
Old 09-01-2011
@corona688

here is the log file


-rwxrwxr-x 1 synchadm glbiom 14884864 May 31 2007 d_labs.sas7bdat
-rw-r--r-- 1 xli glprg 223729 Apr 21 2009 10-17-03 Fortamet MHRA 19534-0005-6 REQUESTS OF .pdf
drwxr-xr-x 2 xli glprg 1024 Apr 21 2009 7-21-04 Fortamet MHRA 19534-0005-6CMC Response


I am trying to collect the all the attributes into arrays in perl and print it in diff format ....
The catch here is the file and directory names contain numbers, spaces, special chars also Smilie..
# 4  
Old 09-01-2011
If you have all the lines in @array:
Code:
print @array[7..$#array];

This User Gave Thanks to bartus11 For This Post:
# 5  
Old 09-01-2011
@bartus11

Thanks you.

It worked.. i can print but all i want is to assign it to a variable which helps me to do more processing...

I couldn't assign that value to a variable...
# 6  
Old 09-01-2011
Quote:
Originally Posted by firestar
It worked.. i can print but all i want is to assign it to a variable which helps me to do more processing...
Isn't it a variable already?

If you mean all as one giant text blob, perhaps you could do something like this:

Code:
$var=join('', @array[7..$#array]);

# 7  
Old 09-01-2011
If you have these lines in an @array, then you already have them as variables too, albeit with ugly syntax.
$array[0] is the first
$array[1] is the second
...
$array[$#array] is the last, where $#array is the total number of elements.

Are you trying to only grab the file names out of these lines?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl: compare two arrays

Hi friends, I want to compare two arrays and find matched one using perl? Also, I want to delete unmatched one. Plz suggest me solution (1 Reply)
Discussion started by: Renesh
1 Replies

2. Shell Programming and Scripting

Perl Compare 2 Arrays

Hello, Consider the following 2 arrays: Array1 = qw(Fa0/0 Fa0/1 Fa0/2 Fa0/3); Array1 = qw(Fa0/1 Fa0/2 Fa0/3 Fa0/4); I want to compare the following 2 arrays as follows: Take specific action when elements of Array1 that doesn't exist in Array2 (in my example: Fa0/0). Take another... (4 Replies)
Discussion started by: ahmed_zaher
4 Replies

3. Shell Programming and Scripting

Difference between 2 arrays in perl

Hi, I have 2 arrays: @a=qw(19190289 18381856 12780546 10626296 9337410 8850557 7740161 8101063); @b=qw(18309897 17612870 10626296 16871843 7740161 19947571 18062861); $len=@a; print "<br> length of array1: $len<br>"; $len1=@b; print "<br> length of array2: $len1<br>"; The output... (3 Replies)
Discussion started by: vanitham
3 Replies

4. Shell Programming and Scripting

compare 2 arrays in perl

Hi Im supposed to compare lines in a file : KB0005 1019 T IFVATVPVI 0.691 PKC YES KB0005 1036 T YFLQTSQQL 0.785 PKC YES KB0005 1037 S FLQTSQQLK 0.585 DNAPK YES KB0005 1045 S KQLESEGRS 0.669 PKC YES KB0005 1045 S KQLESEGRS 0.880 unsp YES KB204320 1019 T IFVATVPVI 0.699 PKC YES ... (7 Replies)
Discussion started by: karla
7 Replies

5. Shell Programming and Scripting

Perl hash containing arrays

Hi, I am not that good at Perl. But here's what I wanna do. I want to create a hash where the keys would point to different arrays. This is what I have tried to do but in vain :( @arr=(1,2,3); @arr1=(3,2,1); %hashOfLists=(); $hashOfLists{Key1}=@arr."\n"; $hashOfLists{Key2}=@arr1."\n";... (3 Replies)
Discussion started by: King Nothing
3 Replies

6. Shell Programming and Scripting

Comparing arrays in perl

Hi all, I am trying to compare two arrays in perl using the following code. foreach $item (@arrayA){ push(@arrayC, $item) unless grep(/$item/, @arrayB); ... (1 Reply)
Discussion started by: chriss_58
1 Replies

7. Shell Programming and Scripting

perl arrays

Hi I need some help using arrays in perl. I have an array say var and a variable var1. I want to check if the var1 is present in the array. How do I check that ? my @var = 1...10; my $var1 =5; if ( $var1 in @var ) { ....... } else { ....... } Something like above. Can some... (2 Replies)
Discussion started by: ammu
2 Replies

8. Shell Programming and Scripting

Perl array of arrays

Hi, I am trying to assign an array as a value to one of the array element, I mean I have an array @KS and array @kr. I want array @KS to hold @kr as an element. So I am doin this $KS=@kr; But the value stored is number of elements in the @kr array. Can... (2 Replies)
Discussion started by: eamani_sun
2 Replies

9. Shell Programming and Scripting

Perl - Compare 2 Arrays

Hi all, I have the following script where the contents of file1 and file2 would be something like this: file1: 56790,0,0,100998765 89756,0,0,100567876 867645,1,3,678777654 file2: 56790,0,0,100998765 65776,0,0,4766457890 +5896,0,0,675489876 What I then want to do is check if... (4 Replies)
Discussion started by: Donkey25
4 Replies

10. Programming

perl arrays

hello ppl, i'm coding a perl script and i have the following situation: @array1 = ("test1", "test2", "test3"); @array2 = ("something1", "something2", "something1"); $var1 = "with_one_of_the_array1_values"; $var2 = "with_one_of_the_array2_values"; what i want to do is to compare $var1... (2 Replies)
Discussion started by: crashnburn
2 Replies
Login or Register to Ask a Question