"\!" appears on new line

Discussion in 'Perl Misc' started by April, Oct 10, 2008.

  1. April

    April Guest

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

    Thank you
    !

    How can I get them on the same line?
     
    April, Oct 10, 2008
    #1
    1. Advertising

  2. 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
     
    Leon Timmermans, Oct 10, 2008
    #2
    1. Advertising

  3. April

    April Guest

    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 <> 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
     
    April, Oct 10, 2008
    #3
  4. 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
     
    Peter Makholm, Oct 10, 2008
    #4
  5. April

    April Guest

    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 <> wrote:
    > 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
     
    April, Oct 10, 2008
    #5
  6. 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
     
    Peter Makholm, Oct 10, 2008
    #6
  7. April

    April Guest

    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 <> wrote:
    > 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
     
    April, Oct 10, 2008
    #7
  8. April

    April Guest

    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 <> 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 <> wrote:
    >
    >
    >
    > > 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- Hide quoted text -

    >
    > - Show quoted text -
     
    April, Oct 10, 2008
    #8
  9. April

    April Guest

    On Oct 10, 10:10 am, Scott Bryce <> 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!
     
    April, Oct 10, 2008
    #9
  10. 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/"
     
    Tad J McClellan, Oct 10, 2008
    #10
  11. April

    April Guest

    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";

    On Oct 10, 10:13 am, April <> wrote:
    > 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 <> 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 <> wrote:

    >
    > > > 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 chompit.

    >
    > > > > 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 -- Hide quoted text -

    >
    > - Show quoted text -
     
    April, Oct 10, 2008
    #11
  12. April wrote:
    > 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
    --
    Perl isn't a toolbox, but a small machine shop where you
    can special-order certain sorts of tools at low cost and
    in short order. -- Larry Wall
     
    John W. Krahn, Oct 10, 2008
    #12
  13. April

    Guest

    On Fri, 10 Oct 2008 12:31:34 -0700, "John W. Krahn" <> wrote:

    >April wrote:
    >> 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


    Whoa, this is a wild weazle..

    sln
     
    , Oct 10, 2008
    #13
  14. April

    April Guest

    On Oct 10, 3:31 pm, "John W. Krahn" <> wrote:
    > April wrote:
    > > 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
    > --
    > Perl isn't a toolbox, but a small machine shop where you
    > can special-order certain sorts of tools at low cost and
    > in short order.                            --Larry Wall


    wow thanks John!
     
    April, Oct 11, 2008
    #14
  15. April

    Guest

    On Fri, 10 Oct 2008 21:19:47 -0700 (PDT), April <> wrote:

    >On Oct 10, 3:31 pm, "John W. Krahn" <> wrote:
    >> April wrote:
    >> > 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
    >> --
    >> Perl isn't a toolbox, but a small machine shop where you
    >> can special-order certain sorts of tools at low cost and
    >> in short order.                            -- Larry Wall

    >
    >wow thanks John!


    wOW, ITS ALL liKE garbaNZO beans...

    sln
     
    , Oct 11, 2008
    #15
  16. April

    Tim Greer Guest

    April wrote:

    > 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?
    --
    Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
    Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
    and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
    Industry's most experienced staff! -- Web Hosting With Muscle!
     
    Tim Greer, Oct 14, 2008
    #16
  17. April

    Tim Greer Guest

    Tim Greer wrote:

    > April wrote:
    >
    >> 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?


    Disregard my reply, I didn't see your follow up posts until after I had
    replied. Looks like you understand the issue now.
    --
    Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
    Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
    and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
    Industry's most experienced staff! -- Web Hosting With Muscle!
     
    Tim Greer, Oct 14, 2008
    #17
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ross
    Replies:
    5
    Views:
    3,633
    Mark Parnell
    Nov 5, 2003
  2. Replies:
    7
    Views:
    555
    dorayme
    Sep 11, 2006
  3. Mrmaster Mrmaster
    Replies:
    9
    Views:
    98
    Ben Giddings
    Sep 19, 2009
  4. piggy
    Replies:
    4
    Views:
    100
    piggy
    Dec 21, 2005
  5. Replies:
    8
    Views:
    221
    Dennis Lee Bieber
    Dec 19, 2012
Loading...

Share This Page