Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > "\!" appears on new line

Reply
Thread Tools

"\!" appears on new line

 
 
April
Guest
Posts: n/a
 
      10-10-2008
print $wholething, $wholething2, "\!", "\n";

Thank you
!

How can I get them on the same line?
 
Reply With Quote
 
 
 
 
Leon Timmermans
Guest
Posts: n/a
 
      10-10-2008
On Fri, 10 Oct 2008 06:07:31 -0700, April wrote:

> 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
 
Reply With Quote
 
 
 
 
April
Guest
Posts: n/a
 
      10-10-2008

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!

On Oct 10, 9:12*am, Leon Timmermans <faw...@gmail.com> wrote:
> On Fri, 10 Oct 2008 06:07:31 -0700, April wrote:
> > 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


 
Reply With Quote
 
Peter Makholm
Guest
Posts: n/a
 
      10-10-2008
April <> writes:

> 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
 
Reply With Quote
 
April
Guest
Posts: n/a
 
      10-10-2008
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?


On Oct 10, 9:22*am, Peter Makholm <pe...@makholm.net> wrote:
> April <xiaoxia20...@yahoo.com> writes:
> > 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


 
Reply With Quote
 
Peter Makholm
Guest
Posts: n/a
 
      10-10-2008
April <> writes:

> 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
 
Reply With Quote
 
April
Guest
Posts: n/a
 
      10-10-2008
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





On Oct 10, 9:42*am, Peter Makholm <pe...@makholm.net> wrote:
> April <xiaoxia20...@yahoo.com> writes:
> > 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


 
Reply With Quote
 
April
Guest
Posts: n/a
 
      10-10-2008
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";


On Oct 10, 9:53*am, April <xiaoxia20...@yahoo.com> wrote:
> 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
>
> On Oct 10, 9:42*am, Peter Makholm <pe...@makholm.net> wrote:
>
>
>
> > April <xiaoxia20...@yahoo.com> writes:
> > > 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- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
April
Guest
Posts: n/a
 
      10-10-2008
On Oct 10, 10:10*am, Scott Bryce <sbr...@scottbryce.com> wrote:
> April wrote:
> > thanks, however after the recommended change the script hangs
> > following keyboard entry:

>
> That is because you are asking for another keyboard input.
>
> > #! 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> );

>
> chomp $input;


you are correct Scott, input & chomp, thanks!
 
Reply With Quote
 
Tad J McClellan
Guest
Posts: n/a
 
      10-10-2008
April <> wrote:

> print $firststinput, "\!", "\n";



That is the same as

print "$firststinput!\n";

only easier to read and maintain.


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
counting how often the same word appears in a txt file...But my codeonly prints the last line entry in the txt file dgcosgrave@gmail.com Python 8 12-19-2012 06:29 PM
Value isn't appended in puts statement(appears on next line) Mrmaster Mrmaster Ruby 9 09-19-2009 06:35 AM
How to read a text file line by line and remove some line kaushikshome C++ 4 09-10-2006 10:12 PM
Read a file line by line with a maximum number of characters per line Hugo Java 10 10-18-2004 11:42 AM
thin verticle white line appears on printed picture Brian Digital Photography 6 10-11-2004 02:31 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57