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.

What do you have so far?

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 :wall:..

If you have all the lines in @array:

print @array[7..$#array];
1 Like

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...

Isn't it a variable already?

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

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

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?

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..

Why not split on newlines instead of spaces?

$
$
$ 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