Following is my code:
md5 = Digest::MD5.new
md5 << "!@#$"
Then comes the error:
SyntaxError: (irb):46: unterminated string meets end of file
What is wrong? And how can I calculate the md5 hash of the string "!@#$"
?
Following is my code:
md5 = Digest::MD5.new
md5 << "!@#$"
Then comes the error:
SyntaxError: (irb):46: unterminated string meets end of file
What is wrong? And how can I calculate the md5 hash of the string "!@#$"
?
The hash #
sign in double quoted strings is used for variable and expression substitution. In this case, you are substituting the value of the global variable $"
into the string, but you are not closing the string. The syntactically correct way of expressing that would be
"!@#$"" # Note the extra closing quotes
However, it seems that you actually don't want to do variable substitution anyway, in which case you should always use single quoted strings:
'!@#$'
Your problem is the string you got is in a double apostrophe (") - so it is interpreted. And you have a hash (#) inside, so it is trying to do expression substitution. Put the string in a single apostrophe:
md5 << '!@#$'