Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you want to split up path elements, look at <a href="http://search.cpan.org/dist/File-Spec" rel="nofollow noreferrer">File::Spec</a> or <a href="http://search.cpan.org/dist/Path-Class" rel="nofollow noreferrer">Path::Class</a>, which handle all of the operating system specific stuff:</p> <pre><code> use File::Spec; my( $root, @path_parts ) = File::Spec-&gt;splitdir( $path ); </code></pre> <p>The nice thing about keeping the root is that you can go backward easily and still keep that leading slash (or whatever your opearting system might use):</p> <pre><code> my $path = File::Spec-&gt;catfile( $root, @path_parts ); </code></pre> <p>This isn't such a big deal with URLs since they all use a unix-like path specification. Still, it's easy to construct the local path in the same way, and remember where the root is (which may be important on Windows, VMS, etc):</p> <pre><code> my ($docroot_root, @doc_root ) = File::Spec-&gt;splitdir( $ENV{DOCUMENT_ROOT} ); my $local_path = File::Spec-&gt;catfile( $docroot_root, @doc_root, @path_parts ); </code></pre> <p>Otherwise, you're stuck with what split does. It assumes that you care about the position of fields, so it preserves their position (i.e. the thing before the first separator is always position 0 in the list, even if it is empty). For your problem, I tend to write it as a list assignment where I use a variable to soak up the initial empty field, just like I'd do with </p> <pre><code> my( $root, @path_parts ) = split m|/|, $path; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload