Questions tagged [chomp]

a function in Perl/Ruby to remove newline at the end of a string,

60 questions
1
vote
3 answers

Chomp changes my string to 1

In my code I assign a variable disc to equal the result of an command disc on my linux system. This outputs the string RESEARCH my $disc = `disc`; print "$disc\n"; $disc = chomp($disc); print "$disc\n"; However when I use chomp to strip the newline…
moadeep
  • 3,988
  • 10
  • 45
  • 72
1
vote
1 answer

perl large IO bug on Mac but not Windows or Linux (adds newline can't be chomped)

I've tested my program on a dozen Windows machines, a half dozen Macs, and a Linux machine and it works without error on both the Windows and Linux but not the Macs. My program is designed to work with protein database files which are text files…
Dave D
  • 35
  • 6
0
votes
1 answer

using gets.chomp twice in a one line call to a nested hashmap - ruby

what is the best way of using gets.chop for the following example? user = {} user["list"] = [ {gets.chomp => {gets.chomp.delete(' ') => rand(1000000000000)} } ] I can think of: a = gets.chop ; b = a.delete(' ') ; user["list"] = [ {a => {b =>…
beoliver
  • 5,579
  • 5
  • 36
  • 72
0
votes
2 answers

In perl, how to split a string in this desired way?

I have a string str a\tb\tc\td\te I want the 1st field value a to go in a variable, then 2nd field value b to go in other variable, then both c\td to go in 3rd variable and last field value e to go in one variable. If I do my ($a,$b,$c,$d) =…
xyz
  • 8,607
  • 16
  • 66
  • 90
0
votes
1 answer

Passing multiple STDIN inputs from powershell script into perl script

I have an existing perl script (which i cannot modify) which has two STDIN calls. I would like to run this perl script from a powershell script and feed it the two "user inputs" but using variables. For a single input I tried 'input' | perl…
tommy
  • 11
  • 3
0
votes
1 answer

Code never enter any of the if statements

begin selected_option = gets.chomp if selected_option == 1 puts "Welcome to the Welcome Screen!" elsif selected_option == 2 puts "This is the options menu." elsif selected_option == 3 puts "Logging out. Goodbye!" else puts…
delete
0
votes
1 answer

Perl chomp plus =~s Yielding very strange results

I am writing a perl program which creates a procmailrc text file. The output procmail requires looks like this: (partial IP addresses separated by "|") \(\[54\.245\.|\(\[54\.252\.|\(\[60\.177\.| Here is my perl script: open (DEAD, "$dead"); @dead =…
Konabob
  • 9
  • 4
0
votes
3 answers

Use of chomp in this Perl script

I am trying to learn Perl here and the tutorial suggests the following code snippet after reading some file: my $team_number = 42; my $filename = 'input.txt'; open(my $fh, '<', $filename) or die "cannot open '$filename' $!"; my…
Bram Vanroy
  • 27,032
  • 24
  • 137
  • 239
0
votes
1 answer

Connecting rows in Perl after filter

I want ask you for some tips. My code looks like next few rows: #!/usr/bin/env perl while () { if (/\bSTART\b/ .. /\bEND\b/) { #$together = $_; #$together = chomp ($_); print ($_, "\n"); } } __DATA__ rubish rub START Data…
0
votes
0 answers

sublime text can't compile gets.chomp

I'm learning ruby on sublime text 2, however it seems that sublime text cannot understand user input method. when I typed puts "Enter your first name: " first_name = gets.chomp sublime text return this error: in `
': undefined method `chomp'…
KhoaVo
  • 376
  • 3
  • 18
0
votes
1 answer

Selecting items up and to the right of the item clicked in a panel in java

So I am working on a game of Chomp. Where you have a grid of "cookies" and a "poison cookie" in the bottom left corner. When a player selects a cookie, all the cookies up and to the right of that cookie are eaten. Right now, my program selects all…
Greg Taylor
  • 21
  • 1
  • 7
0
votes
1 answer

Ruby - command exit error

I'm completely new to programming and im having trouble figuring out why Im getting an error when typing the following: puts "What is your favorite number?" number = gets.chomp number = number.to_i + 1 puts "I suggest " + number.to_s + " as a…
Krisha
  • 1
0
votes
1 answer

NoMethodError using gets.chomp in Ruby

Can anyone help me with this simple exercise? class Item def percents() self * 100 end end answer = gets.chomp puts answer.percents() The result is: percents.rb:7:in `
': undefined method `percents' for "300":String (NoMethodError)
0
votes
3 answers

Difference between ways to use gets method

I saw two ways to use gets, a simple form: print 'Insert your name: ' name = gets() puts "Your name is #{name}" and a form that drew my attention: print 'Insert your name: ' STDOUT.flush name = gets.chomp puts "Your name is #{name}" The second…
Leandro Arruda
  • 466
  • 6
  • 16
0
votes
4 answers

Perl weird chomp and newline

I'm having weird things when extracting line from file. Lines are coming from SSH commands sent on a router and saved into a file. They are looking like : saved_commands FastEthernet0 is up, line protocol is up Helper address is not set …
Gui O
  • 363
  • 4
  • 8
  • 22