in reply to Proper way to print a large number of strings

I'm also willing to accept that it doesn't really matter at all.

That's probably the correct answer. Since this is a CGI program, you're almost certainly going to be limited by I/O long before printing time on the CPU becomes an issue. You should format your code in the most readable way, which is usually a heredoc.

  • Comment on Re: Proper way to print a large number of strings

Replies are listed 'Best First'.
Re: Re: Proper way to print a large number of strings
by jpfarmer (Pilgrim) on Jan 07, 2003 at 15:04 UTC

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

      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