On Wednesday, May 1, 2002, at 04:18 , John W. Krahn wrote:
> Garrett Esperum wrote:
[..]
>>
>> /export/home/user/www/doc-root/dir/projects/19463/1_0001.doc
>>
>> $projectId = substr($projectDocDir, length($dir), index($projectDocDir,
>> "/",
>> length($dir)));
you might want to perldoc File::Basename ;
I think I have figured out a part of the problem you are running into
let:
ProjectDocDir: /export/home/user/www/doc-root/dir/projects/19463
dir: /export/home/user/www/doc-root/dir/projects/
the indexNum = -1
undt it is 1946
my $doc = '/export/home/user/www/doc-
root/dir/projects/19463/1_0001.doc';
my $projectDocDir = dirname($doc) . ;
my $dir = dirname($projectDocDir) . "/"; # the cheaters
print "ProjectDocDir: $projectDocDir\ndir: $dir\n";
my $indexNum = index($projectDocDir, "/",length($dir));
print "the indexNum = $indexNum\n";
my $projectId = substr($projectDocDir, length($dir), $indexNum );
print "undt it is $projectId\n";
the Kicker here was pulling out the 'index()' call - and seeing
what it was returning - which is '-1' since if '$dir' ended with a "/"
then you get the 'error' condition' '-1' because it does not find your
string - hence the sub string is going to return from the length($dir)
a whole '-1' which actually is 'one short of your load'....
the alternative is that you style with John's idea:
[..]
> Either of these should work:
>
> (my $projectId) = $projectDocDir =~ m!.*/(\w+)/!;
>
> # or
>
> my $projectId = (split /\//, $projectDocDir)[-2];
you gotta just love the man..... He is just the GOD of regEx!
My complements!!!
the idiot idea I had been thinking was the old school tie
use File::Basename;
my $doc = '/export/home/user/www/doc-
root/dir/projects/19463/1_0001.doc';
my $projId = basename(dirname($doc));
print "we find dirname $projId\n";
ciao
drieux
---
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]