Pass the paramater?

mply=0
kill=0
open("list.lfi","rb").each do |block|
['lol', '%00'].each do |suffix|
  while mply < 10
      if block.include? ".log"
        puts suffix
        suffix
        kill=1
  break
  print("!!! Check your log.html !!!")
      end
        if kill==1; break;end
        mply=mply+1
    end
      if kill==1; break;end
      mply=0
  end
    if kill==1; break;end
end

print suffix.last

i always do things the hard way... i dont know how to get suffix out
side of the loop...

···

--
Posted via http://www.ruby-forum.com/.

I don't know what you expect from your given code (you didn't explain
it). However, the line "suffix" in the above code does nothing.

···

2011/2/6 Bigmac Turdsplash <i8igmac@aim.com>:

while mply < 10
if block.include? ".log"
puts suffix
suffix
kill=1

--
Iñaki Baz Castillo
<ibc@aliax.net>

Bigmac Turdsplash wrote in post #979843:

mply=0
kill=0
open("list.lfi","rb").each do |block|
['lol', '%00'].each do |suffix|
  while mply < 10
      if block.include? ".log"
        puts suffix
        suffix
        kill=1
  break
  print("!!! Check your log.html !!!")
      end
        if kill==1; break;end
        mply=mply+1
    end
      if kill==1; break;end
      mply=0
  end
    if kill==1; break;end
end

print suffix.last

i always do things the hard way... i dont know how to get suffix out
side of the loop...

If a local variable is first assigned to inside of a block, then its
scope does not extend outside of the block (i.e. it's local to that
block).

So you can assign to it outside the block:

  foo = nil
  10.times do |x|
    foo = x
  end
  puts foo # remembers value

However, in this case 'suffix' is itself a block argument. In ruby 1.9,
it's forced to be local to that block. In ruby 1.8 the block argument
can be a variable which has already been assigned to, but that's bad
practice.

suffix = nil
['lol', '%00'].each do |suffix
  ... do stuff
end
puts suffix # doesn't work in ruby 1.9

So if you want the value of 'suffix' used in the last iteration of the
loop, simply remember it explicitly.

last_suffix = nil
['lol', '%00'].each do |suffix|
  last_suffix = suffix
  ... do stuff
end
puts last_suffix

···

--
Posted via http://www.ruby-forum.com/.

Bigmac Turdsplash wrote in post #979843:

mply=0
kill=0
open("list.lfi","rb").each do |block|

Another remark: you do not close the IO object properly that is opened
in the line above. Rather do

File.open("list.lfi","rb") do |io|
  io.each do |block|
    ...
  end
end

Btw, I'd consider "line" a better name for the block parameter here.
Although: you open the file with mode "rb" but use a line based
parsing scheme (by using IO#each) - that looks at least odd.

['lol', '%00'].each do |suffix|
while mply < 10

Why do you use a while loop here? Doesn't really look reasonable
since you process the same line (variable "block") over and over
again.

  if block\.include? &quot;\.log&quot;
    puts suffix
    suffix
    kill=1

break
print("!!! Check your log.html !!!")
end
if kill==1; break;end
mply=mply+1
end
if kill==1; break;end
mply=0
end
if kill==1; break;end
end

print suffix.last

i always do things the hard way... i dont know how to get suffix out
side of the loop...

This really looks overly hard. Can you describe what that code is
supposed to do?

Cheers

robert

···

On Sun, Feb 6, 2011 at 9:01 PM, Brian Candler <b.candler@pobox.com> wrote:

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/