tricky use of print?

Discussion in 'Perl Misc' started by Ela, Apr 2, 2008.

  1. Ela

    Ela Guest

    I found that little can be done on debugging a variable on print, after
    visiting a page containing the module PadWalker.

    I wonder whether in Perl can do something like:

    $newline = '\n'

    print
    foo
    $foo

    print $newline;


    I use the vim editor, in this sense, rapid coding and debugging can achieve.
    But i at least know that the newline trick doesn't work...
     
    Ela, Apr 2, 2008
    #1
    1. Advertising

  2. Ela

    szr Guest

    David Filmer wrote:
    > Ela wrote:
    >> $newline = '\n'

    >
    > In Perl, single-quotes are not interpolated (meaning $newline is set
    > to backslash-n). You would need to use double-quotes (or qq{}) to
    > interpolate \n as a newline.


    Or a heredoc :)

    print <<_EOF_;
    $foo $bar
    _EOF_

    --
    szr
     
    szr, Apr 2, 2008
    #2
    1. Advertising

  3. Ela

    Ela Guest

    > Or a heredoc :)
    >
    > print <<_EOF_;
    > $foo $bar
    > _EOF_
    >
    > --
    > szr
    >


    There are too few words in your example and I'm unable to follow/Google. I
    guess maybe you are telling something important? thx
     
    Ela, Apr 2, 2008
    #3
  4. Ela

    szr Guest

    David Filmer wrote:
    > Ela wrote:
    >>> Or a heredoc :)
    >>>
    >>> print <<_EOF_;
    >>> $foo $bar
    >>> _EOF_
    >>>

    >>
    >> There are too few words in your example and I'm unable to
    >> follow/Google. I guess maybe you are telling something important? thx

    >
    > szr is just showing you an example of how to use a heredoc, which
    > recognizes the \n at the end of any lines within it (so it's just
    > another way of printing newlines).


    I should of also said, you can either physically have new lines, like:

    print <<_EOF_;
    A
    B
    C
    _EOF_


    Or you can use \n instead:

    print <<_EOF_;
    A\nB\nC
    _EOF_


    Or mix and match:

    print <<_EOF_;
    A
    B\nC
    _EOF_


    Either way you get:

    $ perl -e 'print <<_EOF_;
    > A
    > B\nC
    > _EOF_'

    A
    B
    C

    --
    szr
     
    szr, Apr 2, 2008
    #4
  5. Ela <> wrote:
    >> Or a heredoc :)
    >>
    >> print <<_EOF_;
    >> $foo $bar
    >> _EOF_
    >>
    >> --
    >> szr
    >>

    >
    > There are too few words in your example and I'm unable to follow/Google. I
    > guess maybe you are telling something important? thx



    See the "<<EOF" section in perlop.pod.


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
     
    Tad J McClellan, Apr 3, 2008
    #5
    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. Replies:
    9
    Views:
    561
    CBFalconer
    Apr 25, 2006
  2. keto
    Replies:
    0
    Views:
    1,046
  3. Replies:
    11
    Views:
    516
    Charlie Gordon
    Sep 15, 2007
  4. David Cournapeau

    print a vs print '%s' % a vs print '%f' a

    David Cournapeau, Dec 30, 2008, in forum: Python
    Replies:
    0
    Views:
    400
    David Cournapeau
    Dec 30, 2008
  5. Alex

    Use of a Repeater control in tricky situation

    Alex, Oct 2, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    124
Loading...

Share This Page