Arrays in perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Arrays in perl
# 8  
Old 09-01-2011
@corona688

The main purposeof my script is i have a screen shot all the directory permission recursively from last month....

one admin screqwd the whole prod by giving chmod 775 * on the root dir with root ID... now everything got changed i am trying to find the changes... need to report to my maanger so that we can restore back using these changes...


While splitting the log into the array i was using

@array = split ' ',$_;

i can use join to combine the file name so that i can have the whole file name in one var.

But there are some places where they are more than 1 space in the file name and they are chopped off and could find when i am trying to find the same file currently ....

is there any other way to get the string into the array with out lossing the space..
# 9  
Old 09-01-2011
Why not split on newlines instead of spaces?
# 10  
Old 09-01-2011
Quote:
Originally Posted by firestar
...But there are some places where they are more than 1 space in the file name and they are chopped off and could find when i am trying to find the same file currently ....
is there any other way to get the string into the array with out lossing the space..
Code:
$
$
$ cat logfile
-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
$
$ perl -lne '@x = m/^(.*? [a-zA-Z]{3} \d\d \d{4} )([ 0-9-]*)(.*?)$/; print "FILE = \"$x[2]\""' logfile
FILE = "d_labs.sas7bdat"
FILE = "Fortamet MHRA 19534-0005-6 REQUESTS OF .pdf"
FILE = "Fortamet MHRA 19534-0005-6CMC Response"
$
$

tyler_durden
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