in reply to Re: Proper way to print a large number of strings
in thread Proper way to print a large number of strings

I did consider that, but that doesn't seem to properly handle the OO references (unless I'm missing something obvious). For example, when I run this:

use CGI; $cgi = new CGI; print << "HEREDOC"; $cgi->p("Test.") HEREDOC <code> I get <code>CGI=HASH(0x119960)->p("Test.")
when I really want <p>Test.</p>.

Replies are listed 'Best First'.
Re:x3 Proper way to print a large number of strings (use scalar interpolation)
by grinder (Bishop) on Jan 07, 2003 at 16:49 UTC
    use CGI; $cgi = new CGI; print << "HEREDOC"; $cgi->p("Test.") HEREDOC
    I get CGI=HASH(0x119960)->p("Test.")

    What you want to do is take a reference to your object, and interpolate it via a scalar reference. Look at the following:

    $cgi->p('test') | V \$cgi->p('test') | V ${\$cgi->p('test')}

    In Perl 6, ${...} becomes a mere scalar, and no longer a scalar reference, so you'll be able to write ${$cgi->p('test')} which will be pretty cool. Until then, you'll have to make do with using the above hack. Sometimes this is acceptable, sometimes it's better to do something like:

    print 'stuff ' . $q->b( $q->i( 'and' )) . ' nonsense'

    It all depends on what comes out as being more readable.


    print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'
      Or the IMHO more tolerable @{[ $cgi->p('test') ]} which avoids the ugly backslash and creates a sort of (unwieldy) "template directive look&feel" with its paired delimiters.

      Makeshifts last the longest.

Re: Re: Re: Proper way to print a large number of strings
by Fletch (Bishop) on Jan 07, 2003 at 15:30 UTC
    print $cgi->p( $_ ), "\n" foreach split( /\n\n/, <<"EOT" ); Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi rhoncus, est in pulvinar volutpat, massa erat gravida ipsum, sit amet pharetra lorem nulla eu odio. Integer nec velit. Integer commodo. Duis dui. Aliquam erat volutpat. Pellentesque quis turpis vitae ante egestas imperdiet. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam scelerisque. Vivamus mi dolor, bibendum vitae, eleifend at, lobortis sit amet, leo. EOT