in reply to Quick Regex question

I tried File:Basename, but it didn't do any better than my own regex at removing the path when it was uploaded from a floppy. So long as it is off of C:\, then everything works fine. What's up???

Replies are listed 'Best First'.
Re: Re: Quick Regex question
by repson (Chaplain) on Jan 14, 2001 at 06:32 UTC
    Another function is splitpath from File::Spec.
    use File::Spec; ($volume,$directories,$file) = File::Spec->splitpath( $path ); # process $file
    This will of course work for / (unix), \ (win) and : (mac), unlike your regex. Still so should File::Basename.
Re: Re: Quick Regex question
by Fastolfe (Vicar) on Jan 14, 2001 at 04:24 UTC
    (fastolfe) gemina:~$ cat test use File::Basename; fileparse_set_fstype('MSWin32'); # Because I'm on Unix while (<DATA>) { chomp; printf("%20s %s\n", $_, basename($_)); } __DATA__ a:\pic3.jpg a:\some\dir\pic.jpg a:\some\other\pic \blah\pic. a:\pic a:pic.jpg a:\pic3. (fastolfe) gemina:~$ perl test a:\pic3.jpg pic3.jpg a:\some\dir\pic.jpg pic.jpg a:\some\other\pic pic \blah\pic. pic. a:\pic pic a:pic.jpg pic.jpg a:\pic3. pic3.
    So if File::Basename is working properly, perhaps your input is messed up somehow? Are you reading your filenames from a file perhaps and forgetting to chop off the newline?
      Let me explain in a little more detail what I'm trying to do. I have a form that writes to a text database. In that form, I have file upload fields that are used solely to get filenames for a photographic tour. When the names are written to the database, they have to have their paths chopped off. Those upload fields don't upload images because I couldn't get an upload script working that would upload that many images at once... The filenames are written to a text file (after having their paths chopped off) that tells what files need to be uploaded. Any path works so long as it has some folder in the path. Eg: A:\pic3.jpg would not work, whereas A:\test\pic3.jpg would.
        What was the problem getting the upload images to work? Just use CGI. To the best of my knowledge the only limits are throttles in CGI.pm and/or in the webserver that limit the size/number of uploads to avoid denial of service attacks. If those limits are a problem, they should be configurable and instructions to configure it should be in the documentation.
        If sounds like you just want s/.*\\// or perhaps s!.*[\\/:]!!
        But why do you say that File:Basename did not work?
Re: Re: Quick Regex question
by I0 (Priest) on Jan 14, 2001 at 03:28 UTC
    What was the path when it was uploaded from a floppy?
Re: Re: Quick Regex question
by repson (Chaplain) on Jan 14, 2001 at 06:32 UTC
    Duplicate post.