Click here to get back home

tricky use of print?

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
tricky use of print? Ela 04-02-2008
Posted by Ela on April 2, 2008, 2:57 am
Please log in for more thread options
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...



Posted by David Filmer on April 2, 2008, 3:06 am
Please log in for more thread options
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.

Posted by szr on April 2, 2008, 12:11 pm
Please log in for more thread options
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



Posted by Ela on April 2, 2008, 12:20 pm
Please log in for more thread options
> 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



Posted by David Filmer on April 2, 2008, 1:28 pm
Please log in for more thread options
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).

You could do the same thing like this:

print "$foo $bar
";

but that's questionable programming style (whereas a heredoc is
generally accepted, though I personally dislike them).

Similar ThreadsPosted
Tricky Merge task in Perl - Pls help June 5, 2005, 3:41 pm
Coderefs in objects: tricky questions September 26, 2005, 2:18 pm
Tricky regex (exclude some multiple characters) July 27, 2006, 4:44 pm
(",) Print This! Press [Ctrl][P] Keys To Print... >> http://www.phpbbserver.com/phpbb/viewtopic.php?t=2&mforum=anysubjectchat < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < May 30, 2005, 2:05 pm
Tricky subclassing problem: Parent class method uses static value from child class September 26, 2006, 4:45 am
* * * Please Read And/Or Print This! * * * Press [Ctrl][P] Keys On Your Keyboard To Print >> June 1, 2004 8:24:38 pm >> http://115639.aceboard.net/forum2.php?rub=158&cat=61&login=115639&page=0#id96 << * * * * * * * * * * * * * * * * * * * * * * * * * * * June 1, 2005, 6:24 pm
print @ versus print @ September 25, 2005, 9:53 pm
difference between print < August 16, 2006, 1:16 pm
CGI: print $x =~ s/\n/
\n/g;
July 9, 2004, 9:46 pm
why not print $A[0] November 5, 2004, 6:28 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap