I need store each element in the first column where are the privileges in keys and value in the file, i did this but I do not understand.
it’s content in my file “file-privilege”
-rw-rw-r--. file-privilege
-rw-rw-r--. file-selinux
-rwxrwxrwx. funcion-split-join.pl
-rwxrwxr-x. hash2.pl
-rw-rw-r--. hash3.pl
-rwxrwxr-x. hash.pl
-rwxrwxr-x. inthashfile.pl
-rw-rw-r--. ls
-rwx------. probando.pl
the code in perl.
%pr_file = ();
open(WHO, "file-privilege");
while (<WHO>) {
($privilege, $file) = split ;
push( @{$pr_file{$privilege}}, $file );
}
this output.
-rwx------. = ARRAY(0x83bb7f0)
-rw-rw-r--. = ARRAY(0x83a06f8)
-rwxrwxr-x. = ARRAY(0x83bb780)
-rwxrwxrwx. = ARRAY(0x83bb750)
I need:
key = value
-rw-rw-r--. = file-privilege
etc…
any idea?
The same key maps to multiple values. You need to dereference the array reference just like when you add a value; or use a scalar which only remembers the last (or first, or a random) value.
Anyway, the code you have shown us is correct; the problem is in the code which prints out the values, which you have not provided. But something like this:
By the by, you should probably use Perl’s built-in
stat()function rather than try to parselsoutput.