Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Building 2 key hash with output from unix command

Reply
Thread Tools

Building 2 key hash with output from unix command

 
 
mac8500
Guest
Posts: n/a
 
      05-03-2006
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?

 
Reply With Quote
 
 
 
 
Brian McCauley
Guest
Posts: n/a
 
      05-03-2006

mac8500 wrote:
> 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.

 
Reply With Quote
 
 
 
 
Brad Baxter
Guest
Posts: n/a
 
      05-03-2006
mac8500 wrote:
> 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:umper;

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;

--
Brad

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
Re: how to handle output generated after execution of command/scripton host unix machine? Dan Stromberg Python 0 12-23-2010 12:42 AM
Hash#select returns an array but Hash#reject returns a hash... Srijayanth Sridhar Ruby 19 07-02-2008 12:49 PM
hash key to var name of value hash key value Une bévue Ruby 5 08-10-2006 04:05 PM
Run Unix shell command $ parse command line arguments in python rkoida@yahoo.com Python 4 04-23-2005 04:42 AM



Advertisments