[aklug] Re: perl lists question, sorting, sort of.

From: Arthur Corliss <acorliss@nevaeh-linux.org>
Date: Tue Aug 17 2010 - 22:33:06 AKDT

On Tue, 17 Aug 2010, Christopher Howard wrote:

> Here is a start in Ruby:
>
> #!/usr/bin/env ruby
>
> @data = {}
> File.new(ARGV[0]).each do |line|
> if line =~ /^\s*(\S+)\s*(\S+)\s*$/
> if !@data[$1]
> @data[$1] = {}
> end
> @data[$1][$2] = true
> end
> end
> @data.each do |ip, host_name_hash|
> print ip.to_s
> host_name_hash.each_key do |hostname|
> print " " + hostname.to_s
> end
> print "\n"
> end
>
> Call it like: ./hosts.rb olddatafile > newdatafile
>
> Sorry, that was the two minute job, so we only do one hostname per IP
> address in the original data file. (Gotta get back to working on my
> church website...)
>
> Also, unlike Arthur and those Perl dweebs (who think they are impressing
> us by using semicolons to squeeze eighteen lines of code into six) I
> decided to leave the code in a somewhat readable state.

:-) Let's be fair, my last submission was literally only three lines of
code. Count the semicolons! Besides, how readable is addressing a hash
element like a two dimensional array?! ;-)

Out of curiosity: is it possible to do CLI programs in ruby, or is the use
of newlines & indentation necessary to delineate lines/blocks of code?

         --Arthur Corliss
           Live Free or Die
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Tue Aug 17 22:33:15 2010

This archive was generated by hypermail 2.1.8 : Tue Aug 17 2010 - 22:33:15 AKDT