Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: File::Spec::Win32 returning different result than File::Spec when doing catfile with empty string

by nysus (Parson)
on Sep 08, 2019 at 05:49 UTC ( [id://11105822]=note: print w/replies, xml ) Need Help??


in reply to Re: File::Spec::Win32 returning different result than File::Spec when doing catfile with empty string
in thread File::Spec::Win32 returning different result than File::Spec when doing catfile with empty string

Well, I want the trailing slash. It's needed in the context of my algorithm, currently. catdir on *nix does not create a trailing slash. I can recode my algorithm pretty easily but I thought it was weird that the same method produces two separate results.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

  • Comment on Re^2: File::Spec::Win32 returning different result than File::Spec when doing catfile with empty string

Replies are listed 'Best First'.
Re^3: File::Spec::Win32 returning different result than File::Spec when doing catfile with empty string
by jcb (Parson) on Sep 08, 2019 at 05:52 UTC

    If you improve your algorithm to process directories as arrays of name components instead of copying back to strings, it will not be a problem any more and your algorithm should be faster, too.

    As for the odd behavior, I suspect that it was needed for portability to some oddball half-broken commercial Unix back in the 5.005 era. :-)

      Yeah, I thought about processing an array but I would still have to use File::Spec to split the file path and I could just feel it in my bones that there would still be some weird cross-platform issue lingering and I just want to go to bed. So I just did letter-by-letter comparison. Speeding it up will have be a task for another day.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

Re^3: File::Spec::Win32 returning different result than File::Spec when doing catfile with empty string
by davido (Cardinal) on Sep 09, 2019 at 15:17 UTC

    Conceptually directory structures are trees, and paths are lists of nodes that represent traversal(1). When you think of things that way instead of strings with slashes, life becomes easier, and common tools tend to just work. Pushing to the boundaries of your application as much representational decoration as possible, and internally working with more native data structure types is a principal that doesn't only apply to data serialization formats, it also applies to filesystem paths.

    Your algorithm should be working with lists of directory names and file names, and converting to slash-delimited strings at the ingress and egress boundaries.

    (1) Actually many file systems are directed acyclic graphs, thanks to concepts such as hard linking, but conceptually we can treat them like heirarchical data structures, keeping in mind that it's possible for a node in the tree to point to any other node anywhere else in the tree. ...so the tree concept does sort of break down, but is a useful white lie.


    Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11105822]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-25 02:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found