[#385051] How to order Structs based on two fields — Iñaki Baz Castillo <ibc@...>

Hi, I've a struct like this:

20 messages 2011/07/01
[#385052] Re: How to order Structs based on two fields — Iñaki Baz Castillo <ibc@...> 2011/07/01

2011/7/1 Iñaki Baz Castillo <ibc@aliax.net>:

[#385057] Re: How to order Structs based on two fields — Robert Klemme <shortcutter@...> 2011/07/01

On Fri, Jul 1, 2011 at 12:55 PM, Iki Baz Castillo <ibc@aliax.net> wrote:

[#385069] Offering Help — Joe Peric <peric.joe@...>

I'm new to Ruby and I am willing to learn. Anyone need help on a

18 messages 2011/07/01
[#385072] Re: Offering Help — Jeremy Heiler <jeremyheiler@...> 2011/07/01

On Fri, Jul 1, 2011 at 11:43 AM, Joe Peric <peric.joe@gmail.com> wrote:

[#385073] Re: Offering Help — Joe Peric <peric.joe@...> 2011/07/01

Never heard of it, but I'll get right on it. Thanks.

[#385082] Re: Offering Help — Joe Peric <peric.joe@...> 2011/07/02

Just finished this. I had to find some more info on exceptions to get

[#385083] Re: Offering Help — Jeremy Heiler <jeremyheiler@...> 2011/07/02

On Sat, Jul 2, 2011 at 1:39 PM, Joe Peric <peric.joe@gmail.com> wrote:

[#385102] symbol vs string for hash keys — Intransition <transfire@...>

What are the important factors to consider when deciding whether to

12 messages 2011/07/03

[#385160] Fatal Error with Ruby/GTK2, Homebrew, Green Shoes, and OSX Snow Leopard — Timothy Barnes <barnes7td@...>

I posted the below question to the Shoes mailing list and got back the

10 messages 2011/07/09

[#385194] RubyInstaller Extras — Jon <jon.forums@...>

Since 2009, we've been pleased to include Huw Collingbourne's The Book of Ruby with RubyInstaller. Well now, Huw has a newly updated version, and he's published it with No Starch Press.

11 messages 2011/07/12

[#385207] Creating a range of directories — Simon Harrison <simon@...>

I'm wanting to create a range of directories with a prefix, like the

13 messages 2011/07/13

[#385276] Is there a more efficient way to remove data from a string? — Eddie Catflap <catflaporama@...>

Hi

9 messages 2011/07/15

[#385297] Help needed for a new release of text-hyphen — Austin Ziegler <halostatue@...>

I've had folks asking me for a release of text-hyphen that works with

12 messages 2011/07/15

[#385326] Comparing hashes based on their keys — Stefano Mioli <stefano.mioli@...>

Hi list,

13 messages 2011/07/15

[#385342] moving a 1.8.6 install? — Roggie Boone <rogboone@...>

Is it possible to move the gems from a Ruby 1.8.6 install on an (old)

10 messages 2011/07/15

[#385410] Better name for #zip_with — Intransition <transfire@...>

Any ideas for a better name for:

13 messages 2011/07/18

[#385452] Ruby + USB + CCTV Camera Driver? — "Bob Carpenter." <rgc3679@...>

I want to write a Ruby driver that handles the feed from A CCTV camera.

23 messages 2011/07/18
[#385459] Re: Ruby + USB + CCTV Camera Driver? — William Rutiser <wruyahoo05@...> 2011/07/18

On 2011-07-18 1:00 PM, Bob Carpenter. wrote:

[#385461] Re: Ruby + USB + CCTV Camera Driver? — "Bob Carpenter." <rgc3679@...> 2011/07/18

William Rutiser wrote in post #1011466:

[#385462] Re: Ruby + USB + CCTV Camera Driver? — Hassan Schroeder <hassan.schroeder@...> 2011/07/18

On Mon, Jul 18, 2011 at 11:51 AM, Bob Carpenter. <rgc3679@yahoo.com> wrote:

[#385464] Re: Ruby + USB + CCTV Camera Driver? — "Bob Carpenter." <rgc3679@...> 2011/07/18

Hassan Schroeder wrote in post #1011472:

[#385471] Re: Ruby + USB + CCTV Camera Driver? — Hassan Schroeder <hassan.schroeder@...> 2011/07/18

On Mon, Jul 18, 2011 at 12:58 PM, Bob Carpenter. <rgc3679@yahoo.com> wrote:

[#385474] Re: Ruby + USB + CCTV Camera Driver? — Phillip Gawlowski <cmdjackryan@...> 2011/07/18

On Tue, Jul 19, 2011 at 12:18 AM, Hassan Schroeder

[#385477] Re: Ruby + USB + CCTV Camera Driver? — "Bob Carpenter." <rgc3679@...> 2011/07/19

Phillip Gawlowski wrote in post #1011503:

[#385509] A beginner question. — "Cajus A." <cajus_@...>

Hi i'm trying to write and example program where you speak to a

12 messages 2011/07/19

[#385542] Splitting strings — Ryan Mckenzie <ryan@...>

Hi all,

18 messages 2011/07/19

[#385565] error building ruby p290 — Dev Guy <devguy.ca@...>

I get the following build error on my Linux box while trying to build

12 messages 2011/07/20

[#385629] Are Job Ads OK? — Lee Hughes <lee@...>

Is it OK to post Ruby job ads on this forum?

12 messages 2011/07/21

[#385847] String manuplation example — kotin 76 <kotin76@...>

Hi,

15 messages 2011/07/27

[#385860] Counting lines of code in a ruby code file ignoring method code lines in the process — Harry Truax <htruax@...>

Hello,

8 messages 2011/07/27

[#385936] Help in Pointer — Tridib Bandopadhyay <tridib04@...>

Hello

18 messages 2011/07/29

[#386012] Ruby a "4th generation language"? Credible sources? — Albert Schlef <albertschlef@...>

I've noticed that Wikipedia says that "C#, Java" are 3'rd generation

13 messages 2011/07/31

[#386050] system stack error in ObjectSpace.each_object — luke gruber <luke.gru@...>

Hey guys, I'm just starting to mess around with metaprogramming in Ruby,

14 messages 2011/07/31
[#386052] Re: system stack error in ObjectSpace.each_object — Josh Cheek <josh.cheek@...> 2011/07/31

On Sun, Jul 31, 2011 at 4:29 PM, luke gruber <luke.gru@gmail.com> wrote:

[#386055] Re: system stack error in ObjectSpace.each_object — luke gruber <luke.gru@...> 2011/08/01

> Typically, SystemStackError is due to recursing for too long, perhaps I

[#386058] Re: system stack error in ObjectSpace.each_object — Robert Klemme <shortcutter@...> 2011/08/01

On Mon, Aug 1, 2011 at 3:56 AM, luke gruber <luke.gru@gmail.com> wrote:

Re: if condition for pattern matching

From: Chad Perrin <code@...>
Date: 2011-07-27 17:54:38 UTC
List: ruby-talk #385882
On Thu, Jul 28, 2011 at 01:55:37AM +0900, kotin 76 wrote:
> Hi any one can reply for this?

Give people a chance to read, formulate a response, and reply.  Sometimes
it takes time.  We are all members of a community here who have lives
outside of this mailing list; we are not some organization's customer
support channel.

> kotin 76 wrote in post #1013393:
> > Hi ,
> >
> > i applying same above logic for below program
> >
> >   1
> >   2 #!/usr/bin/env ruby
> >   3
> >   5  dev2 = File.readlines("dev_string2.txt")
> >   8
> >   9
> >  10 for i in dev2
> >  11 devstring=i.match(/\/dev\/[\w]+/)
> >  12 puts devstring
> >  14     if  devstring =~ %r{/dev/} then
> >  15     puts "pass"
> >  16     end
> >  17 end

You may want to try using more consistent formatting for your code in
line with common Ruby idioms.  Taking care with code formatting makes
your code easier to read, which makes people more likely to reply.

If I eliminate the line numbers, your code might better be formatted
thusly (with the whole code sample indented by four spaces in this case
to set it off from the main text of the email):

    dev2 = File.dreadlines("dev_string2.txt")

    for i in dev2
      devstring = i.match(/\/dev\/[\w]+/)
      puts devstring

      if devstring =~ %r{/dev/} then
        puts "pass"
      end
    end

With this clearer formatting, it is easier at a glance for most Rubyists
to see where your code might be cleaned up and altered to make it do what
you want it to do.

In addition, you might want to use the %r syntax for the regex used in
the i.match expression, as well as in the devstring matching expression,
and you might want to leave out the unnecessary brackets in that regex:

    devstring = i.match %r{/dev/\w+}

> >
> > but i am not able to print pass. pleas suggest any thing to print pass

Your devstring variable does not actually contain a string.  It contains
a MatchData object, because that is what your i.match expression returns.
A MatchData object for %r{/dev/\w+} will not match a string, so your
later devstring matching expression fails to find a match.  You must
change your MatchData object into a string in one of at least two places
to make the minimally effective change to your code.

One place is where the first regular expression is used, resulting in
code like the following:

    dev2 = File.dreadlines("dev_string2.txt")

    for i in dev2
      devstring = i.match( %r{/dev/\w+} ).to_s
      puts devstring
      
      if devstring =~ %r{/dev/} then
        puts "pass"
      end
    end

Another is to change it where your second regular expression is used,
resulting in code like the following:

    dev2 = File.dreadlines("dev_string2.txt")

    for i in dev2
      devstring = i.match %r{/dev/\w+}
      puts devstring
      
      if devstring.to_s =~ %r{/dev/} then
        puts "pass"
      end
    end

> >
> > pleas find the attached file of dev_string2.txt

I have not looked at this file, so I am not 100% certain my code samples
will solve all your problems here, but hopefully my code samples will
help you understand the problem you have been having.

There are other changes I might make to this code, but I do not want to
clutter this email's code samples with too much information that
distracts from the central problems at hand.

-- 
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]

In This Thread