Ok. I have a major pattern matching problem. In essence, right now
the word i am trying to match is “hello”, WITH double quotes around it.
Why isn’t this working? It always hits the else part of my case-when
loop.
write_file = open(‘albuminfo.txt’, ‘w’)
lines.each do |line|
puts line
case line
when line =~ /^(.+)$/
write_file.puts(’"#{$1}"’)
write_file.close
print ‘.’
else
print ‘$’
end
end
It doesn’t want to match!
Please don’t let me drown,
---------------------------------------------------------------|
~Ari
“I don’t suffer from insanity. I enjoy every minute of it” --1337est
man alive
case line
when line =~ /^(.+)$/
write_file.puts(’"#{$1}"’)
write_file.close
print ‘.’
else
print ‘$’
end
end
Others have pointed out a problem with your case statement, but I
think there’s another problem here – your #{$1} substitution isn’t
going to work in single-quoted string.
Others have pointed out a problem with your case statement, but I
think there’s another problem here – your #{$1} substitution isn’t
going to work in single-quoted string.
You’re serious? I can’t use variable substitution in a single quoted
string? I ran into that a while ago, but i just thought it was some
glitch on my part!
Why is that so? Whats the difference between single and double quoted
strings?
Thanks
-------------------------------------------------------|
~ Ari
crap my sig won’t fit
Am Freitag, 06. Jul 2007, 12:27:40 +0900 schrieb Morton G.:
On Jul 5, 2007, at 8:50 PM, Ari B. wrote:
when line =~ /^(.+)$/
write_file.puts(’"#{$1}"’)
Others have pointed out a problem with your case statement, but I
think there’s another problem here – your #{$1} substitution isn’t
going to work in single-quoted string.
Further, the grouping is superfluous.
when /^.+$/ then
do_sth_with $&
will do.
As `line’ will alwas contain a single newline character at
the strings end and as /./ will never match that, even