Perl soelim (was Re: software tools question)

Chip Salzenberg chip at ateng.com
Thu Dec 14 06:39:31 AEST 1989


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.
-- 
You may redistribute this article only to those who may freely do likewise.
Chip Salzenberg at A T Engineering;  <chip at ateng.com> or <uunet!ateng!chip>
	  "The Usenet, in a very real sense, does not exist."



More information about the Comp.unix.questions mailing list