"\!" appears on new line

A

April

print $wholething, $wholething2, "\!", "\n";

Thank you
!

How can I get them on the same line?
 
L

Leon Timmermans

print $wholething, $wholething2, "\!", "\n";

Thank you
!

How can I get them on the same line?

It prints on one line for me. Though I do wonder very much why you are
escaping the exclamation point.

Leon Timmermans
 
A

April

I tried sevral ways ... then it could be a bug? I'm using v5.8.8
built for MSWin32-x86-multi-thread (ActivePerl).

Just doing some exercises, thanks for your prompt response Leon!
 
P

Peter Makholm

April said:
print $wholething, $wholething2, "\!", "\n";

Thank you
!

How can I get them on the same line?

My guess is that $wholething2 have a newline at the end. Remove that
and it should work as you want it to.

//Makholm
 
A

April

here is a variation of the whole script, but does the same:

print "Enter a phrase and convert the first letter to upper case and
add a ! at end: ";
my $input = <STDIN>;
my $firststinput = uc( substr($input, 0, 1) );
print $firststinput, substr($input, 1), "\!", "\n";

does substr change to a new line?
 
P

Peter Makholm

April said:
print "Enter a phrase and convert the first letter to upper case and
add a ! at end: ";
my $input = <STDIN>;

Here you string will have an newline at the end. You'll have to chomp it.
my $firststinput = uc( substr($input, 0, 1) );
print $firststinput, substr($input, 1), "\!", "\n";

Uhmmm, and use ucfirst if that is what you need to do.

//Makholm
 
A

April

thanks, however after the recommended change the script hangs
forllowing keyboard entry:

#! c:\perl
print "Enter a phrase and convert the first letter to upper case and
add a ! at end: ";
my $input = <STDIN>;
chomp( $input = <STDIN> );
my $firststinput = ucfirst($input);
print $firststinput, substr($input, 1), "\!", "\n";


C:\Perl\Exercise1>perl new3-6d.pl
Enter a phrase and convert the first letter to upper case and add a !
at end: thank you
 
A

April

this one finally worked! thanks you two!

#! c:\perl
my $input;
print "Enter a phrase and convert the first letter to upper case and
add a ! at end: ";
chomp( $input = <STDIN> );
my $firststinput = ucfirst( $input );
print $firststinput, "\!", "\n";
 
A

April

this is more concise:

print "Enter a phrase and convert the first letter to upper case and
add a ! at end: ";
chomp( my $input = <STDIN> );
print ucfirst( $input ), "\!", "\n";
 
J

John W. Krahn

April said:
this is more concise:

print "Enter a phrase and convert the first letter to upper case and
add a ! at end: ";
chomp( my $input = <STDIN> );
print ucfirst( $input ), "\!", "\n";

TIMTOWTDI:

print "Enter a phrase and convert the first letter to upper case and add
a ! at end: ";
( my $input = <STDIN> ) =~ s/$/!/;
print "\u$input";



John
 
S

sln

TIMTOWTDI:

print "Enter a phrase and convert the first letter to upper case and add
a ! at end: ";
( my $input = <STDIN> ) =~ s/$/!/;
print "\u$input";



John

Whoa, this is a wild weazle..

sln
 
A

April

TIMTOWTDI:

print "Enter a phrase and convert the first letter to upper case and add
a ! at end: ";
( my $input = <STDIN> ) =~ s/$/!/;
print "\u$input";

John

wow thanks John!
 
T

Tim Greer

April said:
print $wholething, $wholething2, "\!", "\n";

Thank you
!

How can I get them on the same line?

I assume that the $wholething2 variable has a new line in it, because it
should work. Why are you escaping \ the ! character? Are you running
this on the command line or something?
 
T

Tim Greer

Tim said:
I assume that the $wholething2 variable has a new line in it, because
it
should work. Why are you escaping \ the ! character? Are you running
this on the command line or something?

Disregard my reply, I didn't see your follow up posts until after I had
replied. Looks like you understand the issue now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top