noochies Posted August 25, 2008 Share Posted August 25, 2008 Hello, I am very baffled with some lines of code from a program I took over that was written by someone else. Here is the code: my $ext=$file; $ext =~ /(\..{3,4}$)/; $ext = $1; my $documentFormatId = isAllowedExtension($ext); I know that this is ultimately getting the file extension into the $ext variable, but that's as far as I've gotten. I can't figure out what the second line is trying to do. I put in print statements in between each of those lines printing out what the var $ext had in it. After the second line, the var is the same as it was before the second line (it equals $file). I know that the tilde character (~) is the bitwise negation character, but I'm not sure how the regular expression fits into the mix. Can someone tell me how you bitwise negate a string with a regular expresson involved? Quote Link to comment Share on other sites More sharing options...
effigy Posted August 25, 2008 Share Posted August 25, 2008 This is Perl: ### Define the variable my $ext = $file; ### Run a match $ext =~ /(\..{3,4}$)/; ### Assign the first capture from the last match $ext = $1; NODE EXPLANATION ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- \. '.' ---------------------------------------------------------------------- .{3,4} any character except \n (between 3 and 4 times (matching the most amount possible)) ---------------------------------------------------------------------- $ before an optional \n, and the end of the string ---------------------------------------------------------------------- ) end of \1 Quote Link to comment Share on other sites More sharing options...
Jabop Posted August 25, 2008 Share Posted August 25, 2008 effigy explains regex nicely. Quote Link to comment Share on other sites More sharing options...
effigy Posted August 25, 2008 Share Posted August 25, 2008 Thank you, but the credits go to YAPE::Regex::Explain. Quote Link to comment Share on other sites More sharing options...
noochies Posted August 25, 2008 Author Share Posted August 25, 2008 Well how stupid do I feel? I apologize about that. This application I adopted has it's front end written in php and the back end written in perl. I guess I got the two temporarily mixed up. WHOOPS. Thanks for all your responses... Quote Link to comment Share on other sites More sharing options...
effigy Posted August 25, 2008 Share Posted August 25, 2008 For more Perl information see learn.perl.org or perlmonks.org. You can also try our Other Languages board, but it is nowhere as comprehensive. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.