Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #!/usr/bin/perl
  2. # usage echo "/Applications/Google Earth.app/Contents/MacOS/Google Earth -psn_0_935678236" | ./this.pl
  3. $l = <STDIN> ;
  4.  
  5. if ($l =~ /^\/.+/) {
  6. chomp $l;
  7. $cp = "";
  8. @v = split (/\//, $l);
  9. $i = 0;
  10. foreach $pc (@v) {
  11. $tp = $cp;
  12. if ($i) {
  13. $tp .= "/$pc";
  14. } else {
  15. $tp .= "$pc";
  16. }
  17.  
  18. if ( -x $tp ) {
  19. $cp = $tp;
  20. }
  21. $i++;
  22. }
  23.  
  24. $cp .= "/";
  25. $end = $v[$#v];
  26.  
  27. @words = split(/\s+/, $end);
  28. $tp = $cp;
  29. $i = 0;
  30. foreach $w (@words) {
  31. if ($i == 0) {
  32. $tp .= "$w";
  33. } else {
  34. $tp .= " $w";
  35. }
  36. if ( -x $tp ) {
  37. $cp = $tp;
  38. last;
  39. }
  40. $i++;
  41. }
  42.  
  43. print "$cp\n";
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement