in reply to Comparing depth-indent tree to full-paths

Define 'fast' and/or 'timely manner'. I guarantee the following will complete before lunch time:

use strict; use warnings; my @dirs; while (my $line = <DATA>) { my ($indent, $entry, $isDir) = $line =~ m!^(\s*)([^/]*)(/|\\)?!; next unless defined $entry and length $entry; my $depth = length ($indent); if ($depth < @dirs) { splice @dirs, $depth, $#dirs; } if ($isDir) { push @dirs, $entry; next; } print join ('/', @dirs, $entry); } __DATA__ base/ dir1/ file1.txt a.png dir2/ b.txt q.txt dir3/ a.png f.txt

Prints:

base/dir1/file1.txt base/dir1/a.png base/dir1/dir2/b.txt base/dir1/q.txt base/dir3/a.png base/f.txt

Update: using jdporter's assign to $#array technique the code reduces to:

use strict; use warnings; my @dirs; while (my $line = <DATA>) { my ($indent, $entry, $isDir) = $line =~ m!^(\s*)([^/]*)(/|\\)?!; next unless defined $entry and length $entry; $#dirs = length $indent; $dirs[-1] = $entry; next if $isDir; print join '/', @dirs; }

True laziness is hard work