Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Perl Formatting Text

by oopl1999 (Novice)
on Jun 23, 2016 at 19:50 UTC ( [id://1166420]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl Formatting Text
in thread Perl Formatting Text

Hi I am a little confused with your code. Where did you input the data in the code or put the name of the file that contains the data to sort?

Replies are listed 'Best First'.
Re^3: Perl Formatting Text
by Marshall (Canon) on Jun 23, 2016 at 21:22 UTC
    The post that I made is runnable code. If you download it, it will run "as is". I hope that you did that!

    Instead of an actual data file, I used the predefined DATA file handle. The data that is being read is right after the __DATA__ statement. This allows me to make a single post that shows the program, the output, and the input data.

    What Perl does is open the .pl program for read and then "seeks" to the beginning of the line right after __DATA__. The DATA file handle is initialized by Perl without me doing anything extra. Pretty cool! As trivia, it is possible to "seek" the DATA file handle to the beginning of the file. This would allow a Perl program to actually "read itself".

    To make a "real program", you need to put in something like this:

    open FILE, '<', "yourfilename" or "die unable to open read file $!";
    Now put FILE everywhere that I used DATA.

    The other "trick" that I used was perldoc. Perl has a way of embedding documentation right into the program. There is a utility that generates nicely formatted documentation and HTML pages using certain markup tags. The "=prints" says that what follows is documentation. The "=cut" says "end of documentation". So everything between and including the =prints and =cut tags is skipped by the compiler because it figures that this is program documentation.

    Asking questions if you see something that you don't understand is fine. I can't predict in advance what you know or don't know.

      I mentioned above that a Perl program can "read itself". Here is a short demo of that:
      #!/usr/bin/perl use warnings; use strict; ## DEMO of reading myself seek (DATA,0,0) or die "unable to seek $!"; print while <DATA>; __DATA__ some data would go here

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1166420]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-03-29 14:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found