in reply to Re: Shell v Perl
in thread Shell v Perl, here-doc as stdin

If you have an empty line before the END, that empty line will get printed, which may not be what you want. You are right that it must match the first tag exactly though, if you say print <<"END";, the ending line must have ONLY 'END' in it, if you have extra spaces (even ones you may not be able to see at the end of the line), it won't work. This advice is doubly serious when you write things like this:

sub print_stuff { print <<"END"; some stuff some more stuff END }

This example doesn't work because your starting tag is "END" but your ending tag is " END". Leaving a blank line before the END isn't something I'm planning to start doing though, if you are using the here-docs right, you don't need it, if you need to always leave a blank line, then you are probably doing something wrong.


We're not surrounded, we're in a target-rich environment!

Replies are listed 'Best First'.
Re: Re: Re: Shell v Perl
by Coplan (Pilgrim) on Apr 10, 2003 at 17:28 UTC
    That brings up a good question. Would you be able to use regexp in a situation like that?

    $buffer = <<"/\s*END/";

    I don't have perl here at work, so I can't test it.

    --Coplan

      Short answer: No:

      #!/usr/bin/env perl eval { sub test { my $buffer =<<"/\s*END/"; Eins Zwei END return $buffer; } print test(); }; if($@) { print $@; } print "\ndone\n"; __END__ Can't find string terminator "/\s*END/" anywhere before EOF at test.pl + line 3.

      Longer answer in perlfaq4 as answer to the question "Why don't my <<HERE documents work?".

      regards,
      tomte


      Hlade's Law:

      If you have a difficult task, give it to a lazy person --
      they will find an easier way to do it.


      Corrcted the code to look like zthe code I actually used ;)