Sort an array and more

From: krzys-iek (krzys-iek_at_-----wp.pl)
Date: 05/15/04

  • Next message: Alex Lee: "represent a perl script in binary"
    Date: Sat, 15 May 2004 19:46:42 +0200
    
    

    Hi

    I try to rewrite my AWK/BASH script (you can see it here:
    www.krionix.net/perl/ - aw file)
    This script reads passwd file (included there too) and displays only those
    people we want.
    They are placed in a nice, neat table.

    You can run this script like that: ./aw 1000 1
    And 1000 is a group ID, we will see only people with GID=1000.
    1 is a sorting rule (sort by login name, 2 sort by name, 3 sort by surname).

    So we will see sorted (by login) people with GID 1000.

    OK, now I would like to rewrite this script and use *only PERL language* no
    bash etc.

    I have written something like this:

    ------------------------------------------

    #!/usr/bin/perl -w

    $file = 'passwd';
    open(INFO, $file);

    while (<INFO>)
    {
    chomp;
    (m/^([a-zA-Z0-9_]*):x:[0-9]+:$ARGV[0]:/) && (push @ludzie_z_1000, $_);
    }

    # @ludzie_z_1000 = sort @ludzie_z_1000;

    foreach (@ludzie_z_1000)
    {
    m/^([a-zA-Z0-9_]*):x:[0-9]+:$ARGV[0]:([^:,]*).*/;
    print "$1 | ";
    $_=$2;
    m/^([^ ]*) (.*)/;
    print "$1 | $2\n";
    }

    ----------------------------------------

    You can run it like that: ./script 1000

    This perl script works but I got stuck...

    I do not how to sort it with sort function ( I must sort it by login or name
    or surname!).

    Can you help me how to do that? I can not use linux sort function (as in my
    ./aw script... damn)

    @ludzie_z_1000 = sort @ludzie_z_1000; this solves only sorting by login but
    what about name and surname?:/

    Next question, How can I do something like that:

    printf "| %3s %2s %10s %2s %11s %2s %15s %2s \n", ile+1, "|", $1, "|", $2,
    "|", $3, "|"; ile+=1;}

    with perl language? You know, now my table does not look nice...

    rafit | Rafal | Tomczak
    serwik | S | Serwik
    sq6elt | Pawel | Jarosz
    tyciu | Mateusz | Tykierko

    This is a neat table/array I want :)

    rafit | Rafal | Tomczak
    serwik | S | Serwik
    sq6elt | Pawel | Jarosz
    tyciu | Mateusz | Tykierko

    Thank you!


  • Next message: Alex Lee: "represent a perl script in binary"

    Relevant Pages

    • Sort an array + more
      ... This script reads passwd file and displays only those ... now I would like to rewrite this script and use only PERL language no ... I can not use linux sort function (as in my ...
      (comp.lang.perl.misc)
    • Re: problems with standard rand functions
      ... Timothy Goddard wrote: ... > # Start Script ... numbers were stuck in before perfroming a sort function, ...
      (comp.lang.ruby)
    • Re: Block CodeRed/Nimda with script and IPCHAINS?
      ... >I have a script that loads and runs each time my site is accessed. ... >i find a match i want to have the script just drop the connection. ... the rewrite engine's "rewritemap" function. ... but rejected it for one reason: ...
      (comp.os.linux.security)
    • misc.fishfingers.yum
      ... A page-one rewrite of my second feature length drama for television. ... Shut the fuck up: ... hurdle of getting the script invitations. ... town, with credible loglines. ...
      (misc.writing)
    • Re: Asp.net 2.0 and Dreamweaver
      ... however, changes between 2.0 and 1.1, so you may have to rewrite some ... with errors because some of the coding techniques i used were now ... with code-behind, but it may apply to inline files as well, I have not ... I think the part where it talks about the inserting of script ...
      (microsoft.public.dotnet.framework.aspnet)