Try the following instead:
unless(open TST, ">>$var1") { One(); Two(); exit; # or die "Failed to open $var1: $!"; } # rest of code here.
Then, if open fails you'll execute all the code in the block and then exit, which is what you're trying to do.

I alse get 1 at C:\Dev\MiscTests\sub.pl line 8
die is a function that takes a string and exits the program printing that message out with the line number and script name. In this case die is getting the result of your do{} as its string and printing it: "1". The result of your do just happens to be the return value of your subroutine Two, which is 1. (print returns 1 if it printed, and if there is no explicit return, the value of the last line (of code) in a subroutine is the return value).

If you try my suggestion from above, you won't get that any more.

Hope it helps.

jarich

Short answer to below
Yes, you're entirely correct. if( !cond ) is identical to unless( cond ). unless( cond ) { ...... } else { ......} is also legal (although there is no elsunless) but I'd encourage you to change any unless-then-else structures you might be tempted to write into if-then-else because that is much easier to read (mostly because that's what everyone else expects to see).

I prefer unless because I find that sometimes I don't see the ! in if( !$foo ). Readability kinda depends on the reader. unless does take more character presses...


In reply to Re: Run 2 Subroutines after a die by jarich
in thread Run 2 Subroutines after a die by AcidHawk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.