title: One liner to access an array element in perl?
body: <p>I have the following:</p>
  
  <pre><code>my @path = split( "/", getcwd );
  my $grandParent = $path[-2];
  </code></pre>
  
  <p>I'd like to do it in one line (like in other languages) since I'm not using @path again, like so:</p>
  
  <pre><code>my $grandParent = split( "/", getcwd )[-2];
  </code></pre>
  
  <p>Is this possible? If so, how?</p>
  
  <p>EDIT: Just to be clear - where I am running the script from I know some things are going to be invariant (the directory structure, names, etc). This being said, validation is nice, but in this scenario is more clutter than it is worth; thanks to those who submitted solutions with error checking any ways.</p>