Garrett Esperum wrote: > > Hi all, Hello,
> I am using Solaris, Perl 5. > I am having some problems manipulating strings. > The string I am manipulating is: > > /export/home/user/www/doc-root/dir/projects/19463/1_0001.doc > > I am trying to take out the "19463" part from the string and insert it into > a variable. > > Example of my code to do this: > > $projectId = substr($projectDocDir, length($dir), index($projectDocDir, "/", > length($dir))); > > The $dir variable contains the path > "/export/home/user/www/doc-root/dir/projects". > > When I run my script, the string "1946" is returned, the last "3" is not. > What am I doing wrong?? Either of these should work: (my $projectId) = $projectDocDir =~ m!.*/(\w+)/!; # or my $projectId = (split /\//, $projectDocDir)[-2]; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]