Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Frozen string problem, but I haven't frozen anything?

Reply
Thread Tools

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

 
 
LC Geldenhuys
Guest
Posts: n/a
 
      02-17-2004
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

 
Reply With Quote
 
 
 
 
Emmanuel Touzery
Guest
Posts: n/a
 
      02-17-2004
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.



 
Reply With Quote
 
 
 
 
LC Geldenhuys
Guest
Posts: n/a
 
      02-17-2004
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

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      02-17-2004

"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

 
Reply With Quote
 
Mark Hubbart
Guest
Posts: n/a
 
      02-17-2004

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



 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      02-18-2004

"Mark Hubbart" <> schrieb im Newsbeitrag
news:3AA77270-6182-11D8-B680-...
>
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling xpython: No rule to make target `runathana.py', needed by `frozen/frozen.c'. est Python 1 10-11-2010 03:35 AM
frozen string David Coffield Ruby 2 05-27-2009 03:21 PM
How to return an unmodifiable but nor frozen array? LAMBEAU Bernard Ruby 1 01-08-2009 02:04 PM
`concat': can't modify frozen string in benchmark.rb Peņa, Botp Ruby 2 05-31-2007 02:29 AM
"unknown encoding: string-escape" in frozen Python Jeff Groves Python 0 03-03-2007 01:27 AM



Advertisments
 



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