Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Feb 032009
 

Remove newline character from the end of a string in Perl

Answer:

chomp() is useful when reading data from a file or from a user - it remove remove any newline character from the end of a string.

E.g.

while (my $text = ) {
    chomp($text);
    print "You entered '$text'\n"; # newline from input is removed
}

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>