| |||||||||||
| |||||||||||
Combine source code files into single dbn file
Practical Example - Perl in use example from a Well House Consultants training course
More on Practical Example - Perl in use [link] Source code: combine Module: P772
#!/usr/bin/env perl
# Full POD documentation may be found below. # Sample program by Graham Ellis / Well House Consultants if ($#ARGV != 0) { die "Usage: $0 sourcefilename\n"; } if (! -r $ARGV[0] or ! -f $ARGV[0]) { die "Error 106 - File $ARGV[0] is not plain and readable\n"; } ## Set queue @inqueue = @ARGV; @outqueue = (); ## while queue not empty while (@inqueue) { ## read file $file = shift(@inqueue); unless (open (FH,$file)) { warn "# Warning 107 - Cannot read $file\n"; next; } my @modulecontent = <FH>; $loaded{$file} = 1; close FH; ## handle and add to queue any new module needs foreach $addn(@modulecontent) { if (($modwant) = $addn =~ /^\s*use\s+(\w+)/) { unless ($already{$modwant}) { push @inqueue,"$modwant.pm"; $already{$modwant} = 1; } } } ## push source to start of output push @modulecontent,"\n\n########## Source code from $file ###########\n\n"; unshift @outqueue,\@modulecontent; } ## display results foreach $sblock (@outqueue) { foreach $line (@$sblock) { if (($modcalled) = $line =~ /^\s*use\s+(\w+)/) { if ($loaded{"$modcalled.pm"}) { $line = "##inc: ".$line; } } print $line; } } __END__ =head1 Source Code Combiner This program was written as a demonstration for a customer who required to combine a whole series of source files into a single output file for distribution, with a file named on the command line being included at the END of the output file and any files called up internally included above it. The program must run recursively (i.e. there can be includes within includes). For the purpose of this demonstration, I have used Perl source code and Perl's use 'function' to provide me with test data - thus allowing me to demonstrate the comining of multiple Perl sources into a single source file. In this use, please note: a) use calls that call up code from directories other that the current directory will NOT be expanded as the code called is probably "system" uses - but a warning is issued. b) Imports from a module via the use xxxx(yyyy) syntax are NOT supported. c) Include statements which are correctly actioned are commented out of the resultant file to render the code as close to a working combined application as practical as it can be in such a short demo. d) Output is to STDOUT which the user may redirect to a file. Fatal errors and warnings to STDERR; warnings are preceeed by a # character to ensure they would be treated as comments IF the appliaction is uses in such a way that they get included in the output file! =cut Learn about this subject
This module and example are covered on our public Perl bootcamp course. If you have a group of
three or more trainees who need to learn the subject, we can also arrange a
private or on site course for you.
Books covering this topic
Yes. We have over 700 books in our library. Books
covering Perl are listed here and when you've selected a
relevant book we'll link you on to Amazon to order.
Other Examples
This example comes from our "Practical Example - Perl in use" training module. You'll find a description of the topic and some
other closely related examples on the "Practical Example - Perl in use" module index page.
Full description of the source code
You can learn more about this example on the training courses listed on this page,
on which you'll be given a full set of training notes.
Many other training modules are available for download (for limited use) from our download centre under an Open Training Notes License. Other resources
• Our Solutions centre provides a number of longer technical articles.
• Our Opentalk forum archive provides a question and answer centre. • The Horse's mouth provides a daily tip or thought. • Further resources are available via the resources centre. • All of these resources can be searched through through our search engine • And there's a global index here. Web site author
Purpose of this website
This is a sample program, class demonstration or answer from a
training course. It's main purpose
is to provide an after-course service to customers who have attended our
public private or
on site courses, but the examples are made
generally available under conditions described below.
Conditions of use
Past attendees on our training courses are welcome to use individual
examples in the course of their programming, but must check
the examples they use to ensure that they are suitable for their
job. Remember that some of our examples show you how not to do
things - check in your notes. Well House Consultants take no responsibility
for the suitability of these example programs to customer's needs.
This program is copyright Well House Consultants Ltd. You are forbidden from using it for running your own training courses without our prior written permission. See our page on courseware provision for more details. Any of our images within this code may NOT be reused on a public URL without our prior permission. For Bona Fide personal use, we will often grant you permission provided that you provide a link back. Commercial use on a website will incur a license fee for each image used - details on request. |
| ||||||||||
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho PAGE: http://www.wellho.net/resources/ex.php • PAGE BUILT: Sun Oct 11 14:50:09 2020 • BUILD SYSTEM: JelliaJamb |