[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Deleting objects?

Paatsch, Bernd

2/15/2006 10:46:00 PM

My mistake:

I set an variable to nil outside the loop and then the second time around it
was not nil and therefore not populating the hash as I expected.

-Bernd


-----Original Message-----
From: John Carter [mailto:john.carter@tait.co.nz]
Sent: Wednesday, February 15, 2006 2:17 PM
To: ruby-talk ML
Subject: Re: Deleting objects?

On Thu, 16 Feb 2006, Paatsch, Bernd wrote:

> My little program works one. However fails when I add a loop two run
> it multiple times with different input data.
>
> I believe this might be due to objects that have not been delete. Is
> there a way to delete objects other than setting the variable to nil?

Example...

$global_var = {}

def my_func( line)
# Uses $global_var, $global_var just accumulates objects, never letting
# go.
end

STDIN.each_line do |line|
my_func( line)
end

# Now if we use a local variable like so...

def my_func( line)
local_var = {}
# We get a fresh new hash every loop, old hash and old objects we held
# on to are garbage collected automagically every time we leave the
# scope of the variable.
end

To really debug your problem we need to see your code.

John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : john.carter@tait.co.nz
New Zealand

Carter's Clarification of Murphy's Law.

"Things only ever go right so that they may go more spectacularly wrong
later."

From this principle, all of life and physics may be deduced.


5 Answers

Henning

10/16/2013 5:55:00 PM

0


"MM" <kylix_is@yahoo.co.uk> skrev i meddelandet
news:1lht591evkhdnfdt5sd16e2boe2k4u8eii@4ax.com...
> On Wed, 16 Oct 2013 17:34:28 +0100, Deanna Earley
> <dee.earley@icode.co.uk> wrote:
>
>>On 16/10/2013 17:11, MM wrote:
>>> Text strings are what's being filtered.
>>>
>>> What I want is to filter for (A AND B) OR (C AND D) or maybe
>>> (A AND B AND C) OR D
>>>
>>> What's the best way to approach this? Regular expressions?
>>
>>Filter in what way?
>>
>>If (Instr(blah, "A") > 0 And Instr(blah, "B") > 0) or (Instr(blah, "C")
>> > 0 And Instr(blah, "D") > 0) Then
>
> But I might only have a simple filter:
> If A AND B...
>
> or If A OR B...
>
> as well as any combination of compound filters using parentheses. I
> can hardly have a whole bunch of different If (Instr(blah, "A") > )...
> etc statements, and you can't change the If statement at runtime
> (although I recall reading years ago that some add-in or something
> allowed the programmer to create on-the-fly code changes at runtime).
>
> What I need is *one* section of code that will deal with every
> eventuality, including, later, NOT tests combined with AND and OR,
> with/without parentheses depending on what filtering I needed.
>
> So, for example, let's assume the text contains:
> "ben walked to the end of the road to meet sally, but bill was there"
>
> I might want to filter using the following criteria:
>
> Only include record if "ben" is present.
> Only include record if "sally" or "bill" is present.
> Only include record if "road" and "bill" are present.
> and so on.
>
> The above text is short, but in practice it might be several lines
> long and the filters might run to 10 or more, coupled with any
> combination of AND, OR, or NOT, plus parentheses where necessary.
>
> Note: I don't need to find *where* a word/substring is in the text;
> just that it is present or absent.
>
>>You can split it up into individual temporary variables or separate
>>checks depending on the exact structure and what it's doing.
>
> MM

Separate Functions for each combination of criteria...

/Henning



Jeff Johnson [MVP: VB]

10/16/2013 9:53:00 PM

0

"MM" <kylix_is@yahoo.co.uk> wrote in message
news:1lht591evkhdnfdt5sd16e2boe2k4u8eii@4ax.com...

>>> What I want is to filter for (A AND B) OR (C AND D) or maybe
>>> (A AND B AND C) OR D
>>>
>>> What's the best way to approach this? Regular expressions?

Regular expressions sounds like the way to go here. However, what controls
the switching between criteria? I mean, it sounds like you're looking for
some means of dynamically specifying criteria to apply in situation "x." How
do you intend to address that selection of criteria? Have the user input a
regex manually? Pick from a list of options?


MikeB

10/17/2013 2:53:00 AM

0


"MM" <kylix_is@yahoo.co.uk> wrote in message
news:1lht591evkhdnfdt5sd16e2boe2k4u8eii@4ax.com...
> On Wed, 16 Oct 2013 17:34:28 +0100, Deanna Earley
> <dee.earley@icode.co.uk> wrote:
>
>>On 16/10/2013 17:11, MM wrote:
>>> Text strings are what's being filtered.
>>>
>>> What I want is to filter for (A AND B) OR (C AND D) or maybe
>>> (A AND B AND C) OR D
>>>
>>> What's the best way to approach this? Regular expressions?
>>
>>Filter in what way?
>>
>>If (Instr(blah, "A") > 0 And Instr(blah, "B") > 0) or (Instr(blah, "C")
>> > 0 And Instr(blah, "D") > 0) Then
>
> But I might only have a simple filter:
> If A AND B...
>
> or If A OR B...
>
> as well as any combination of compound filters using parentheses. I
> can hardly have a whole bunch of different If (Instr(blah, "A") > )...
> etc statements, and you can't change the If statement at runtime
> (although I recall reading years ago that some add-in or something
> allowed the programmer to create on-the-fly code changes at runtime).

Eval?

> What I need is *one* section of code that will deal with every
> eventuality, including, later, NOT tests combined with AND and OR,
> with/without parentheses depending on what filtering I needed.
>
> So, for example, let's assume the text contains:
> "ben walked to the end of the road to meet sally, but bill was there"
>
> I might want to filter using the following criteria:
>
> Only include record if "ben" is present.
> Only include record if "sally" or "bill" is present.
> Only include record if "road" and "bill" are present.
> and so on.
>
> The above text is short, but in practice it might be several lines
> long and the filters might run to 10 or more, coupled with any
> combination of AND, OR, or NOT, plus parentheses where necessary.
>
> Note: I don't need to find *where* a word/substring is in the text;
> just that it is present or absent.
>
>>You can split it up into individual temporary variables or separate
>>checks depending on the exact structure and what it's doing.
>
> MM


(Mike Mitchell)

10/17/2013 6:18:00 AM

0

On Wed, 16 Oct 2013 17:53:10 -0400, "Jeff Johnson" <i.get@enough.spam>
wrote:

>"MM" <kylix_is@yahoo.co.uk> wrote in message
>news:1lht591evkhdnfdt5sd16e2boe2k4u8eii@4ax.com...
>
>>>> What I want is to filter for (A AND B) OR (C AND D) or maybe
>>>> (A AND B AND C) OR D
>>>>
>>>> What's the best way to approach this? Regular expressions?
>
>Regular expressions sounds like the way to go here. However, what controls
>the switching between criteria? I mean, it sounds like you're looking for
>some means of dynamically specifying criteria to apply in situation "x." How
>do you intend to address that selection of criteria? Have the user input a
>regex manually? Pick from a list of options?

The user types in a simplified expression, such as:

(into a text box)

"cat"

or

"cat AND dog"

or

"(cat AND dog) OR pig"

or

"(cat AND dog) OR (pig AND horse)"
etc

The AND and OR don't need to be uppercase.

MM

(Mike Mitchell)

10/17/2013 4:04:00 PM

0

On Thu, 17 Oct 2013 17:51:56 +0200, ObiWan <obiwan@mvps.org> wrote:

>
>> "cat"
>>
>> or
>>
>> "cat AND dog"
>>
>> or
>>
>> "(cat AND dog) OR pig"
>>
>> or
>>
>> "(cat AND dog) OR (pig AND horse)"
>> etc
>>
>> The AND and OR don't need to be uppercase.
>
>ok... what if the *searched* terms are "OR" and/or "AND" <eg> ?

Not allowed.

MM