CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Match...

 



AndyNewby
Novice

Jun 7, 2003, 4:51 AM

Post #1 of 4 (4744 views)
Match... Can't Post

I'm trying to match the filename for a 'file' sype field. The format of the variable is;

C:\WINDOWS\Desktop\wee\contact-button.gif

I'm trying to grab the contact-button.gif.

I currently have;

$IN->param('TestImage') =~ m,(.+?)\.(gif|jpg|jpeg)^, and $img = $1;

The problem is, that is not grabbing anything :|

I have aslo tried;

$IN->param('TestImage') =~ m,\\(.+?)^, and $img = $1;

Anyone got any suggestions?

Cheers

Andy


AndyNewby
Novice

Jun 7, 2003, 8:01 AM

Post #2 of 4 (4743 views)
Re: [AndyNewby] Match... [In reply to] Can't Post

Ok...here is a test script;


Code
#!C:\Program Files\nusphere\perl\bin\perl.exe 
# ==================================================================

$var = "c:\windows\test\test.gif";
$var2 = "c:/windows/test/test.gif";

$var =~ m|([^\\]+)$| and $img = $1;
$var2 =~ m|([^/]+)$| and $img2 = $1;

print "Content-type: text/html \n\n";
print "\$img => $img <BR><BR>\$img2 => $img2";


This returns;

$img => c:windows est est.gif

$img2 => test.gif

Anyone got any ideas? It seems to be the backslaslashes that are causing the problem :(

Cheers

Andy

Andy
webmaster@ace-installer.com
http://www.ace-installer.com


Paul
Enthusiast

Jun 7, 2003, 8:51 AM

Post #3 of 4 (4742 views)
Re: [AndyNewby] Match... [In reply to] Can't Post

Well your first post examples are wrong because you are using ^ at the end of the regex when you should be using $

Your next post seems wrong because I get a different result for your code.


Code
$var = "c:\windows\test\test.gif";  
$var =~ m|([^\\]+)$| and $img = $1;


For me $img now contains "test.gif"

The following works fine...


Code
my ($in)   = $IN->param('file_field'); 
my ($file) = $in =~ m|([^\\/]+)$|;



(This post was edited by Paul on Jun 7, 2003, 8:52 AM)


AndyNewby
Novice

Jun 7, 2003, 11:32 AM

Post #4 of 4 (4739 views)
Re: [Paul] Match... [In reply to] Can't Post

LOL....just worked out why my Regex was givng the wrong result.

To define the file, I was using;

$var = "c:\windows\test\test.gif";

I forgot that the \ would be escaping the 'w', 't' and 't' Unimpressed

All seems fine now that I am quoting it with ' '.

Cheers

Andy

Andy
webmaster@ace-installer.com
http://www.ace-installer.com

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives