Perl Heredoc
id : nz3nzjini4
category : computer
blog : perl
created : 03/04/10 - 12:21:56

Here is a simple exemple of sub usage using a perl heredoc :

.01sub usage {
.02    my $binary = shift;
.03
.04    my $basename = basename($binary);
.05
.06    #Here begin usage heredoc
.07    warn << "END_USAGE_HD";
.08Usage : $basename
.09Options :
.10    -l <address> : Listen on adress
.11    -p <port> | default $DEFAULT_PORT : Listen on port
.12    -b default on : launch deamon in background
.13    -v default off : Mode verbose
.14    -V : $basename version
.15END_USAGE_HD
.16}


    • Use double quotes to interpolate vars
    • Use simple quote to not interpolate vars