Program: tkshufflepod
This short program uses
Tk to list the
=head1
sections in the file using the Listbox
widget, and it lets you drag the sections around to reorder them.
When you’re done, press "s"
or
"q"
to save or quit. You can even double-click on
a section to view it with the Pod widget. It writes the section text
to a temporary file in /tmp and removes the file
when the Pod widget is destroyed.
Call it with the name of the Pod file to view:
% tkshufflepod chap15.pod
We used this a lot when we wrote this book.
The program text is shown in Example 15.10.
Example 15-10. tkshufflepod
#!/usr/bin/perl -w # tkshufflepod - reorder =head1 sections in a pod file use Tk; use strict; # declare variables my $podfile; # name of the file to open my $m; # main window my $l; # listbox my ($up, $down); # positions to move my @sections; # list of pod sections my $all_pod; # text of pod file (used when reading) # read the pod file into memory, and split it into sections. $podfile = shift || "-"; undef $/; open(F, "< $podfile") or die "Can't open $podfile : $!\n"; $all_pod = <F>; close(F); @sections = split(/(?==head1)/, $all_pod); # turn @sections into an array of anonymous arrays. The first element # in each of these arrays is the original text of the message, while # the second element is the text following =head1 (the section title). foreach (@sections) { /(.*)/; $_ = [ $_, $1 ]; } # fire up Tk and display the list of sections. $m = MainWindow->new(); $l = $m->Listbox('-width' => 60)->pack('-expand' ...
Get Perl Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.