Professional Web Applications Themes

Article on oreilly.net on how to build Unix tools with Ruby - Ruby

Thought you'd like to know about this article This links to the printable version, much easier to read. [url]http://linux.oreillynet.com/lpt/a/4159[/url] Enjoy....

  1. #1

    Default Article on oreilly.net on how to build Unix tools with Ruby

    Thought you'd like to know about this article
    This links to the printable version, much easier to read.
    [url]http://linux.oreillynet.com/lpt/a/4159[/url]

    Enjoy.
    Xavier Guest

  2. #2

    Default Re: Article on oreilly.net on how to build Unix tools with Ruby

    On Sat, Sep 20, 2003 at 06:00:21AM +0900, Xavier wrote:
    > Thought you'd like to know about this article
    > This links to the printable version, much easier to read.
    > [url]http://linux.oreillynet.com/lpt/a/4159[/url]
    >
    > Enjoy.
    A pretty good article, though:
    1. It would be nice if it mentioned optp, which is a little
    cleaner than getoptlong for what the author is doing.
    2. Using "while line = gets do" is just as clean as "while gets", but
    doesn't require the use of $_. I suspect the author came from a
    perl background.
    3. I wish he'd mentioned the option of using #!/usr/bin/env ruby
    instead of #!/usr/local/bin/ruby.

    Paul


    Paul Brannan Guest

  3. #3

    Default Re: Article on oreilly.net on how to build Unix tools with Ruby

    Xavier <NOSPAMkeepyourspam.com> wrote:
    > Thought you'd like to know about this article
    > This links to the printable version, much easier to read.
    > [url]http://linux.oreillynet.com/lpt/a/4159[/url]
    Nice script for handling CSVs. But it doesn't handle commas embedded in
    double quotes (yet).

    --
    Geoffrey S. Knauth | [url]http://knauth.org/gsk[/url]
    Geoffrey S. Knauth Guest

  4. #4

    Default Re: Article on oreilly.net on how to build Unix tools with Ruby

    [email]geoffknauth.org[/email] (Geoffrey S. Knauth) writes:
    > Xavier <NOSPAMkeepyourspam.com> wrote:
    > > Thought you'd like to know about this article
    > > This links to the printable version, much easier to read.
    > > [url]http://linux.oreillynet.com/lpt/a/4159[/url]
    >
    > Nice script for handling CSVs. But it doesn't handle commas embedded in
    > double quotes (yet).
    If anyone wants one, I've got a DelimPr class that handles different
    delimiters and quote marks as well as delimiters, escaped characters, and
    doubled quotes that appear in the data.

    It doesn't use regexps. It's a simple state machine that walks through each
    character in the input.

    Ask and thou shall receive.

    Jim
    --
    Jim Menard, [email]jimmio.com[/email], [url]http://www.io.com/~jimm/[/url]
    "$665.95: The Retail Price of the Beast" -- Unknown
    Jim Menard Guest

  5. #5

    Default Re: Article on oreilly.net on how to build Unix tools with Ruby

    > If anyone wants one, I've got a DelimPr class that handles
    different
    > delimiters and quote marks as well as delimiters, escaped
    characters, and
    > doubled quotes that appear in the data.
    >
    > It doesn't use regexps. It's a simple state machine that walks
    > through each character in the input.
    >
    > Ask and thou shall receive.
    I'd like to get a copy of that please.

    I've used [url]http://raa.ruby-lang.org/list.rhtml?name=csv[/url] in the past,
    and while it works for my feeble CSV needs, I find the interface
    somewhat [overly] complex.


    __________________________________
    Do you Yahoo!?
    Yahoo! SiteBuilder - Free, easy-to-use web site design software
    [url]http://sitebuilder.[/url]

    Michael Campbell Guest

  6. #6

    Default Re: Article on oreilly.net on how to build Unix tools with Ruby

    il 23 Sep 2003 15:06:01 -0500, Jim Menard <jimmio.com> ha scritto::
    >It doesn't use regexps. It's a simple state machine that walks through each
    >character in the input.
    >
    >Ask and thou shall receive.

    would you please send me a copy or publish it on RAA ?

    gabriele renzi Guest

  7. #7

    Default Re: Article on oreilly.net on how to build Unix tools with Ruby

    gabriele renzi <surrender_itremove.yahoo.it> writes:

    > il 23 Sep 2003 15:06:01 -0500, Jim Menard <jimmio.com> ha scritto::
    >
    > >It doesn't use regexps. It's a simple state machine that walks through each
    > >character in the input.
    > >
    > >Ask and thou shall receive.
    >
    >
    > would you please send me a copy or publish it on RAA ?
    >
    Gabriele,

    I emailed it to you and Michael and posted it to
    <http://www.io.com/~jimm/downloads/index.html>.

    Jim
    --
    Jim Menard, [email]jimmio.com[/email], [url]http://www.io.com/~jimm/[/url]
    "Unix is extremely user-friendly. It also happens to be extremely
    selective when picking its friends." -- Daniel E. Macks
    Jim Menard Guest

  8. #8

    Default Re: Article on oreilly.net on how to build Unix tools with Ruby

    On Wednesday, 24 September 2003 at 5:15:41 +0900, Jim Menard wrote:
    > [email]geoffknauth.org[/email] (Geoffrey S. Knauth) writes:
    >
    > > Xavier <NOSPAMkeepyourspam.com> wrote:
    > > > Thought you'd like to know about this article
    > > > This links to the printable version, much easier to read.
    > > > [url]http://linux.oreillynet.com/lpt/a/4159[/url]
    > >
    > > Nice script for handling CSVs. But it doesn't handle commas embedded in
    > > double quotes (yet).
    >
    I have found that the csv pr by NaHi to be very good and
    full featured.

    [url]http://raa.ruby-lang.org/list.rhtml?name=csv[/url]


    --
    Jim Freeze
    ----------
    God made the world in six days, and was arrested on the seventh.

    Jim Freeze Guest

  9. #9

    Default Re: Article on oreilly.net on how to build Unix tools with Ruby

    On Wednesday, September 24, 2003, 2:33:01 AM, Paul wrote:
    > 3. I wish he'd mentioned the option of using #!/usr/bin/env ruby
    > instead of #!/usr/local/bin/ruby.

    Can someone please explain to me what /usr/bin/env/ruby does?

    Thanks,
    Gavin


    Gavin Sinclair Guest

  10. #10

    Default Re: Article on oreilly.net on how to build Unix tools with Ruby

    * Gavin Sinclair <gsinclairsoyabean.com.au> [2003-09-23 17:16]:
    > On Wednesday, September 24, 2003, 2:33:01 AM, Paul wrote:
    > > 3. I wish he'd mentioned the option of using #!/usr/bin/env ruby
    > > instead of #!/usr/local/bin/ruby.
    >
    > Can someone please explain to me what /usr/bin/env/ruby does?
    Note that there's no slash between "env" and "ruby"... env is a program that
    lets you run a program in a modified environment, and it's also useful on the
    shebang line if you don't know the exact location of the interpreter you want
    to run. It will find the executable in the path before executing it.

    -- Mike

    --
    Michael W. Thelen
    Experience is what you get when you don't get what you want.
    -- Dan Stanford

    Michael W Thelen Guest

  11. #11

    Default Re: Article on oreilly.net on how to build Unix tools with Ruby

    On Wednesday, 24 September 2003 at 8:24:36 +0900, Michael W Thelen wrote:
    > * Gavin Sinclair <gsinclairsoyabean.com.au> [2003-09-23 17:16]:
    > > On Wednesday, September 24, 2003, 2:33:01 AM, Paul wrote:
    > > > 3. I wish he'd mentioned the option of using #!/usr/bin/env ruby
    > > > instead of #!/usr/local/bin/ruby.
    > >
    > > Can someone please explain to me what /usr/bin/env/ruby does?
    Speaking of env, does this work on linux when options are passed
    to ruby?

    I'm not at a linux terminal right now, but when the shebang is:

    /usr/bin/env ruby -w

    I get the error that ruby -w is not found.
    The gnu manual says that it should work, but it certainly
    doesn't work as it does on FreeBSD or Sun.

    The distro is RH 7.3.


    --
    Jim Freeze
    ----------
    Adore, v.:
    To venerate expectantly.
    -- Ambrose Bierce, "The Devil's Dictionary"

    Jim Freeze Guest

  12. #12

    Default Re: Article on oreilly.net on how to build Unix tools with Ruby

    On Wed, Sep 24, 2003 at 09:04:55AM +0900, Jim Freeze wrote:
    > Speaking of env, does this work on linux when options are passed
    > to ruby?
    No, it doesn't. I've seen a detailed explanation somewhere on a perl
    mailing list or newsgroup, but I can't remember the specifics.

    Paul


    Paul Brannan Guest

  13. #13

    Default Re: Article on oreilly.net on how to build Unix tools with Ruby

    Hi,
    > From: "Jim Freeze" <jimfreeze.org>
    > Sent: Wednesday, September 24, 2003 7:05 AM
    > > > Xavier <NOSPAMkeepyourspam.com> wrote:
    > > > > Thought you'd like to know about this article
    > > > > This links to the printable version, much easier to read.
    > > > > [url]http://linux.oreillynet.com/lpt/a/4159[/url]
    > > >
    > > > Nice script for handling CSVs. But it doesn't handle commas embedded in
    > > > double quotes (yet).
    > I have found that the csv pr by NaHi to be very good and
    > full featured.
    >
    > [url]http://raa.ruby-lang.org/list.rhtml?name=csv[/url]
    And is bundled in ruby from 1.8...
    It can p <<__EOS__.chomp
    a,b,",","""","\r\n","\r","\n"
    __EOS__

    Of cource it must have easy interface!
    Any suggestion are welcome. How do you want to write
    parsing code?

    Regards,
    // NaHi

    PS. Current interface;

    SYNOPSIS

    1. reader = CSV.open( filename, "r" )

    2. CSV.open( filename, "r" ) do | row |
    ...
    end

    3. writer = CSV.open( filename, "w" )

    4. CSV.open( filename, "w" ) do | writer |
    ...
    end

    ARGS

    filename: filename to open.
    mode: "r" for read (p)
    "w" for write (generate)
    row: an Array of cells which is a pd line.
    writer: Created writer instance. See CSV::Writer#<< and
    CSV::Writer#addRow to know how to generate CSV string.

    RETURNS

    reader: Create reader instance. To get p result, see
    CSV::Reader#each.
    writer: Created writer instance. See CSV::Writer#<< and
    CSV::Writer#addRow to know how to generate CSV string.

    DESCRIPTION

    Open a CSV formatted file to read or write.

    EXAMPLE 1

    reader = CSV.open( "csvfile.csv", "r" )
    row1 = reader.shift
    row2 = reader.shift
    if row2.empty?
    p "row2 not find."
    end
    reader.close

    EXAMPLE 2

    CSV.open( "csvfile.csv", "r" ) do | row |
    p row
    end

    EXAMPLE 3

    writer = CSV.open( "csvfile.csv", "w" )
    writer << [ "r1c1", "r1c2" ] << [ "r2c1", "r2c2" ] << [ nil, nil ]
    writer.close

    EXAMPLE 4

    CSV.open( "csvfile.csv", "w" ) do | writer |
    writer << [ "r1c1", "r1c2" ]
    writer << [ "r2c1", "r2c2" ]
    writer << [ nil, nil ]
    end

    NAKAMURA, Hiroshi Guest

  14. #14

    Default Re: Article on oreilly.net on how to build Unix tools with Ruby

    Hi,
    > From: "NAKAMURA, Hiroshi" <nakahirosarion.co.jp>
    > Sent: Wednesday, September 24, 2003 11:54 AM
    > Of cource it must have easy interface!
    > Any suggestion are welcome. How do you want to write
    > parsing code?
    I didn't mean "it must be easy already without any modification".
    I mean "it should have easy interface if the current interface
    is not easy".

    Where's my teacher of English composition?

    Regards,
    // NaHi

    NAKAMURA, Hiroshi Guest

  15. #15

    Default Re: Article on oreilly.net on how to build Unix tools with Ruby


    Paul Brannan wrote:
    >
    >
    > 3. I wish he'd mentioned the option of using #!/usr/bin/env ruby
    > instead of #!/usr/local/bin/ruby.
    >
    >Paul
    >
    >
    >
    advantages ?

    -r.


    Bermejo, Rodrigo Guest

  16. #16

    Default Re: Article on oreilly.net on how to build Unix tools with Ruby

    On Wednesday, 24 September 2003 at 12:30:24 +0900, Bermejo, Rodrigo wrote:
    >
    > Paul Brannan wrote:
    >
    > >
    > >
    > > 3. I wish he'd mentioned the option of using #!/usr/bin/env ruby
    > > instead of #!/usr/local/bin/ruby.
    > >
    > advantages ?
    >
    I thought someone had already mentioned the advantages.
    Basically, you don't need to know the path of ruby.
    So, if you are distributing an application, your app
    will run no matter where ruby is installed.

    There are also options that you can pass to env to
    control environment variables.

    The main disadvantage is that using env increases
    the security risk over a hard coded path.

    --
    Jim Freeze
    ----------
    It is now 10 p.m. Do you know where Henry Kissinger is?
    -- Elizabeth Carpenter

    Jim Freeze Guest

  17. #17

    Default Re: Article on oreilly.net on how to build Unix tools with Ruby

    > On Sat, Sep 20, 2003 at 06:00:21AM +0900, Xavier wrote:
    >
    >>Thought you'd like to know about this article
    >>This links to the printable version, much easier to read.
    >>[url]http://linux.oreillynet.com/lpt/a/4159[/url]
    >>
    >>Enjoy.
    Speaking of Unix tools, do any of the Perlians in this list remember Tom
    Christiansen's pet project Perl Power Tools?

    [url]http://www.perl.com/language/ppt/[/url]

    The project aims to rewrite many Unix commands in Perl, from simple
    commands like 'echo', 'clear', and 'cat' to moderately complex ones like
    'cp', 'find', and 'ls' to complex ones like 'awk', 'make', and 'm4'.
    Take a look at the URL above, they seem to have implemented a good chunk
    of them.

    Perhaps someone with extra free time on his hands would like to take a
    stab on a Ruby Power Tools project? ;-)

    --
    dave



    David Garamond Guest

  18. #18

    Default Re: Article on oreilly.net on how to build Unix tools with Ruby

    In article <20030923200517.A36392freeze.org>,
    Jim Freeze <jimfreeze.org> wrote:
    >On Wednesday, 24 September 2003 at 8:24:36 +0900, Michael W Thelen wrote:
    >> * Gavin Sinclair <gsinclairsoyabean.com.au> [2003-09-23 17:16]:
    >> > On Wednesday, September 24, 2003, 2:33:01 AM, Paul wrote:
    >> > > 3. I wish he'd mentioned the option of using #!/usr/bin/env ruby
    >> > > instead of #!/usr/local/bin/ruby.
    >> >
    >> > Can someone please explain to me what /usr/bin/env/ruby does?
    >
    >Speaking of env, does this work on linux when options are passed
    >to ruby?
    >
    >I'm not at a linux terminal right now, but when the shebang is:
    >
    > /usr/bin/env ruby -w
    >
    > I get the error that ruby -w is not found.
    > The gnu manual says that it should work, but it certainly
    > doesn't work as it does on FreeBSD or Sun.
    One way of getting arounf env's ignoring ARGS iff you are just doing -w
    is to put

    $VERBOSE = true

    after the shebang line. See
    [url]http://mail.gnu.org/archive/html/bug-sh-utils/2002-04/msg00020.html[/url]
    for an explanation.

    Hope this helps,

    Mike

    --
    [email]mikestok.co.uk[/email] | The "`Stok' disclaimers" apply.
    [url]http://www.stok.co.uk/~mike/[/url] | GPG PGP Key 1024D/059913DA
    [email]mikeexegenix.com[/email] | Fingerprint 0570 71CD 6790 7C28 3D60
    [url]http://www.exegenix.com/[/url] | 75D2 9EC4 C1C0 0599 13DA
    Mike Stok Guest

  19. #19

    Default Re: Article on oreilly.net on how to build Unix tools with Ruby

    On Wednesday, 24 September 2003 at 20:18:42 +0900, Mike Stok wrote:
    > In article <20030923200517.A36392freeze.org>,
    > >
    > > I get the error that ruby -w is not found.
    > > The gnu manual says that it should work, but it certainly
    > > doesn't work as it does on FreeBSD or Sun.
    >
    > One way of getting arounf env's ignoring ARGS iff you are just doing -w
    > is to put
    >
    > $VERBOSE = true
    >
    > after the shebang line. See
    Yes, that is our current work around. It's probably the better
    convention because it is reliable for all platforms.


    --
    Jim Freeze
    ----------
    All things are possible, except skiing thru a revolving door.

    Jim Freeze Guest

  20. #20

    Default Re: Article on oreilly.net on how to build Unix tools with Ruby

    On Wed, 2003-09-24 at 02:23, David Garamond wrote:
    > Speaking of Unix tools, do any of the Perlians in this list remember Tom
    > Christiansen's pet project Perl Power Tools?
    >
    > [url]http://www.perl.com/language/ppt/[/url]
    >
    > The project aims to rewrite many Unix commands in Perl, from simple
    > commands like 'echo', 'clear', and 'cat' to moderately complex ones like
    > 'cp', 'find', and 'ls' to complex ones like 'awk', 'make', and 'm4'.
    > Take a look at the URL above, they seem to have implemented a good chunk
    > of them.
    >
    > Perhaps someone with extra free time on his hands would like to take a
    > stab on a Ruby Power Tools project? ;-)
    rpt.rubyforge.org is still available...

    Yours,

    Tom
    --
    Tom Copeland <tominfoether.com>
    InfoEther


    Tom Copeland Guest

Page 1 of 2 12 LastLast

Similar Threads

  1. Article : Security Tools Part -- 2 (.Net FrameWork Tools Series)
    By Namratha Shah \(Nasha\) in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: November 23rd, 04:01 PM
  2. Article: What is Isolated Storage ? (.Net FrameWork Tools Series)
    By Namratha Shah \(Nasha\) in forum ASP.NET Data Grid Control
    Replies: 3
    Last Post: November 19th, 08:59 PM
  3. Article : Code Access Security Part - 1 (.Net FrameWork Tools Series)
    By Namratha Shah \(Nasha\) in forum ASP.NET Building Controls
    Replies: 0
    Last Post: November 6th, 03:37 PM
  4. unix tools
    By Gustavo Rios in forum Linux / Unix Administration
    Replies: 0
    Last Post: August 20th, 05:16 PM
  5. Replies: 4
    Last Post: September 12th, 09:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139