Building 2 key hash with output from unix command

M

mac8500

Tought that would work .. but doesn't look like it.

my $_ = `$path/find /usr/local/ -print -ls | $path/awk '{print
$5,$6,$11}' | $path/grep "[a-zA-Z]"`;

foreach $_ (sort keys %find) {
( $uid, $gid, $file, ) = split();
$find{ $uid }{ $gid } = $file;
}

What i'm i doing wrong here?
 
B

Brian McCauley

mac8500 said:
Tought that would work .. but doesn't look like it.

What would work?
my $_ = `$path/find /usr/local/ -print -ls | $path/awk '{print
$5,$6,$11}' | $path/grep "[a-zA-Z]"`;

You cannot make $_ lexical.

Why are you using find and awk when you've got Perl?
foreach $_ (sort keys %find) {

Where did %find come from.
What i'm i doing wrong here?

I suspect you are posting under the influence of mind altering
(destroying) sustances.
 
B

Brad Baxter

mac8500 said:
Tought that would work .. but doesn't look like it.

my $_ = `$path/find /usr/local/ -print -ls | $path/awk '{print
$5,$6,$11}' | $path/grep "[a-zA-Z]"`;

Backticks perform double-quote interpolation, so you need
to escape those dollar signs (\$).
foreach $_ (sort keys %find) {

%find has no keys yet.
( $uid, $gid, $file, ) = split();

use strict;
$find{ $uid }{ $gid } = $file;
}

You're overwriting the value of previous file there.
What i'm i doing wrong here?

Perhaps:

use warnings;
use strict;
use Data::Dumper;

my %find;
my $path = '/usr/bin';
foreach( `$path/find /usr/local/ -print -ls
| $path/awk '{print \$5,\$6,\$11}'
| $path/grep "[a-zA-Z]"` ) {
my ( $uid, $gid, $file, ) = split();
push @{$find{ $uid }{ $gid }}, $file;
}

print Dumper \%find;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,184
Messages
2,570,978
Members
47,561
Latest member
gjsign

Latest Threads

Top