ruby Unexpected keyword else error [closed] - ruby

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I have this ruby program to parse a CSV file. I am missing a endif somewhere and I cannot figure out.
require 'csv'
prevrow=nil
newarray=Array.new
CSV.foreach("\\\\192.168.0.1\\fe18cb0618cabd41\\ninjatrader\\uniqueside.csv", col_sep: ',') do |row|
if(prevrow==nil)
# do nothing
newarray<<row
prevrow=row
elsif (prevrow!=nil and row[0]!=prevrow[0] )
# do something
newarray<<row
prevrow=row
##count=1
elsif(prevrow!=nil and row[0]=prevrow[0] and ##count<4)
puts "new date"
newarray<<row
prevrow=row
##count++
end
end
removesamedirctiontop4.rb:23: syntax error, unexpected keyword_else
removesamedirctiontop4.rb:27: syntax error, unexpected end-of-input, expecting keyword_end

#count++ is not valid ruby. The final "plus" is expecting another parameter and thinks it's on the next line, so the line ends up being interpreted as...
`#count + +end`
So you have an invalid statement and you lose an end.
Change the offending line to
#count += 1

Related

raku: Support for utf8-c8 issue in Raku 2020.10 [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I have a file from Wild Wild Web and it contains malformed UTF8. I handled malformed UTF8 in my other codes in previous versions of Raku. In 2020.10 version, I am running into this issue below. Has the support for utf8-c8 changed (this page says it should work, but it doesn't seem to) :
https://docs.raku.org/language/unicode#index-entry-UTF-8_Clean-8
This page has this example:
say slurp($test-file, enc => 'utf8-c8');
Now my code on the command line:
raku -e 'my $a = slurp("zlist"); for $a.lines { .say }'
Malformed UTF-8 near bytes 73 e2 5f at line 55 col 14
in block <unit> at -e line 1
Then using this:
raku -e 'my $a = slurp("zlist", enc => 'utf8-c8'); for $a.lines { .say }'
===SORRY!=== Error while compiling -e
Undeclared routine:
utf8-c8 used at line 1
My code is simple and essentially copied from the example. What am I doing wrong?

Bash string literal comparison to variable failing [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I have the following simple bash code to test string comparison:
#!/bin/sh
BRANCH="master"
echo $ref
if [[ "$ref" = "refs/heads/$BRANCH" ]]
then
echo "Matches"
else
echo "Do not match"
fi
When I ran the code using export ref=/refs/heads/master && . sample I get the following result:
/refs/heads/master
Do not match
What may be causing the problem?
What is causing the problem is the missing slash in your test: /refs/heads/master is not equal to refs/heads/master!

Unable to find the reason for this: bash missing' [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
why am I getting "bash missing'" for this:
function get_xserver ()
{
case $TERM in
xterm )
XSERVER=$(who am i | awk '{print $NF}' | tr -d ')''(' )
;;
aterm | rxvt)
# Find some code that works here. ...
;;
esac
}
This is the exact error:
bash: [: missing `]'
The error is not in the code you posted. The error message:
-bash: [: missing `]'
Means exactly what it says - there is a missing ] character, namely in a [ test ] statement.
Try it:
$ [ 1 -eq 2
-bash: [: missing `]'
You need to identify where the error actually is, and add the missing closing bracket.

find and replace percent symbol within string with back slash in ruby? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I tried this :
irb(main):125:0> a = "ab%c"
=> "ab%c"
irb(main):126:0> a.gsub("%", '\\')
=> "ab\\c"
irb(main):127:0>
whereas expected output is:
ab\c
it did not work.
Thanks in advance.
Update: ruby version
ruby -v
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
a = "ab%c"
a.gsub!("%", '\\')
#=> "ab\\c"
puts a
# ab\c
in "ab\\c" backslash \ is being escaped using character \.
you can verify this with puts

Append to variable within shell script loop [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm trying to loop over all environment variables in a shell script, and create an HTML query string from ones which match a pattern. Unfortunately, I can't seem to assign to variables in the loop. I've got this:
#!/bin/sh
IFS=$'\n'
TAGS=""
for item in $(printenv)
do
if [[ $item == FOO_TAG_* ]]
then
TAGS = "${TAGS}&${item}"
fi
done
But this gives me
/etc/script.sh: line 9: TAGS: command not found
/etc/script.sh: line 9: TAGS: command not found
How do I fix this?
In the assignment, remove space between variable name and =
TAGS="${TAGS}${item}"

Resources