title: Declaring variables in Perl
body: <p>I'm learning Perl, and facing some inconsistency between running a program from the command line versus interactively executing it interactively in the debugger.</p>
  
  <p>Specifically, I invoke the Perl debugger with <code>perl -d -e 1</code>, and run this code line-by-line</p>
  
  <pre><code>my $a = 1;
  print $a;
  
  $b = 2;
  print $b;
  </code></pre>
  
  <p>In the output I am only seeing the value of <code>$b</code>, while <code>$a</code> seems to be undefined. At the same time, when I execute the same statements with <code>perl myscript.pl</code>, both values are shown in the output. Why does this happen? What am I missing? </p>