http://www.perlmonks.org?node_id=565587

dark314 has asked for the wisdom of the Perl Monks concerning the following question:

solution


im sorry, my script is so long, the error is from another place, the tags do work alone. Thanks for your help, and again i apoligize.
at the end of my script was something like...
sub help { //the rest of the code was gone, because i had copied and pasted to th +e top of the script.

UPDATE: It doesnt work for me (EOF tags)

sub help() { print <<"EOF"; Possible Starting Arguments for ldapadmin: blah blah EOF }
I get this error:
dark314@chavez:~/boxes/scripts/csl-ldap-01$ ./ldapadmin -help
Missing right curly or square bracket at ./ldapadmin line 896, at end of line
syntax error at ./ldapadmin line 896, at EOF
Execution of ./ldapadmin aborted due to compilation errors. sorry if this seems very easy, but its bugging me because I know there should be some better way of doing it.
ok, so heres the deal: I have a textfile, with tabstops in it, its a helpfile for a script of mine which is written in, you guessed it, perl. Originally I had the perl script make a system call to cat <name of file> but given the small size of the script, i'd rather it inside the script, perhaps in a subroutine called help(), i was thinking of adding something like this:
print " //paste help text here which was copied ";
but i know this is a bad approach and im sure it doesn't work.

Replies are listed 'Best First'.
Re: inserting a formatted text file into a perl script.
by Hue-Bond (Priest) on Aug 03, 2006 at 23:14 UTC
    i know this is a bad approach and im sure it doesn't work.

    Why are you sure? That would work, although there are other options. I would use a here document. Read about it in perlop.

    print <<"EOF"; insert some text here this text can contain tabs foo bar baz EOF

    --
    David Serrano

Re: inserting a formatted text file into a perl script.
by GrandFather (Saint) on Aug 03, 2006 at 23:20 UTC

    If the help pertains to the script then you might consider putting the help information into the script as POD and use Getopt::Long and/or Pod::Usage to do the heavy lifting for you. See the sample code in the Getopt::Long documentation to get started.


    DWIM is Perl's answer to Gödel
Re: inserting a formatted text file into a perl script.
by planetscape (Chancellor) on Aug 03, 2006 at 23:45 UTC
Re: inserting a formatted text file into a perl script.
by GrandFather (Saint) on Aug 03, 2006 at 23:51 UTC

    In what way doesn't it work for you? What gets printed? Note that if you can reproduce your problem with a short example we are much more inclined to help than if you present us with a huge example. For example, the following works for me:

    print <<"EOF"; Possible Starting Arguments for ldapadmin: EOF

    Prints:

    Possible Starting Arguments for ldapadmin:

    DWIM is Perl's answer to Gödel
Re: inserting a formatted text file into a perl script.
by Magius_AR (Sexton) on Aug 03, 2006 at 23:28 UTC
    I wouldn't necessarily call that a bad approach. I'd use a heredoc myself.

    Though if you're wickedly opposed to the idea, you could always append it at the bottom on your code under a __DATA__ token and just dump out of the <DATA> filehandle. Ugly, but effective :)

Re: inserting a formatted text file into a perl script.
by starbolin (Hermit) on Aug 04, 2006 at 06:37 UTC

    Please elucidate what is not working for you.

    Troll [181] as maint ~/ %cat foo +[11:33pm] #!/usr/bin/perl -w use strict; &help; sub help() { print <<"EOF"; blah blah EOF } Troll [182] as maint ~/ %perl foo +[11:33pm] blah blah Troll [183] as maint ~/ %


    s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}
Re: inserting a formatted text file into a perl script.
by Magius_AR (Sexton) on Aug 04, 2006 at 00:14 UTC
    You appear to be missing your closing curly for the help() function.