Frozen string problem, but I haven't frozen anything?

Discussion in 'Ruby' started by LC Geldenhuys, Feb 17, 2004.

  1. Hi,

    I am new to Ruby. I'm trying to get some Ruby scripts going to manage
    or CVS log message emails. (I haven't written them myself, got them
    from the web.)

    I get:
    /home/cvs/repository/CVSROOT/commitinfo.rb:26:in `tr_s!': can't modify
    frozen string (TypeError)
    from /home/cvs/repository/CVSROOT/commitinfo.rb:26

    I've done some reading, and I suspect I understand what the frozen
    string issue is about. The problem is, I don't see how/why this string
    is frozen? Here is the relevant code snippet:

    -----------------------------------
    if ARGV.size < 4
    puts "Usage: #{$0} CVSROOT USER modulepath file1 [file2...]"
    exit 1 # No way!
    end

    $cvsroot, $cvsuser, $modulepath, *$cvsfiles = *ARGV

    $cvsroot.tr_s!('/', '/')
    $modulepath.tr_s!('/', '/')
    -----------------------------------

    The two lines using 'tr_s!' causes the problem, but I don't see
    how/why $cvsroot or $modulepath is 'frozen'? Might it be due to the
    fact that they are passed to the script, i.e. some global/local scope
    issue?

    Regards,
    Lourens
     
    LC Geldenhuys, Feb 17, 2004
    #1
    1. Advertising

  2. LC Geldenhuys wrote:

    >Hi,
    >
    >I am new to Ruby. I'm trying to get some Ruby scripts going to manage
    >or CVS log message emails. (I haven't written them myself, got them
    >from the web.)
    >
    >I get:
    >/home/cvs/repository/CVSROOT/commitinfo.rb:26:in `tr_s!': can't modify
    >frozen string (TypeError)
    > from /home/cvs/repository/CVSROOT/commitinfo.rb:26
    >
    >I've done some reading, and I suspect I understand what the frozen
    >string issue is about. The problem is, I don't see how/why this string
    >is frozen? Here is the relevant code snippet:
    >
    >-----------------------------------
    >if ARGV.size < 4
    > puts "Usage: #{$0} CVSROOT USER modulepath file1 [file2...]"
    > exit 1 # No way!
    >end
    >
    >$cvsroot, $cvsuser, $modulepath, *$cvsfiles = *ARGV
    >
    >$cvsroot.tr_s!('/', '/')
    >$modulepath.tr_s!('/', '/')
    >-----------------------------------
    >
    >The two lines using 'tr_s!' causes the problem, but I don't see
    >how/why $cvsroot or $modulepath is 'frozen'? Might it be due to the
    >fact that they are passed to the script, i.e. some global/local scope
    >issue?
    >
    >

    you can't modify values in ARGV. you have to copy the values.
     
    Emmanuel Touzery, Feb 17, 2004
    #2
    1. Advertising

  3. On Tue, 17 Feb 2004 18:04:00 +0900, Emmanuel Touzery
    <> wrote:

    >LC Geldenhuys wrote:
    >
    >>Hi,
    >>
    >>I am new to Ruby. I'm trying to get some Ruby scripts going to manage
    >>or CVS log message emails. (I haven't written them myself, got them
    >>from the web.)
    >>
    >>I get:
    >>/home/cvs/repository/CVSROOT/commitinfo.rb:26:in `tr_s!': can't modify
    >>frozen string (TypeError)
    >> from /home/cvs/repository/CVSROOT/commitinfo.rb:26
    >>
    >>I've done some reading, and I suspect I understand what the frozen
    >>string issue is about. The problem is, I don't see how/why this string
    >>is frozen? Here is the relevant code snippet:
    >>
    >>-----------------------------------
    >>if ARGV.size < 4
    >> puts "Usage: #{$0} CVSROOT USER modulepath file1 [file2...]"
    >> exit 1 # No way!
    >>end
    >>
    >>$cvsroot, $cvsuser, $modulepath, *$cvsfiles = *ARGV
    >>
    >>$cvsroot.tr_s!('/', '/')
    >>$modulepath.tr_s!('/', '/')
    >>-----------------------------------
    >>
    >>The two lines using 'tr_s!' causes the problem, but I don't see
    >>how/why $cvsroot or $modulepath is 'frozen'? Might it be due to the
    >>fact that they are passed to the script, i.e. some global/local scope
    >>issue?
    >>
    >>

    >you can't modify values in ARGV. you have to copy the values.
    >
    >


    Thanks, the following now seems to work.

    $cvsroot_in, $cvsuser, $modulepath_in, *$cvsfiles = *ARGV

    $cvsroot = $cvsroot_in.dup
    $modulepath = $modulepath_in.dup

    $cvsroot.tr_s!('/', '/')
    $modulepath.tr_s!('/', '/')

    Cheers,
    Lourens
     
    LC Geldenhuys, Feb 17, 2004
    #3
  4. "LC Geldenhuys" <> schrieb im Newsbeitrag
    news:...
    > On Tue, 17 Feb 2004 18:04:00 +0900, Emmanuel Touzery
    > <> wrote:
    >
    > >LC Geldenhuys wrote:
    > >
    > >>Hi,
    > >>
    > >>I am new to Ruby. I'm trying to get some Ruby scripts going to manage
    > >>or CVS log message emails. (I haven't written them myself, got them
    > >>from the web.)
    > >>
    > >>I get:
    > >>/home/cvs/repository/CVSROOT/commitinfo.rb:26:in `tr_s!': can't modify
    > >>frozen string (TypeError)
    > >> from /home/cvs/repository/CVSROOT/commitinfo.rb:26
    > >>
    > >>I've done some reading, and I suspect I understand what the frozen
    > >>string issue is about. The problem is, I don't see how/why this string
    > >>is frozen? Here is the relevant code snippet:
    > >>
    > >>-----------------------------------
    > >>if ARGV.size < 4
    > >> puts "Usage: #{$0} CVSROOT USER modulepath file1 [file2...]"
    > >> exit 1 # No way!
    > >>end
    > >>
    > >>$cvsroot, $cvsuser, $modulepath, *$cvsfiles = *ARGV
    > >>
    > >>$cvsroot.tr_s!('/', '/')
    > >>$modulepath.tr_s!('/', '/')
    > >>-----------------------------------
    > >>
    > >>The two lines using 'tr_s!' causes the problem, but I don't see
    > >>how/why $cvsroot or $modulepath is 'frozen'? Might it be due to the
    > >>fact that they are passed to the script, i.e. some global/local scope
    > >>issue?
    > >>
    > >>

    > >you can't modify values in ARGV. you have to copy the values.
    > >
    > >

    >
    > Thanks, the following now seems to work.
    >
    > $cvsroot_in, $cvsuser, $modulepath_in, *$cvsfiles = *ARGV
    >
    > $cvsroot = $cvsroot_in.dup
    > $modulepath = $modulepath_in.dup
    >
    > $cvsroot.tr_s!('/', '/')
    > $modulepath.tr_s!('/', '/')


    Why don't you just do

    $cvsroot_in, $cvsuser, $modulepath_in, *$cvsfiles = *ARGV

    $cvsroot.tr_s('/', '/')
    $modulepath.tr_s('/', '/')

    ? And, why do you use global variables at all?

    Regards

    robert
     
    Robert Klemme, Feb 17, 2004
    #4
  5. LC Geldenhuys

    Mark Hubbart Guest

    On Feb 17, 2004, at 6:14 AM, Robert Klemme wrote:

    > Why don't you just do
    >
    > $cvsroot_in, $cvsuser, $modulepath_in, *$cvsfiles = *ARGV
    >
    > $cvsroot.tr_s('/', '/')
    > $modulepath.tr_s('/', '/')


    You probably meant:
    $cvsroot = $cvsroot_in.tr_s('/', '/')
    $modulepath = $modulepath_in.tr_s('/', '/')

    but how about:
    $cvsroot, $cvsuser, $modulepath, *$cvsfiles = *ARGV.map{|a|a.dup}

    this unfreezes everything automagically.

    Cheers,
    Mark
     
    Mark Hubbart, Feb 17, 2004
    #5
  6. "Mark Hubbart" <> schrieb im Newsbeitrag
    news:...
    >
    > On Feb 17, 2004, at 6:14 AM, Robert Klemme wrote:
    >
    > > Why don't you just do
    > >
    > > $cvsroot_in, $cvsuser, $modulepath_in, *$cvsfiles = *ARGV
    > >
    > > $cvsroot.tr_s('/', '/')
    > > $modulepath.tr_s('/', '/')

    >
    > You probably meant:
    > $cvsroot = $cvsroot_in.tr_s('/', '/')
    > $modulepath = $modulepath_in.tr_s('/', '/')


    Yes. Thanks for correcting that.

    > but how about:
    > $cvsroot, $cvsuser, $modulepath, *$cvsfiles = *ARGV.map{|a|a.dup}
    >
    > this unfreezes everything automagically.


    As always there are tons of ways to do things with Ruby. Which is good.
    :)

    Regards

    robert
     
    Robert Klemme, Feb 18, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Miki Tebeka
    Replies:
    2
    Views:
    313
    Derrick 'dman' Hudson
    Nov 6, 2003
  2. Elbert Delaney

    long time we haven't spoken ;)

    Elbert Delaney, Apr 20, 2005, in forum: Python
    Replies:
    0
    Views:
    333
    Elbert Delaney
    Apr 20, 2005
  3. est
    Replies:
    1
    Views:
    596
  4. paul
    Replies:
    0
    Views:
    321
  5. LAMBEAU Bernard
    Replies:
    1
    Views:
    130
    Markus Schirp
    Jan 8, 2009
Loading...

Share This Page