Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After staring at this for over an hour, comparing two nearly identical versions, one that worked, one that didn't, I am able to make it fail or succeed by commenting out a single line. here is the exact code I am running: [Edit note, altered the code to prevent vertical scroll bar in code sample]</p> <pre><code>#!/usr/local/bin/ruby my_input ="ATT Wireless Bill\n\nMobile Number:,770-555-1212\n\nitem,date,time,number called,rate period,plan type,minutes,airtime charge,ld charge,total charge\n\n1,2011-01-02,6:56AM,404-555-1212,NW,UNW,4,0.00,0.00,0.00\n\n" my_input &lt;&lt; "2,2011-01-03,6:56AM,404-555-1212,NW,UNW,4,0.00,0.00,0.00\n\n1,2011-01-03,7:56AM,404-555-1213,DT,UM2M,5,0.00,0.00,0.00\n\nMobile Number:,770-555-1213\n\nitem,date,time,number called,rate period,plan type,minutes,airtime charge,ld charge,total charge\n\n" my_input &lt;&lt; "1,2011-01-02,6:56AM,404-555-1212,NW,UNW,4,0.00,0.00,0.00\n\n2,2011-01-03,6:56AM,404-555-1212,NW,UNW,4,0.00,0.00,0.00\n\n1,2011-01-03,7:56AM,404-555-1213,DT,UM2M,5,0.00,0.00,0.00\n\n" lines = my_input.split("\n") count = 0 cur_num = "" # Line 7 - Comment out this line to see failure lines.each do |line| unless (line.strip.eql?("")) if (line.slice(0,15) == "Mobile Number:,") cur_num = line.slice(15,12) count = 1 puts "Current Number: #{cur_num}" #puts "Object Type: #{cur_num.class}" else data = line.strip.split(',') if (data.length &gt; 8) data.unshift(cur_num) #if (count.modulo(10) == 0 || count == 1) puts "[#{cur_num}] #{data.inspect}" #pp data #end count += 1 end end end end </code></pre> <p>If I comment out line 7, then cur_val is nil on lines 18 and 20.</p> <p>Can someone please explain why?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload