The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Tail of emerge.log

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Florian Frank

Posts: 48
Nickname: ffrank
Registered: Dec, 2005

Florian Frank is a humanoid life-form, living on the third planet of the solar system.
Tail of emerge.log Posted: Apr 4, 2006 5:08 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Florian Frank.
Original Post: Tail of emerge.log
Feed Title: The Rubylution: Tag Ruby
Feed URL: http://rubylution.ping.de/xml/rss/tag/ruby/feed.xml
Feed Description: Starts… Now.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Florian Frank
Latest Posts From The Rubylution: Tag Ruby

Advertisement

I tailed my /var/log/emerge.log on one of my gentoo systems, and saw that they give the time in unixtime stamps (= seconds since the epoch). This is a bit difficult to interpret, so I came up with this short oneliner in Ruby, which converts the timestamp into ISO format (my fav!):

ruby -pe 'sub /\d+/, Time.at($&.to_i).strftime("%F %T")'

This is quite short, and it's usually difficult to do such small tasks in Ruby shorter than in Perl. This is my version of this oneliner in Perl:

perl -MPOSIX -pe 's/\d+/strftime("%F %T", localtime($&))/e'

It's a few characters longer, but not much. It's easy to see from this example, that Ruby and Perl are very similar, especially regarding command line options and special $-variables. Well, I guess Ruby was a bit "inspired" by Perl. But somehow I like the Ruby oneliner better and it seems clearer to me (and it doesn't require loading a special module). To use Perl's black magic /e modifier, always seemed to be a bit dirty to me as well.

Disclaimer: I might be quite biased, I guess. ;)

Read: Tail of emerge.log

Topic: The adventures of scaling, Stage 4 Previous Topic   Next Topic Topic: Restful Rails Revisited

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use