… | |
… | |
6 | |
6 | |
7 | use Guard; |
7 | use Guard; |
8 | |
8 | |
9 | # temporarily chdir to "/etc" directory, but make sure |
9 | # temporarily chdir to "/etc" directory, but make sure |
10 | # to go back to "/" no matter how myfun exits: |
10 | # to go back to "/" no matter how myfun exits: |
11 | sub dosomething { |
11 | sub myfun { |
12 | scope_guard { chdir "/" }; |
12 | scope_guard { chdir "/" }; |
13 | chdir "/etc"; |
13 | chdir "/etc"; |
14 | |
14 | |
15 | call_function_that_might_die_or_other_fun_stuff; |
15 | call_function_that_might_die_or_other_fun_stuff; |
16 | } |
16 | } |
… | |
… | |
176 | Marc Lehmann <schmorp@schmorp.de> |
176 | Marc Lehmann <schmorp@schmorp.de> |
177 | http://home.schmorp.de/ |
177 | http://home.schmorp.de/ |
178 | |
178 | |
179 | =head1 THANKS |
179 | =head1 THANKS |
180 | |
180 | |
181 | To Marco Maisenhelder, who reminded me of the C<$Guard::DIED> solution to |
181 | Thanks to Marco Maisenhelder, who reminded me of the C<$Guard::DIED> |
182 | the problem of exceptions. |
182 | solution to the problem of exceptions. |
183 | |
183 | |
184 | =cut |
184 | =cut |
185 | |
185 | |