Hello [EMAIL PROTECTED]!

On 18-Set-00, you wrote:

 j> Read through the colon-delimited file below (a copy of
 j> an /etc/passwd file, mangled for security purposes),
 j> and print a report tallying the distinct values in the
 j> 7th field (in this case, the field that identifies the
 j> default shell for each userID).  Sort the results by
 j> the value of the field being tallied, and print the
 j> results in neat columns.

This uses a /DIRECT port; it's a bit different,too, just to show
another way to do it. :)

========================================================
REBOL []

foreach-line: func [
  file [file!]
  code [block!]
  /local line
] [
  ; I don't know if this REALLY uses less memory...
  file: open/read/direct/lines file
  code: func [line] code
  while [line: pick file 1] [code line]
  close file
]

shells: []

count-shell: func [shell [string! none!]] [
  change shell: any [
    find/tail shells shell
    insert tail shells shell
  ] 1 + any [shell/1 0]
]

foreach-line %passwords.txt [
  count-shell pick parse/all line ":" 7
]

foreach [shell count] sort/skip shells 2 [
  print [
    ; we really need FORMAT here!
      head insert/dup count: form count " " 3 - length? count
      any [shell "(none)"]
  ]
]
========================================================

I don't have Perl here, so please repeat the tests with this to
see if it makes any difference.

Regards,
    Gabriele.
-- 
Gabriele Santilli <[EMAIL PROTECTED]> - Amigan - REBOL programmer
Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/

Reply via email to