title: Use of uninitialized value $1 in addition - Perl
body: <p>I am writing a program that somewhat mimics the last command in UNIX, and I am trying to use backreferencing in my solution. My program does exactly what it is supposed to do but I get a run time error/warning. My question is why is this error/warning coming up and how can I fix an issue like this?</p>
  
  <p>If you need more information I can provide.</p>
  
  <p>Program Execution</p>
  
  <pre><code>./last dodoherty
  </code></pre>
  
  <p>OUTPUT</p>
  
  <pre><code>Here is a listing of the logins for dodoherty:
  
  1. dodohert pts/1        pc-618-012.omhq. Wed Feb  8 09:19   still logged in
  2. dodohert pts/6        ip98-168-203-118 Tue Feb  7 19:19 - 20:50  (01:31)
  3. dodohert pts/3        137.48.207.178   Tue Feb  7 14:00 - 15:06  (01:05)
  4. dodohert pts/1        137.48.219.250   Tue Feb  7 12:32 - 12:36  (00:04)
  5. dodohert pts/21       137.48.207.237   Tue Feb  7 12:07 - 12:23  (00:16)
  6. dodohert pts/11       ip98-168-203-118 Mon Feb  6 20:50 - 23:29  (02:39)
  7. dodohert pts/9        ip98-168-203-118 Mon Feb  6 20:31 - 22:57  (02:26)
  8. dodohert pts/5        pc-618-012.omhq. Fri Feb  3 10:24 - 10:30  (00:05)
  Use of uninitialized value $1 in addition (+) at ./odoherty_last.pl line 43.
  Use of uninitialized value $2 in addition (+) at ./odoherty_last.pl line 44.
  Here is a summary of the time spent on the system for dodoherty:
  
  dodoherty
  8
  8:6
  </code></pre>
  
  <p>The Code (Snippet of where the error is coming from, Also this is the only time $1 and $2 are used.)</p>
  
  <pre><code>foreach my $line2 (@user)
  {
          $line2 =~ /\S*\((\d{2,2})\:(\d{2,2})\)\s*/;
          $hours = $hours + $1;
          $mins = $mins + $2;
  
          if( $mins &gt;= 60 )
          {
                  $hours = $hours + 1;
                  $mins = $mins - 60;
          }
  }
  </code></pre>