MajingaZ has asked for the wisdom of the Perl Monks concerning the following question:

Actual Location: \\Server\Volume\Text\001\ABC001.txt

Server Location Variable, $A contains \\Server\Volume\LoadFiles

FilePath Variable, $B contains E:\Volume\Text\001\ABC001.txt

I want to modify $A and store the replacement value for $B so that $A\$BPrime would give me the file.

$BMinus in this case should be E:\
$BPrime is Text\001\ABC001.txt
$A is \\Server\Volume

What I have is this: I would love to get some feedback as to what I might have done differently or alternatives. Cause this still seems a bit cludgy.

my $BMinus = substr ($B, 0, (index ($B,&CheckFile(\$A,$B)) - 1)); sub CheckFile { my ($P_ref,$T) = @_; &CrawlForward($P_ref,\$T); while (!(-s "$$P_ref\\$T") || (-s $T)) { $$P_ref =~ s/\A(.+)\\[^\\]+\z/$1/; &CrawlForward($P_ref,\$T); } return $T; } sub CrawlForward { my ($C_ref,$T_ref) = @_; my $FHold = $$T_ref; while (!-s "$$C_ref\\$$T_ref") { unless ($$T_ref =~ s/\A[^\\]+\\(.+)\z/$1/) { $$T_ref = $FHold; last; } } return 1; }

Update: I changed the .+? to [^\\]+ to be more self documenting as that is what I'm actually expecting but was relying on the greediness on .+ and laziness on .+? to get what I wanted, so this makes it easier to read.

Replies are listed 'Best First'.
Re: Merge a UNC Dir with a Mapped File
by roboticus (Chancellor) on Jul 28, 2010 at 23:25 UTC

    MajingaZ:

    I'm sorry, but I can't make heads or tails out of your post. The title, code and text seem to have little relationship to each other. You should probably read: I know what I mean. Why don't you?

    ...roboticus

    Update: On second reading, I can see the relationship. I missed a line in the code. Sorry.