Questions tagged [chomp]

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

60 questions
0
votes
1 answer

Lines are not getting printed after application of chomp in perl

#!/usr/bin/perl use warnings; use Switch; while (<>) { next if /^\s*\/\//; next if /^\s*$/; my $line="$_"; chomp($line); print $line; print "Checking for line:\n$line"; } This is my code which takes input file from command line. It…
sarthak
  • 774
  • 1
  • 11
  • 27
0
votes
1 answer

Ruby--How to get input from server without error? (socket.gets.chomp throwing error)

I'm running a server/client program, I keep getting an error I don't understand: FishClientRun.rb:18:in `
': undefined method `chomp' for nil:NilClass (NoMethodError) Shizuo:FISHGAME2 macowner$ However, the code runs once. It actually…
Yallo
  • 51
  • 2
  • 9
0
votes
2 answers

How do I remove the special character at the end?

I have the following code in my program, which aims to return the version and subversion of Debian installed. The output from shell is read by the variables and parsed and a string formed. #!/usr/bin/perl use warnings; use strict; use Scalar::Util…
Joel G Mathew
  • 7,561
  • 15
  • 54
  • 86
0
votes
1 answer

How do i delete any characters from an array in rails?

I have an array list of email address and i want to delete eveything after the ";" i tried chomp. but that didnt seem to work. How would i loop through the array and remove everything after the ";" in my view.
Fresh
  • 757
  • 1
  • 7
  • 18
0
votes
3 answers

Rails chomp method not working

I have the following line of code in my model method. subjectsinlist='[' subjectlist.subjects.each do |subject| subjectsinlist=subjectsinlist+subject.subject_code+', ' end subjectsinlist.chomp(', ') subjectsinlist+="]" An example of the…
Butter Beer
  • 1,100
  • 3
  • 16
  • 32
0
votes
2 answers

How to receive data from user without ruby adding an extra newline

I am trying to create a program that alphabetizes a users' word entries. However, inspection of the users entries reveals that ruby is for some reason adding a newline character to each word. For instance, If i enter Dog, Cat, Rabbit the program…
Bodhidarma
  • 519
  • 1
  • 7
  • 25
0
votes
2 answers

Unchomping a file, then appending a string

I have a text file with path name file, and some content string that I want to append to it. I want to do something close to File.open(file, "a"){|io| io.puts(string)} but if the original content of the file does not end with an endline character…
sawa
  • 165,429
  • 45
  • 277
  • 381
0
votes
3 answers

Perl+Selenium: chomp() fails

I'm using Selenium for work and I have extract some data from "//ul", unfortunately this data contains a newline, I tried to use chomp() function to remove this (because I need to write in a CSV's file) but it's not working, the portion of code…
fdicarlo
  • 450
  • 1
  • 5
  • 10
-1
votes
3 answers

Chomping inside an array

puts (Array.new(200) {(1..100).to_a[rand(100)]}).group_by { |x| (x - 1) / 10 }.sort_by { |x| x }.map {|x, y| [10 * x + 1, "-" , 10 * (x + 1), " ", "|", " ", "*" * (y.length)]} In the above code, I need to chomp after each comma in the map block.…
-1
votes
2 answers

How do I use correctly chomp command to get rid of \n character in perl?

my question is very simple: i have a database that is looking like this: My goal is just to eliminate the newline \n at the end of every sequence line, NOT OF THE HEADER, i tried the following code #!/usr/bin/perl use strict; my $db = shift; my…
-1
votes
1 answer

Need something like open OR DIE except with chomp

I'm fairly new to coding and I need a fail statement to print out as if it were an or die. Part of my code for an example: print "Please enter the name of the file to search:"; chomp (my $filename=) or die "No such file exists.…
distro
  • 41
  • 5
-1
votes
3 answers

Difference between chomp and trim in Perl?

What is the difference between chomp and trim in Perl? Which one is better to use and when?
Sam 333
  • 61
  • 2
  • 8
-1
votes
4 answers

how to read all file names from a given directory using perl?

friends i 've this code which read file name from a directory and print those names opendir DIR1, "defaults" or die "cannot open dir: $!";#open the given dir my @default_files=readdir DIR1; foreach my $fls(@default_files){ …
Thiyagu ATR
  • 2,224
  • 7
  • 30
  • 44
-2
votes
1 answer

Perl chomp function not working properly

i have a file which contains something like this name: A id: B cl: C name: D id: E cl: F name: I id: G cl: K i am grep the contents after cl: and storing it in an array #!/usr/bin/perl @success=qw(C J K L); …
user3095218
  • 39
  • 1
  • 9
-3
votes
2 answers

changing a variable using gets.chomp()

im trying to write to a file using this code: puts "-------------------- TEXT-EDITOR --------------------" def tor(old_text) old_text = gets.chomp # end $epic="" def torr(input) tore= $epic += input + ", " File.open("tor.txt", "w") do…
TorB
  • 9
  • 3
1 2 3
4