perl - Why isn't this concatenating as expected? -
i'm trying lean perl , doing few simple exercises myself used it.
one of exercises manipulating strings , i've written below.
#!/usr/bin/perl use strict; print "please enter text..\n"; $string =<stdin>; $string_reverse = reverse $string; print "reversed: $string_reverse\n"; $string_length = length $string; print "length: $string_length\n"; $string_upper = uc $string; print "uppercase: $string_upper\n"; $string_lower = lc $string; print "lowercase: $string_lower\n"; print "enter second bit of text\n"; $second_string = <stdin>; print $string . $second_string;
this produces following output.
please enter text.. test reversed: tset length: 5 uppercase: test lowercase: test enter second bit of text 123 test 123
i expected concatenated text shown as:
test123
why showing instead on new line every time?
my $string =<stdin>;
reads in string, including newline.
try using chomp
trim newline off.
Comments
Post a Comment