Hi everyone
I want to know what is __END__ mean , is this the end of the file.
For what this is used in PERL?

Thanks

Recommended Answers

All 11 Replies

hey, you should have googled it, before posting it here...
Well, I found, __END__ is the logical end of program text. You can put anything you want after this token; it will be ignored by the compiler.

kath.

i got it ,
its just like the comments after the program code.
thanks

hey, you should have googled it, before posting it here...
Well, I found, __END__ is the logical end of program text. You can put anything you want after this token; it will be ignored by the compiler.

kath.

There's a related "token" __DATA__ and anything after that in the script can be accessed by the file handle "DATA" as in:

while (<DATA>) {
  # do something w/ the lines
...
}

__DATA__
first data line
2nd data line

This lets you build your data/test stuff right into the script. If you wanted to just hide comments, look at the POD documentation (perldoc perlpod) there are couple of easy tags allow that
http://perldoc.perl.org/perlpod.html

It seems __END__ is a "synonym" of __DATA__
following code proves that

while (<DATA>) {
  print;
}

__END__
hello

__DATA__
first data line
2nd data line
C:\>perl c:\d.pl
hello

first data line
2nd data line

the text "hello" is displayed as it was put in __DATA__ section.

It seems __END__ is a "synonym" of __DATA__

http://perldoc.perl.org/perldata.html

For compatibility with older scripts written before __DATA__ was introduced, __END__ behaves like __DATA__ in the toplevel script (but not in files loaded with require or do) and leaves the remaining contents of the file accessible via main::DATA .

I guess its something to do with the POD (Plain Old Documentation)..

You can refer to http://perldoc.perl.org/perlpod.html

You can put the documentation at the end of the file. So wen u use man or help in options on command line this documentation could be fetched and displayed.

I guess its something to do with the POD (Plain Old Documentation)..

You can refer to http://perldoc.perl.org/perlpod.html

You can put the documentation at the end of the file. So wen u use man or help in options on command line this documentation could be fetched and displayed.

Er, no. _END_ (and the moderner _DATA_) are markers for the script to ignore/not parse what follows, but makes it available from the "built-in" file handle DATA. POD uses a different set of markers to allow documentation to be included in the script and ignored as code. Some folks may *use* _END_ to hide their comments/PDD from the code but that's not it's purpose.

commented: Good explanation. +1

Er, no. _END_ (and the moderner _DATA_) are markers for the script to ignore/not parse what follows, but makes it available from the "built-in" file handle DATA. POD uses a different set of markers to allow documentation to be included in the script and ignored as code. Some folks may *use* _END_ to hide their comments/PDD from the code but that's not it's purpose.

Ok Question..

http://perldoc.perl.org/Pod/Usage.html

Have a look under "Recommended Usage" at the bottom of the page. I copied the script and tried to run it on my machine. For some reason it doesnt display anything if i give the -man or -help options.

Any idea whY? is there something wrong with the script that needs to be fixed..

Ok Question..

http://perldoc.perl.org/Pod/Usage.html

Have a look under "Recommended Usage" at the bottom of the page. I copied the script and tried to run it on my machine. For some reason it doesnt display anything if i give the -man or -help options.

Any idea whY? is there something wrong with the script that needs to be fixed..

hmm, works here. "-help" actually gives me 2 versions and -man gives me a man style output (I named it use.pl):

$ perl use.pl
use.pl: No files given.
Usage:
    sample [options] [file ...]

    Options: -help brief help message -man full documentation
$ perl use.pl -help
Usage:
    sample [options] [file ...]

    Options: -help brief help message -man full documentation

Options:
    -help   Print a brief help message and exits.

    -man    Prints the manual page and exits.

What sort of machine are you running it on?

it is a unix aix box...
i thought it wouldnt matter. since it didnt throw up any errors or warnings..
hmmmm

it is a unix aix box...
i thought it wouldnt matter. since it didnt throw up any errors or warnings..
hmmmm

Yeah, well, winx boxes find all sorts of fun stuff. Try adding a "-w" to perl's run:

$ perl -w use.pl

or "use warnings" in there, in case there's been a cutnpaste-o. If you try perldoc for those 'use'-ed modules:

$ perldoc Pod::Usage

What do you get? Maybe they're not installed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.