Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # usage echo "/Applications/Google Earth.app/Contents/MacOS/Google Earth -psn_0_935678236" | ./this.pl
- $l = <STDIN> ;
- if ($l =~ /^\/.+/) {
- chomp $l;
- $cp = "";
- @v = split (/\//, $l);
- $i = 0;
- foreach $pc (@v) {
- $tp = $cp;
- if ($i) {
- $tp .= "/$pc";
- } else {
- $tp .= "$pc";
- }
- if ( -x $tp ) {
- $cp = $tp;
- }
- $i++;
- }
- $cp .= "/";
- $end = $v[$#v];
- @words = split(/\s+/, $end);
- $tp = $cp;
- $i = 0;
- foreach $w (@words) {
- if ($i == 0) {
- $tp .= "$w";
- } else {
- $tp .= " $w";
- }
- if ( -x $tp ) {
- $cp = $tp;
- last;
- }
- $i++;
- }
- print "$cp\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement