in reply to File::Basename and File::MMagic for File Downloads from Website

I don't know about all file systems — we had a computer whose file system consisted of a piece of a paper with file names and sector addresses at my last job — but File::Basename treats at least "\" (Windows), "/" (unix and Windows) and ":" (old Macs) as separators.

>perl -MFile::Basename -le"print basename 'foo/bar'" bar >perl -MFile::Basename -le"print basename 'foo\bar'" bar >perl -MFile::Basename -le"print basename 'foo:bar'" bar

File::Basename's behaviour is not determined by the system on which the script is executed.

Replies are listed 'Best First'.
Re^2: File::Basename and File::MMagic for File Downloads from Website
by agent00013 (Pilgrim) on Nov 21, 2008 at 00:53 UTC
    I am not getting the same results. On my Debian machine, I get the following output using some of the examples.
    > perl -MFile::Basename -le "print basename 'foo/bar'" bar > perl -MFile::Basename -le "print basename 'Z:\my_files\docs\some_kin +d_of_manual.pdf'" Z:\my_files\docs\some_kind_of_manual.pdf > perl -MFile::Basename -le "print basename '/home/someguy/file.txt'" file.txt

      Sorry, it had been a while. It does behave in a system-specific fashion.

      Technically, what you ask is impossible. 'foo\bar' should return 'foo\bar' if a unix path and 'bar' if a Windows path, but you don't know what kind of path your client built. That means you might as well roll out code that does what you want it to do.

      my $basename = ( split /[:\/\\]/, $_ )[-1];
Re^2: File::Basename and File::MMagic for File Downloads from Website
by MidLifeXis (Monsignor) on Nov 21, 2008 at 14:44 UTC
    we had a computer whose file system consisted of a piece of a paper with file names and sector addresses at my last job

    How long has it been since you have changed jobs? My architecture professor used that as an example of how the OS has come to mask out the hardware differences at least 15 years ago. The example he was using was from long before that, in his younger days.

    --MidLifeXis (not sure if he is hiding grey in his blond locks yet)

      Recently, but that's not relevant. Said computer is still in use, controlling a nuclear reactor. It's a replica of a 1972 computer. (36 years!) It has 64KB of RAM, but since it's only word addressable, it has only 32K addresses. I can't remember what it has for disk space, but we're talking about a few of MB max. (I think 3MB up from an original 1MB.)

      It has a custom made OS called "the Executive" or "EXEC" after it's file name. You can't exactly load linux on it. EXEC provided I/O functions and some library functions. A file system was deemed unnecessary.

      Alarming (logging) is done to a CRT (which won't clear even if something happens to the computer) and to a printer. The computer can also talk to PC that pretends to be a paper tape device.