| Author |
reqular expr for string manip.
|
|
|
| Hi:
I am using the following reqular expression to extract the last part ie
$lang of the following string
$topdir = "common/default/l_cs";
my $lang=$topdir =~ /.*\/(.+)$/;
But it doesnt seem to work, what am i missing here?
Thanks!
| |
| Jeff Pang 2007-04-19, 3:58 am |
| For your purpose,using Perl's built-in module File::Basename is a good way.
use File::Basename;
my $filename = basename($topdir);
my $dirname = dirname($topdir);
Good luck!
2007/4/19, Nishi <nishiprafull@gmail.com>:
>
> Hi:
>
> I am using the following reqular expression to extract the last part ie
> $lang of the following string
> $topdir = "common/default/l_cs";
> my $lang=$topdir =~ /.*\/(.+)$/;
>
> But it doesnt seem to work, what am i missing here?
>
> Thanks!
>
--
mailto: pangj@earthlink.net
http://home.arcor.de/jeffpang/
| |
| elsiddik 2007-04-19, 7:58 am |
|
On Apr 19, 1:26 pm, nishipraf...@gmail.com (Nishi) wrote:
> Hi:
>
> I am using the following reqular expression to extract the last part ie
> $lang of the following string
> $topdir = "common/default/l_cs";
> my $lang=$topdir =~ /.*\/(.+)$/;
>
> But it doesnt seem to work, what am i missing here?
>
> Thanks!
use File::Basename;
my $name = "common/default/l_cs";
my $basename = basename $name ;
zaher el siddik
http://elsiddik.blogspot.com/
| |
| Mumia W. 2007-04-19, 7:58 am |
| On 04/18/2007 10:26 PM, Nishi wrote:
> Hi:
>
> I am using the following reqular expression to extract the last part ie
> $lang of the following string
> $topdir = "common/default/l_cs";
> my $lang=$topdir =~ /.*\/(.+)$/;
>
> But it doesnt seem to work, what am i missing here?
>
> Thanks!
>
my $lang = ($topdir =~ /([^\/]+)$/)[0];
| |
| Dr.Ruud 2007-04-19, 6:58 pm |
| "Mumia W." schreef:
> my $lang = ($topdir =~ /([^\/]+)$/)[0];
ITYRMSL:
my ($lang) = $topdir =~ m~([^/]+)$~;
--
Affijn, Ruud
"Gewoon is een tijger."
| |
| Oryann9 2007-04-20, 6:58 pm |
| > "Mumia W." schreef:
>
>
> ITYRMSL:
>
> my ($lang) = $topdir =~ m~([^/]+)$~;
>
> --
Dr Rudd,
I have never seen the expression m~ or $~
Will you tell me what this is and what is says?
thank you
________________________________________
__________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
| |
| Jeff Pang 2007-04-20, 6:58 pm |
| >
>
>
>
>
> I have never seen the expression m~ or $~
> Will you tell me what this is and what is says?
m~foobar$~ is the same as,
m/foobar$/
here m~ and $~ are not special operators or variables at all,just the
board-symbol for regex.:)
| |
| Rob Dixon 2007-04-20, 6:58 pm |
| oryann9 wrote:
>
> Dr. Ruud wrote:
>
> I have never seen the expression m~ or $~
> Will you tell me what this is and what is says?
Like all Perl quoted constructs, the pattern match
can take any delimiter you choose as long as you supply
the m explcitly, so the following are equivalent:
/regex/
m/regex/
m~regex~
m(regex)
m<regex>
(Note that bracket-like delimiters are paired.)
Using a different delimiter from the usual slash character
removes the need to escape slashes within the regex itself,
which is what Mumia has done.
HTH,
Rob
| |
| Rob Dixon 2007-04-20, 6:58 pm |
| Dr.Ruud wrote:
>
> "Mumia W." schreef:
>
>
> ITYRMSL:
>
> my ($lang) = $topdir =~ m~([^/]+)$~;
IDUWYM. CYETUP?
Rob
| |
|
|
|
|