[ale] Perl Regexe questions

Keith R. Watson keith.watson at gtri.gatech.edu
Tue Jun 15 20:37:57 EDT 2004


At 18:38 6/15/2004 -0400, you wrote:


>I'm trying to strip the file name from the following string:
>
>/opt/SAM/SystemConfig/vtun.pl
>
>I'm using the following regext:
>
>m/\/(.+)/;
>
>That seems to only work if there is only one '/' in the name.
>Since the file can be called with any pathname I need to strip
>all the way to the last '/'  Is there a way to do this with
>regex or should I use strip and get the last element of
>the array?
>
>Thanks,
>Chris


Chris,

#!c:\perl\bin\perl.exe -w

use strict;

my $full_path = '/opt/SAM/SystemConfig/vtun.pl';

my ($file_name) = ($full_path =~ /\/([^\/]+)$/);

print ($file_name, "\n");


use File::Basename;

my ($other_way, undef, undef) = fileparse($full_path,);

print ($other_way, "\n");


keith

-------------

Keith R. Watson                        GTRI/ITD
Systems Support Specialist III         Georgia Tech Research Institute
keith.watson at gtri.gatech.edu           Atlanta, GA  30332-0816
404-894-0836



More information about the Ale mailing list