Trying to get this to work on one line, but not having any success. In my
boredom I re-wrote the find command using perl4, and in tweaking it I'm
running into a problem. When I type in a starting search path as
"./something/something" I want to replace the "." with the current working
directory. Since I am forced to use perl4, the only way I know to grab the
directory is using system commands "pwd" or "dirs -l". Those system commands
append a carriage return, which is where my problem comes in. Here's some of
the lines I've tried
$_spath = shift;
print "$_spath\n";
$path = `pwd`;
#$_spath =~ s/^\./(($path=`pwd`) =~ s/\n//))/e;
#($_spath =~ s/^\./$path=`pwd`/e) =~ chop($_spath);
#($chop($path)) =~ $_spath =~ s/^\./$path = `pwd`/e;
#($_spath =~ s/^\./($path=`pwd`) =~ chop($path)/e);
$_spath =~ s/^\./chop(`pwd`)/e;
print "$_spath\n";
I've tried dozens of ways in one command, but can't get rid of that carriage
return. Chop works fine as long as I don't try to do it inside the
substitution, reason for that?
In a nutshell I am just trying to make my little searching script identify a
path beginning with "." and replace that with the pwd, so I don't have to
type out absolute paths every time. FWIW, here's that script
#!/usr/contrib/bin/perl
($_pattern, $_start) = (shift, shift);
print "Starting search at: $_start\n";
chdir "$_start";
opendir (DIR, "$_start");
foreach (sort readdir(DIR)){
-d $_ ?
((/^\.\.$|^\.$/)?(next):(push(@tree,$_start."/".$_))):(grep(/$_pattern/,$_)?
(print "file: $_start\/$_\n"):(next));
-d $_ ? (grep(/$_pattern/,$_) ? (print "dir: $_start\/$_\n"):()):();
}
closedir (DIR);
&cascade(shift(@tree)) while ($#tree ne -1);
sub cascade {
$SubDir = shift;
print "$SubDir\n" if grep(/$_pattern$/,$SubDir);
chdir "$SubDir";
opendir (SUBDIR, "$SubDir");
foreach (sort readdir(SUBDIR)) {
-d $_ ?
((/^\.\.$|^\.$/)?(next):(push(@tree,$SubDir."/".$_))):(grep(/$_pattern/,$_)?
(print "file: $SubDir\/$_\n"):(next));
}
closedir (SUBDIR);
}
TIA,
Ken
P.S. "chomp()" is not available in perl4.