0

I'm trying to print each values in a line separately. I want the TCP, ports and CIDR to be printed as array values.

sg_rules="TCP,80,80,0.0.0.0/0
TCP,8080,8080,0.0.0.0/0"


sg_rules.each_line  do |rule|
    rule.split(',')
    print rule[0]
end

But I'm getting the following output. I expected TCP as the result.

Output:

$ruby main.rb
TT

1 Answer 1

2

When you call 'split' that returns an array but does not actually store the result in rule variable...

Try this:

sg_rules.each_line  do |rule|
  print rule.split(',').first
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.