in reply to Meaning of 'use constant USAGEMSG = > ...'

It defines a constant with the string in the HERE-doc as value.
to make it clearer one could write that in two steps:
my $c = <<USAGE; Usage:ftp.pl [options] host:/path/to/directory Options: --user <user> Login name --pass <pass> password USAGE #$c now holds the text between <USAGE and USAGE. print $c; use constant USAGEMSG => $c;
Update:
as igekami pointed out, the above wonīt work. That happens when you donīt test your posts :(.


holli, /regexed monk/

Replies are listed 'Best First'.
Re^2: Meaning of 'use constant USAGEMSG = > ...'
by ikegami (Patriarch) on Feb 08, 2005 at 16:36 UTC

    Your code won't work because use is executed before the assignment to $c. Even if $c was initialized in a BEGIN block, it would still be too late.

      #!/usr/bin/perl use strict; use warnings; my $c; BEGIN { $c = <<USAGE; What do you mean, too late? USAGE } use constant USAGEMSG => $c; print +USAGEMSG; __END__ What do you mean, too late?

        hum, I had tested

        BEGIN { $c = <<USAGE; What do you mean, too late? USAGE use constant USAGEMSG => $c; }

        and

        BEGIN { $c = <<USAGE; What do you mean, too late? USAGE } use constant USAGEMSG => $c;

        and both gave me the same error. Maybe the file wasn't properly saved for the second test?

        Thanks for verifying; it puzzled me.