Perl soelim (was Re: software tools question)

Larry Wall lwall at jpl-devvax.JPL.NASA.GOV
Fri Dec 15 10:24:22 AEST 1989


In article <2586A576.9028 at ateng.com> chip at ateng.com (Chip Salzenberg) writes:
: According to merlyn at iwarp.intel.com (Randal Schwartz):
: >#!/usr/bin/perl -p
: >next unless /^\.so\s+(.*)/;
: >if (open(SO,$1)) {
: >	$_ = join("",<SO>);
: >	close(SO);
: >} else {
: >	warn "Cannot open $1 at $ARGV (line $.): $!";
: >}
: 
: I should really hope that people would prefer NOT to read in the entire
: file and assign it to $_.  Rather, I'd do this:
: 
:     #!/usr/bin/perl -p
:     next unless /^\.so\s+(\S+)/;        # A better regexp
:     $SO = $1;
:     if (open(SO)) {
: 	while (<SO>) {
: 	   print;
: 	}
: 	close(SO);
:     } else {
: 	   warn "Cannot open $SO at $ARGV (line $.): $!";
:     }
:     $_ = "";                            # You forgot this, Randal
: 
: >This only works one level deep (no nested .so's), and requires Perl
: >3.0, although the only 3-ism is the "warn".
: 
: Ditto.

There's an example of nested include file processing (thought not
specifically .so files) in the perl manual.  Look under "open".

Larry Wall
lwall at jpl-devvax.jpl.nasa.gov



More information about the Comp.unix.questions mailing list