Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
simple regx please
ProfessorX
Cny you provide me with
my $tmpfile = d:\dir1\dir2\dir3\temp.txt
# INSERT regx here
so that I will have
$dir equals = d:\dir1\dir2\dir3\
and file = temp.txt
Thanks in advance!
WIN2K TS/TST 5.5.2 sp5; OD 5.6.0.1; DD 5.5.2
The Professor-
Find more posts tagged with
Comments
AKB
use File:: BaseName
and then
$filename = basename($file);
$dirpath = dirname($file);
where $file is the path of the file with directories...
should get you going.
Jeremy
Try
$tmpfile =~ m|(.*)\\(.*)$|;
$dir = $1;
$file = $2;
Didn't have time to put it all on one line. I am sure some one else can!
HTH
Migrateduser
my $tmpfile = "d:\\dir1\\dir2\\dir3\\temp.txt";
$tmpfile =~ m#^(.*\\)(.*)$#;
my $path = $1;
my $file = $2;
print "path: $path\n";
print "file: $file\n";
Dave Smith
Sr. Software Engineer
Nike, Inc.
(503) 671-4238
DavidH.Smith@nike.com
Migrateduser
Your regex will leave off the ending
\
in the path name, which he seems to want.
Dave Smith
Sr. Software Engineer
Nike, Inc.
(503) 671-4238
DavidH.Smith@nike.com
Jeremy
Oh right. Good point. So mine would then me
$tmpfile =~ m|(.*\\)(.*)$|;
My bad.
jbonifaci
For the person that wanted a one liner:
my ($dir, $file) = $tmpfile =~ /^(.*[\\\/])([^\\\/]*)$/;
Subdivrpt2.rptdesign
saumil
Hi,
you can use following as well if you dont' want to break your head with regex.
my $tmpfile = d:\dir1\dir2\dir3\temp.txt;
my $lind=rindex $tmpfile,'\';
my $file=substr($tmpfile,0,lind);
my $dirPath=substr($tmpfile,lind+1,0);
Regards,
Saumil
Saumil Shah
Technical Associate
Mahindra and British Telecom
+0919819890479
Migrateduser
But wow, why do in
four
lines what you can do in
one
? I believe that was one of the early Perl credos, actually. To bad they didn't make bumper stickers out of it.
Dave
nipper
Old timers remember APL
One line programs. Some of the ugliest code you EVER saw.
Migrateduser
Oh yeah??? Share! I never heard of APL but if it looks anything like LISP and Prolog, I'll stick to my Perl.
Very curious though, is there an online resource for this?
Dave
Dwayne
If I remember correctly, APL is a TLA for "A Programming Language" and you had to have a special keyboard to code in it, because it used all sorts of wierd characters, rather than normal ASCII (or even EBCDIC - wasn't APL an IBM creation?)
--
Current project: TS 5.5.2/6.1 W2K
Migrateduser
Yep, you're right...
http://www.engin.umd.umich.edu/CIS/course.des/cis400/apl/apl.html
Dave
nipper
Dwayne knows about it. Yes it used a special keyboard of symbols to program. It is wild.
A common game (very geeky game) was to write a 1 line program and see if someone could figure out
what it did without running it.
Not that I ever did things like that in college.