|
From: Xicheng on 27 Jan 2006 10:31 Paul Lalli wrote: > Xicheng wrote: > > a wrote: > > > Also, I have a directory as an input. > > > e.g //server/dirA/dirB/ > > > How can I check the last character is a / or not? > > if $str =~ m{/$} { > > #the last char is / > > } > > no need to invoke the regexp engine for such a simple task. (Oh, and > what you typed is a syntax error). yep, you are right, I forgot to add parenthesis to the 'if' clause:( Xicheng > if (substr($str, -1) eq '/') { > print "Last char is a slash\n"; > } > > Paul Lalli
From: DJ Stunks on 27 Jan 2006 13:25 a wrote: > <first question snipped> > > Also, I have a directory as an input. > e.g //server/dirA/dirB/ > How can I check the last character is a / or not? > Thanks a lot I assume you only want to check for that trailing slash in order to know whether or not it's actually a directory, so just test for that. print "$_ is a directory" if ( -d ); -jp
From: Tad McClellan on 27 Jan 2006 17:49 a <a(a)mail.com> wrote: > How can I check the last character is a / or not? print "last is a slash\n" if substr($path, -1) eq '/'; -- Tad McClellan SGML consulting tadmc(a)augustmail.com Perl programming Fort Worth, Texas
From: Tad McClellan on 28 Jan 2006 00:08 James Taylor <usenet(a)oakseed.demon.co.uk.invalid> wrote: > my ($dir, $leaf) = $path =~ m|^(.*)/(.*)|; ^ ^ That anchor serves no useful purpose, so it probably shouldn't be there. -- Tad McClellan SGML consulting tadmc(a)augustmail.com Perl programming Fort Worth, Texas
From: James Taylor on 28 Jan 2006 12:01 Tad McClellan <tadmc(a)augustmail.com> wrote: > James Taylor <usenet(a)oakseed.demon.co.uk.invalid> wrote: > > > my ($dir, $leaf) = $path =~ m|^(.*)/(.*)|; > ^ > ^ > > That anchor serves no useful purpose, so it probably shouldn't be there. My newsreader doesn't have a monospaced font (I must fix that) so your caret appears to point to the dollar singin front of $path. I must assume though that you were pointing at the beginning of line anchor in my regex. The reason it is there is to ensure that the match fails in linear time if there is no slash in the $path. -- James Taylor
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: Check subroutine-specific requirements on module import Next: Java sucks, Perl Rules. |