Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

RE: RE: variable comparison

by mdillon (Priest)
on May 25, 2000 at 15:38 UTC ( [id://14776]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to RE: variable comparison
in thread variable comparison

i like the substr approach myself, although i would make the small change of using the length function instead of hard coding the length of $ext.
if (substr($filename, -length($ext)) eq $ext) { # do stuff } else { # do other stuff }

Replies are listed 'Best First'.
RE: RE: RE: variable comparison
by Simplicus (Monk) on May 25, 2000 at 16:19 UTC
    Agreed. I've been brainwashed by Redmond to assume that an
    extension is three characters long. My early DOS training
    is to blame for that. (good ol' 8.3 notation, you know?)

    Using a regex to hunt for the dot is out of the question,
    because you might have a filename "foo.bar.htm" for example.
    Of course, you could always look for the last instance of
    the . in the filename, but . . . in the interst of having
    clearer code, I like the substr approach better than the
    regex (if only this once ;-) )
      for finding the last instance of a string in another string, you can use rindex.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://14776]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.