c0d34w4y has asked for the wisdom of the Perl Monks concerning the following question:
I was thinking of a code to split a given directory path (e.g. 'foo/bar/rab/oof') and retreave all parent directories to receive something like this: 'foo' 'foo/bar' 'foo/bar/rab' 'foo/bar/rab/oof' The code I came up with is as follows:(here's a quick test for 'perl -e' command:sub get_parents { my (@p, $o); for (split ("/",$_[0])) {push(@p,"$o/$_");$o.="/$_"} return \@p; }) However, is there any better/quicker way of doing the same thing? I know it does sound rather trivial... Thankx.perl -e '$p="foo/bar/rab/oof";for (split ("/",$p)) {push(@p,"$o/$_") +;$o.="/$_"} print join("|",@p);'
print join(" ", map { sprintf "%#02x", $_ }unpack("C*",pack("L",0x1234 +5678)))
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: No other way?
by perrin (Chancellor) on Dec 13, 2001 at 03:20 UTC | |
|
(Ovid) Re: No other way?
by Ovid (Cardinal) on Dec 13, 2001 at 02:41 UTC | |
by c0d34w4y (Acolyte) on Dec 13, 2001 at 02:51 UTC | |
by chip (Curate) on Dec 13, 2001 at 03:57 UTC | |
by blakem (Monsignor) on Dec 13, 2001 at 08:01 UTC | |
by greenFox (Vicar) on Dec 13, 2001 at 22:52 UTC | |
by chip (Curate) on Dec 14, 2001 at 01:40 UTC |