title: Checking if file exists then if not, PERL
body: <hr>
  
  <p>I'm needing help with a PERL script which i'm trying to do the following on a irc bot: </p>
  
  <ul>
  <li>on user command see if file exists.</li>
  <li>If not exists create new file then print value "1".</li>
  <li>if exists goto next stage.</li>
  <li>get the file information inside the file, which is a number.</li>
  <li>information + 1 then print into a new file, same name.</li>
  </ul>
  
  <p>here is the script:</p>
  
  <pre><code>        my ($who,$channel,$message) = @_;
  my @things = split(' ', $message);
              my @args = @things[1..$#things];
  </code></pre>
  
  <hr>
  
  <pre><code>        if ($message =~ /^&amp;cookie/i &amp;&amp; @args[0..$#args]) {
  
      if ( -s '@args[0..$#args].txt') { $varr = 1; goto varrr;
      } else {
      open (USER, "&gt;", "@args[0..$#args].txt") or die "failed: $!";
      my $sum = 1;
      print USER "$sum";
      close (USER);
      }
         varrr:
         if ($varr == 1) {
      open (USER, "&lt;@args[0..$#args].txt");
      while (my $use = &lt;USER&gt;) {
      my $sum = 1;
      my $newuse = ($use + $sum);
  
      close (USER);
  
      open (USER, "&gt;@args[0..$#args].txt");
      my $usee = $use + 1;
      print USER "$newuse\n";
      close (USER);
      print $sock "PRIVMSG $channel :You have given @args[0..$#args] a cookie! \n";
      $varr = 0;
      }
      }
      }
      elsif ($message =~ /^&amp;cookie/i) {
      print $sock "PRIVMSG $channel :Invalid parameter, use &amp;cookie [name]. \n";
      }
  </code></pre>
  
  <hr>
  
  <p>edit:</p>
  
  <p>fixed, goto had to remain, thank you guys :)</p>
  
  <p>[edit] </p>
  
  <p>D: I must of had a file called what I tested it on, if the file doesn't exist it now no longer will create the file, now what? I've only had 3 days experience with perl.</p>
  
  <p>also tried: </p>
  
  <pre><code>        if ($message =~ /^&amp;cookie/i &amp;&amp; @args[0..$#args]) {
  
  unless ( -s '@args[0..$#args].txt') { $varr = 1;
  } else {
  open (USER, "&gt;", "@args[0..$#args].txt") or die "failed: $!";
  my $sum = 1;
  print USER "$sum";
  close (USER);
  }
     varrr:
     if ($varr == 1) {
  open (USER, "&lt;@args[0..$#args].txt");
  while (my $use = &lt;USER&gt;) {
  my $sum = 1;
  my $newuse = ($use + $sum);
  
  close (USER);
  
  open (USER, "&gt;@args[0..$#args].txt");
  my $usee = $use + 1;
  print USER "$newuse\n";
  close (USER);
  print $sock "PRIVMSG $channel :You have given @args[0..$#args] a cookie! \n";
  $varr = 0;
  }
  }
  }
  </code></pre>