Professional Web Applications Themes

p format - ruby bug? - dumb program? - Ruby

Hi! Can I specify how strings are printed, when using the p function? I mean with ' or with " ? --- During running a little program, which detects files with the same content, I get a ruby bug: processing dir c:\WINDOWS\SYSTEM\VMM32 processing dir c:\WINDOWS\SYSTEM\CatRoot processing dir c:\WINDOWS\SYSTEM\CatRoot\{F750E6C3-38EE-11D1-85E5-00C04FC295EE} processing dir c:\WINDOWS\SYSTEM\CatRoot\{127D0A1D-4EF2-11D1-8608-00C04FC295EE} processing dir c:\WINDOWS\SYSTEM\sfp processing dir c:\WINDOWS\SYSTEM\sfp\tempcats processing dir c:\WINDOWS\SYSTEM\DirectX processing dir c:\WINDOWS\SYSTEM\DirectX\Migrate processing dir c:\WINDOWS\SYSTEM\DirectX\Dinput processing dir c:\WINDOWS\SYSTEM\Drivers Ooops c:\WINDOWS\SYSTEM\VJOYD.VXD: No such file or directory - c:\WINDOWS\SYSTEM \DirectX\Migrate\vjoyd.vxd same.rb:4: [BUG] rb_sys_fail() - errno == 0 ruby 1.8.0 (2003-08-04) [i386-mingw32] abnormal program termination It is a self-compiled ruby. The program ...

  1. #1

    Default p format - ruby bug? - dumb program?

    Hi!

    Can I specify how strings are printed, when using the p function?
    I mean with ' or with " ?

    ---
    During running a little program, which detects files with the same
    content, I get a ruby bug:
    processing dir c:\WINDOWS\SYSTEM\VMM32
    processing dir c:\WINDOWS\SYSTEM\CatRoot
    processing dir
    c:\WINDOWS\SYSTEM\CatRoot\{F750E6C3-38EE-11D1-85E5-00C04FC295EE}
    processing dir
    c:\WINDOWS\SYSTEM\CatRoot\{127D0A1D-4EF2-11D1-8608-00C04FC295EE}
    processing dir c:\WINDOWS\SYSTEM\sfp
    processing dir c:\WINDOWS\SYSTEM\sfp\tempcats
    processing dir c:\WINDOWS\SYSTEM\DirectX
    processing dir c:\WINDOWS\SYSTEM\DirectX\Migrate
    processing dir c:\WINDOWS\SYSTEM\DirectX\Dinput
    processing dir c:\WINDOWS\SYSTEM\Drivers
    Ooops c:\WINDOWS\SYSTEM\VJOYD.VXD: No such file or directory -
    c:\WINDOWS\SYSTEM
    \DirectX\Migrate\vjoyd.vxd
    same.rb:4: [BUG] rb_sys_fail() - errno == 0
    ruby 1.8.0 (2003-08-04) [i386-mingw32]


    abnormal program termination

    It is a self-compiled ruby.

    The program follows: BTW: can anybody simplify it, or make it clearer.
    It seems to work, but I think it can be written more compact...
    (I wrote it in python (I don't know python, I just tried it), and the
    outputs are different.)
    ================================================== ==========
    $files=Hash.new { [] } # {theSize=>[[fn1,fn2],[fn3]]} fn1 and fn2 have same content

    def equalFiles? fn1, fn2
    f1=File.open fn1,'r'
    f2=File.open fn2,'r'
    while chunk1=f1.read(512)
    chunk2=f2.read(512)
    return false if chunk1!=chunk2
    end
    return true
    end

    def processDir(dir='.')
    $stderr.print "processing dir #{dir}\n"
    Dir.foreach(dir) {|f|
    begin
    next if f=='.' or f=='..'
    fn=dir+'\\'+f
    if File.directory? fn
    fnprocessDir fn
    else
    elsesize=File.size fn
    fnif
    fnif ($files[size]).each{|fn2| # process each segment
    segment if equalFiles? fn,fn2[0]
    fn2 #fn2.replace fn2.push(fn)
    fn fn2<<=fn
    fn break nil
    nil end
    end }
    end $files[size]<<=[fn]
    fnend
    end
    rescue
    $stderr.print "Ooops #{fn}: #$!\n"
    end
    }
    end

    processDir ARGV[0]
    puts '='*60
    $files.sort.each {|h|
    size,arr_size=h
    arr_size.each {|segment|
    if segment.size>1
    print "#{size} -> "
    p segment
    end
    }
    }
    ================================================== ==========

    --
    +-[ Kontra, Gergely<kgergelymcl.hu> PhD student Room IB113 ]---------+
    | [url]http://www.mcl.hu/~kgergely[/url] "Olyan langesz vagyok, hogy |
    | Mobil+36 20) 356 9656 ICQ: 175564914 poroltoval kellene jarnom" |
    +-- Magyar php mirror es magyar php dokumentacio: [url]http://hu.php.net[/url] --+

    KONTRA Gergely Guest

  2. #2

    Default Re: p format - ruby bug? - dumb program?

    Hi,

    At Wed, 13 Aug 2003 03:10:11 +0900,
    KONTRA Gergely wrote:
    > Can I specify how strings are printed, when using the p function?
    > I mean with ' or with " ?
    It is hard coded in String#inspect method, so you have to
    override it.

    class String
    alias __inspect_orig__ inspect
    def inspect
    s = __inspect_orig__()
    s.sub!(/'/, "\\\\'")
    s.sub!(/\\"/, '"')
    s.gsub!(/(\A"|"\z)/, "'")
    end
    end

    --
    Nobu Nakada

    nobu.nokada@softhome.net Guest

  3. #3

    Default Re: p format - ruby bug? - dumb program?

    On 0813, KONTRA Gergely wrote:
    > Hi!
    >
    > Can I specify how strings are printed, when using the p function?
    > I mean with ' or with " ?
    >
    > ---
    > During running a little program, which detects files with the same
    > content, I get a ruby bug:
    [...]
    > processing dir c:\WINDOWS\SYSTEM\Drivers
    > Ooops c:\WINDOWS\SYSTEM\VJOYD.VXD: No such file or directory -
    > c:\WINDOWS\SYSTEM
    > \DirectX\Migrate\vjoyd.vxd
    > same.rb:4: [BUG] rb_sys_fail() - errno == 0
    > ruby 1.8.0 (2003-08-04) [i386-mingw32]
    >
    >
    > abnormal program termination
    code snippet:
    > def equalFiles? fn1, fn2
    > f1=File.open fn1,'r'
    > f2=File.open fn2,'r'
    > while chunk1=f1.read(512)
    > chunk2=f2.read(512)
    > return false if chunk1!=chunk2
    > end
    > return true
    > end
    The problem was: files are opened, but none of them are closed
    explicitly. The ruby output is a bit misleading. Can it be improved?

    Gergo
    --
    +-[ Kontra, Gergely<kgergelymcl.hu> PhD student Room IB113 ]---------+
    | [url]http://www.mcl.hu/~kgergely[/url] "Olyan langesz vagyok, hogy |
    | Mobil+36 20) 356 9656 ICQ: 175564914 poroltoval kellene jarnom" |
    +-- Magyar php mirror es magyar php dokumentacio: [url]http://hu.php.net[/url] --+

    KONTRA Gergely Guest

  4. #4

    Default Re: p format - ruby bug? - dumb program?

    Hi,

    At Thu, 21 Aug 2003 21:09:28 +0900,
    KONTRA Gergely wrote:
    > The problem was: files are opened, but none of them are closed
    > explicitly. The ruby output is a bit misleading. Can it be improved?
    Seems to be due to msvcrt.dll's bug. Usa reported 6.00.8397.0
    has no such problem.

    --
    Nobu Nakada

    nobu.nokada@softhome.net Guest

Similar Threads

  1. unrecognized Client Program format
    By Footer in forum AIX
    Replies: 3
    Last Post: October 1st, 01:47 PM
  2. NIM -unrecognized client program format
    By Peter Brandstätter in forum AIX
    Replies: 3
    Last Post: September 26th, 12:40 PM
  3. [ANN] ruby-freedb, ruby-serialport, ruby-mp3info moved to Rubyforge
    By guillaume.pierronnet@ratp.fr in forum Ruby
    Replies: 0
    Last Post: August 31st, 11:57 PM
  4. Replies: 1
    Last Post: July 24th, 10:58 PM
  5. seeking feedback on my first Ruby program
    By Joe Cheng in forum Ruby
    Replies: 3
    Last Post: July 4th, 05:00 PM

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