Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Newline

  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mumbai, India
    Posts
    218
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Newline

    How do I print something in a new line in the terminal?

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mumbai, India
    Posts
    218
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, I got it.

    Code:
    printf "\n";
    I was using

    Code:
    print '\n';
    which did not work.


  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The problem with your print '\n'; was not that it wasn't printf() but that it used single quotes, where no interpolation was done - i.e. Perl interpreted the slash-n literally, and printed out a slash-n to your browser. If you were to use print "\n"; it would work as you wanted.

    Generally speaking printf is used only if you want to do some kind of formatting, for instance:
    Code:
    printf("%.4d", $count);
    Will pad the variable out to have a width of 4 characters, and it will be preceded with 0's, i.e.
    Code:
    $count = 4;
    printf("%.4d", $count);
    # prints out 0004
    
    $count = 3489;
    printf("%.4d", $count);
    #prints out 3489
    Hope that helps.

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mumbai, India
    Posts
    218
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, I know. I realised that later while working on my script


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •