\$"=q;grep;;\$,=q"grep";for(`find . -name ".saves*~"`){s;\$/;;;/(.*-(\d+)-.*)\$/; \$_=["ps -e -o pid | "," \$2 | "," -v "," "];`@\$_`?{print"+ \$1"}:{print"- \$1"}&&`r m \$1`; print\$\;} ##```## \$"=q; grep;;\$,=q"grep"; for(`find . -name ".saves*~"`){ s;\$/;;; /(.*-(\d+)-.*)\$/; \$_=["ps -e -o pid | "," \$2 | "," -v "," "]; `@\$_` ? {print"+ \$1"} : {print"- \$1"} && `rm \$1`; print \$\; } ##``````## 1: \$"=q; 2: 3: grep;;\$,=q"grep"; 4: 5: for(`find . -name ".saves*~"`){ 6: s;\$/;;; 7: /(.*-(\d+)-.*)\$/; 8: \$_=["ps -e -o pid | "," \$2 | "," -v "," "]; 9: `@\$_` ? {print"+ \$1"} : {print"- \$1"} && `rm \$1`; 10: print \$\; 11: } ##``````## perl -e '@a = qw (a bc def); print "before: @a\n"; \$"=q; print "after: @a\n";' Output: before: a bc def ##``````## perl -MO=Deparse -e '@a = qw (a bc def); print "before: @a\n"; \$"=q; print "after: @a\n";' Output: @a = ('a', 'bc', 'def'); # ok, I agree print "before: @a\n"; # yep, still with ya \$" = ' print "after: @a\\n"'; # whoa, this is unexpected -e syntax OK # good news, I guess ##``````## \$"=q;grep;; \$,=q"grep"; ##``````## \$" = 'grep'; \$, = 'grep'; ##``````## 1: \$"= 'grep' ; 2: \$,= 'grep' ; 3: 4: for(`find . -name ".saves*~"`){ 5: s;\$/;;; 6: /(.*-(\d+)-.*)\$/; 7: \$_=["ps -e -o pid | "," \$2 | "," -v "," "]; 8: `@\$_` ? {print"+ \$1"} : {print"- \$1"} && `rm \$1`; 9: print \$\; 10: } ##``````## / # start of pattern match ( # begin storing into \$1 .* # store any number of any character... - # ...followed by a hyphen... ( # begin storing into \$2 \d # ...any digit... + # ...as many as we can grab... ) # stop storing into \$2 - # ...followed by another hyphen .* # ...followed by any number of any character... ) # stop storing into \$2 \$ # end of the line, bub /x; # / to terminate regex, x to allow comments ##``````## @command = "ps -e -o pid | grep \$2 | grep -v grep "; \$ar_command = \@command; ##``````## perl -e '\$foo = 0; \$foo==0 ? print "foo is zero" : print "foo is non-zero";' Output: foo is zero ##``````## \$foo = 0; if ( \$foo == 0 ) { print "foo is zero" ; } else { print "foo is non-zero" ; } ##``````## if ( `@\$_` ) { print "+ \$1"; } else { print "- \$1" && `rm \$1`; } ##``````## my \$owner_is_still_running = `@\$_`; # search for a specific \$pid if ( \$owner_is_still_running ) { print "\$owner_is_still_running, keeping \$1"; # found \$pid, keep tempfile } else { print "removing \$1"; # didn't find \$pid `rm \$1`; # remove \$pid's tempfile } ##``````## #!/usr/bin/perl use strict; use warnings; # find files that match the naming convention my @files = `find . -name ".saves*~"`; foreach ( @files ) { chomp; # hold onto filename, and extract creator's pid / # start of pattern match ( # begin storing into \$1 .* # store any number of any character... - # ...followed by a hyphen... ( # begin storing into \$2 \d # ...any digit... + # ...as many as we can grab... ) # stop storing into \$2 - # ...followed by another hyphen .* # ...followed by any number of any character... ) # stop storing into \$2 \$ # end of the line, bub /x; # / to terminate regex, x to allow comments my ( \$filename, \$creator_pid ) = ( \$1, \$2 ); # Check process stack for the creator's pid, storing command result my \$command = "ps -e -o pid | grep \$creator_pid | grep -v grep"; my \$command_result = `\$command`; # if the command result is positive, leave \$filename alone... # ... otherwise, remove \$filename if ( \$command_result ) { print "+ \$filename\n"; } else { print "- \$filename\n"; `rm \$filename`; } } ```