Building 2 key hash with output from unix command

Discussion in 'Perl Misc' started by mac8500, May 3, 2006.

  1. mac8500

    mac8500 Guest

    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?
     
    mac8500, May 3, 2006
    #1
    1. Advertising

  2. 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.
     
    Brian McCauley, May 3, 2006
    #2
    1. Advertising

  3. mac8500

    Brad Baxter Guest

    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::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;

    --
    Brad
     
    Brad Baxter, May 3, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    1,729
    Terry Hancock
    Apr 23, 2005
  2. M P
    Replies:
    1
    Views:
    502
  3. rp
    Replies:
    1
    Views:
    556
    red floyd
    Nov 10, 2011
  4. Une bévue
    Replies:
    5
    Views:
    156
    Une bévue
    Aug 10, 2006
  5. Antonio Quinonez
    Replies:
    2
    Views:
    180
    Antonio Quinonez
    Aug 14, 2003
Loading...

Share This Page