Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

It might help to give us some runable code. I started by writing this, but the folder IDs don't match up.

my %folders = ( 4464 => 'foldername_1', 4465 => 'foldername_2', 4466 => 'foldername_3', ); my @subfolders = split /\n/, <<'SUBFOLDER_LIST'; Folder 1298 - foldername_ten. subfolder 1299. subfolder 1300. Folder 1299 - foldername_eleven. No sub folders. Folder 1300 - foldername_twelve. No sub folders. Folder 1311 - foldername_thirteen. subfolder 1317. subfolder 1318. subfolder 1958. SUBFOLDER_LIST ;

Off the topic of your question, one thing I notice about your code is that build_path is defined with a prototype (which is usually a bad idea), and then you call it with an ampersand sigil which bypasses the prototype anyway. Unless there's more code somewhere that requires the prototype to be in effect, I'd suggest you get rid of it and call build_path normally (without the ampersand).

I'm not entirely clear on the question you're trying to answer. It seems as if you're saying that build_path could return more than one path for a given folder ID. If that's the case, I'd say have it return a reference to an array rather than a simple string. Later, when you walk through %folderpaths, you can create the first path listed and make the others symbolic links to it. The code below is supposed to give you an idea of what I'm talking about.

use Data::Dumper; sub mock_build_path { my $folderid = shift @_; my @dumpff = @_; my @paths; push @paths, 'example/1'; push @paths, 'example/2'; push @paths, 'example/3'; return \@paths; } my %folderpaths; $folderpaths{ '1337' } = mock_build_path( 1234, 'stuff' ); print Dumper \%folderpaths; my ( $mkpath, @linkpaths ) = @{ $folderpaths{ '1337' } }; print "make path: $mkpath\n"; print "link paths: ", join( q{, }, @linkpaths ), "\n"; __END__ $VAR1 = { '1337' => [ 'example/1', 'example/2', 'example/3' ] }; make path: example/1 link paths: example/2, example/3

This requires the use of references, which I don't see in the code you've posted. If you're not familiar with references, have a look at Perl reference tutorial, Perl References, and References quick reference (links I took from the home node of kennethk, which has a lot of other good information on it).

I hope this helps.


In reply to Re: Building a UNIX path from Irritating data by kyle
in thread Building a UNIX path from Irritating data by roswell1329

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2024-04-24 09:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found