title: How can I resolve a symbolic link in Perl?
body: <p>I have a symbolic name <em>java</em> or <em>jre</em> or <em>jre1.5</em> or <em>jre1.6</em> or <em>java1.5</em> or <em>java1.6</em> that will point to the respective directory. Taking into account the first instance, it will look like: </p>
  
  <pre><code>   java -&gt; /usr/java/jdk1.5.x.x
  </code></pre>
  
  <p>My aim is as follows:</p>
  
  <ol>
  <li>To check whether the symbolic exists or not</li>
  <li>To get the value of the directory it is pointing</li>
  <li>To use regular expression instead of using if-else statement in the code.</li>
  </ol>
  
  <p>The link will be in <em>/usr/tmp</em>.</p>
  
  <p>I wrote some code in Perl which is as follows:</p>
  
  <pre><code> $filename = "/usr/local/java";
   if (-l $filename) {
          print "File exists \n";
   } else {
          print "Not \n";
   }
  </code></pre>
  
  <p>But in case <em>java</em> is not present and instead <em>java1.4</em> or <em>java1.5</em> is present I want to search which should start with <em>java</em> and is a symbolic link.</p>
  
  <p>Also I need to get the directory that it is pointing. Please advice how to  proceed.</p>