>Jensen Kenneth B Sra Afpc/Dpdmpq wrote:
>>
>> 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,
>
>WHY??
Because it would involve the sysadmin team here to do some work and learn a
little UNIX to install the latest version. On our hp-unix systems.
>> 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;
>
>$_spath =~ s{^\.}
> { $path = `pwd`;
> chop $path;
> $path
> }e;
I wasn't aware I could have multiple commands in there. Had to change it
around so perl4 would be happy, no white space and restricted to using s///.
Thanks
$_spath =~ s/^\./$path =`pwd`;chop $path;$path/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?
>
>It works, it's just that you have to return the path not the return value
of chop.
I figured that was what was happening, but I thought it should have returned
the new value of $path.
>> 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
>
>#!/usr/contrib/bin/perl -w
I only use the -w when I am developing it, as this is a script that can
iterate several thousand times depending on the depth of the directories. I
didn't want to see the same warning message that many times. :)
>> ($_pattern, $_start) = (shift, shift);
>> print "Starting search at: $_start\n";
>>
>> chdir "$_start";
>
>Useless use of quotes. You should verify that chdir worked.
>
>unless ( chdir $_start ) {
> print STDERR "Cannot chdir to $_start: $!";
> exit 1;
> }
>
>
>> opendir (DIR, "$_start");
>
>Useless use of quotes. You should verify that opendir worked.
>
>unless ( opendir( DIR, $_start ) ) {
> print STDERR "Cannot open $_start: $!";
> exit 1;
> }
I didn't want to trap errors on the chdir's or opendirs. If it fails its
because I don't have the permissions to open that directory, and it should
be skipped anyway. The use of quotes may be useless, but it's just more
aesthetically appealing to me. I doubt they really effect processing speed
by any measurable amount anyway :).
Thanks for the input John!
Ken
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
RE: Commands inside a reg-ex substitution problems
Jensen Kenneth B SrA AFPC/DPDMPQ Thu, 06 Mar 2003 17:04:22 -0800
- Commands inside a reg-ex substitution pro... Jensen Kenneth B SrA AFPC/DPDMPQ
- Re: Commands inside a reg-ex substit... John W. Krahn
- Re: Commands inside a reg-ex sub... Scott R. Godin
- Re: Commands inside a reg-ex... Jenda Krynicky
- Re: Commands inside a reg-ex... John W. Krahn
- HTML for my perl CGI Luinrandir Hernsen
- Re: HTML for my perl CGI Wiggins d'Anconia
- Re: Commands inside a reg-ex substit... Jensen Kenneth B SrA AFPC/DPDMPQ
- Re: Commands inside a reg-ex sub... Wiggins d'Anconia
- Re: Commands inside a reg-ex sub... John W. Krahn
- RE: Commands inside a reg-ex substit... Jensen Kenneth B SrA AFPC/DPDMPQ
- RE: Commands inside a reg-ex substit... wiggins
