What is meaning of “<<”, “--” in perl and implementation in php?

后端 未结 2 1741
北海茫月
北海茫月 2021-01-23 07:19

I am converting some Perl code to PHP.
However, I do not know much about Perl, so I have to code it with a rough meaning.

And, I do not understand what the below P

2条回答
  •  鱼传尺愫
    2021-01-23 08:02

    Nothing very different from PHP actually.

    • << Heredoc, also present in PHP with slight differences:

      echo (<<<"POST_DATA"
      First line
      Second line
      POST_DATA
      );
      
    • -- Variable decrease, as in

    Note:

    Of course, inside a Heredoc -- is just text.


    Suggestion:

    If you don't fully understand the Perl, try to run it (it's not evil code).

    my $boundary = 'Nobody-has-the-intention-to-erect-a-wall';
    print(<<"POST_DATA");
    
    --$boundary
    Content-Disposition: form-data; name="num_result"
    Content-Type: text/plain
    
    $num_result
    --$boundary
    Content-Disposition: form-data; name="img"; filename="search.jpg"
    Content-Type: image/jpeg
    
    $image
    --$boundary--
    POST_DATA
    

    Will yield:

     
    --Nobody-has-the-intention-to-erect-a-wall
    Content-Disposition: form-data; name="num_result"
    Content-Type: text/plain
    
    
    --Nobody-has-the-intention-to-erect-a-wall
    Content-Disposition: form-data; name="img"; filename="search.jpg"
    Content-Type: image/jpeg
    
    
    --Nobody-has-the-intention-to-erect-a-wall--
    

提交回复
热议问题