ok, so i’m trying to create a here doc for a little program i’m writing
and
it dosn’t seem to want to work right!
this code works:
pry(main)> print <<NUMS
pry(main)* 08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
pry(main)* 49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
pry(main)* NUMS
08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
=> nil
but this:
pry(main)> str = ‘’
=> “”
pry(main)> str <<NUMS
pry(main)* 08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
pry(main)* 49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
pry(main)* NUMS
gives me:
SyntaxError: (pry):43: Invalid octal digit
08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
^
(pry):43: syntax error, unexpected tINTEGER, expecting $end
08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
^
from
/home/serialhex/.rvm/gems/ruby-1.9.2-p180/gems/pry-0.9.1/lib/pry/pry_instance.rb:226:in
`eval’
so why can i ‘print’ a here doc, but not set it to a variable??? or am
i
doing something stupid wrong that i dont know what i’m doing with the
stupid
and the wrongness?? (sorry, i think i need to catch up on some sleep
too)
any help is appreciated
hex
–
my blog is cooler than yours: serialhex.github.com http://goo.gl/7s4yU
Other than the fact Linux has a cool name, could someone explain why I
should use Linux over BSD?
No. That’s it. The cool name, that is. We worked very hard on
creating a name that would appeal to the majority of people, and it
certainly paid off: thousands of people are using linux just to be able
to say “OS/2? Hah. I’ve got Linux. What a cool name”. 386BSD made the
mistake of putting a lot of numbers and weird abbreviations into the
name, and is scaring away a lot of people just because it sounds too
technical.
– Linus Torvalds’ follow-up to a question about Linux
On Tue, Jun 28, 2011 at 11:17 PM, serialhex [email protected] wrote:
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
pry(main)* NUMS
from
any help is appreciated
hex
Try this:
irb(main):001:0> st = “”
=> “”
irb(main):002:0> st << <<NUMS
irb(main):003:0" 08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77
91 08
irb(main):004:0" NUMS
=> “08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08\n”
irb(main):005:0>
thanks J-H!! that works BEAUTIFULLY!!! (though why that works and the
other doesn’t is a mystery to me, seems like it violates the principle
of
least surprise)
hex
On Tue, Jun 28, 2011 at 5:27 PM, J-H Johansen [email protected]
wrote:
pry(main)* 49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
pry(main)> str <<NUMS
(pry):43: syntax error, unexpected tINTEGER, expecting $end
doing something stupid wrong that i dont know what i’m doing with the
irb(main):001:0> st = “”
certainly paid off: thousands of people are using linux just to be able
–
Jens-Harald Johansen
–
There are 10 kinds of people in the world: Those who understand binary and
those who don’t…
–
my blog is cooler than yours: serialhex.github.com
Other than the fact Linux has a cool name, could someone explain why I
should use Linux over BSD?
No. That’s it. The cool name, that is. We worked very hard on
creating a name that would appeal to the majority of people, and it
certainly paid off: thousands of people are using linux just to be able
to say “OS/2? Hah. I’ve got Linux. What a cool name”. 386BSD made the
mistake of putting a lot of numbers and weird abbreviations into the
name, and is scaring away a lot of people just because it sounds too
technical.
– Linus Torvalds’ follow-up to a question about Linux
On Jun 28, 2011, at 2:17 PM, serialhex wrote:
pry(main)> str <<NUMS
str << <<NUMS
NUMS
<<NUMS\n\nNUMS is a here-document, it does not invoke the #<< method
On Tue, Jun 28, 2011 at 4:17 PM, serialhex [email protected] wrote:
this code works:
pry(main)> print <<NUMS
but this:
pry(main)> str = ‘’
pry(main)> str <<NUMS
gives me:
SyntaxError: (pry):43: Invalid octal digit
In the first case, puts is a method. In the second, str is a variable.
You
can pass arguments to methods, which is what you do. You cannot pass
arguments to variables. The <<
in <<NUMS
is not an operator, it is
part
of the here document syntax (I take it to mean “put the string here,
where
I’m pointing to”) so it expands to str "..."
which is more obviously
incorrect.
If you’re trying to append to the string, then it should be str << <<NUMS
if you’re trying to assign it to the string, then it should be str = <<NUMS
On Tue, Jun 28, 2011 at 5:38 PM, Josh C. [email protected]
wrote:
If you’re trying to append to the string, then it should be str << <<NUMS
if you’re trying to assign it to the string, then it should be str = <<NUMS
ahh, ok, this explains things a lot better! i thought it was a method
or
some such, also it makes more sense for me to str = <<NUMS ...
than
str = ''; str <<NUMS...
thank you!
hex
–
my blog is cooler than yours: serialhex.github.com
Other than the fact Linux has a cool name, could someone explain why I
should use Linux over BSD?
No. That’s it. The cool name, that is. We worked very hard on
creating a name that would appeal to the majority of people, and it
certainly paid off: thousands of people are using linux just to be able
to say “OS/2? Hah. I’ve got Linux. What a cool name”. 386BSD made the
mistake of putting a lot of numbers and weird abbreviations into the
name, and is scaring away a lot of people just because it sounds too
technical.
– Linus Torvalds’ follow-up to a question about Linux