title: how to combine directory path in perl
body: <p>I am having a perl script in which i am giving path to directory as input.
  Directory has xml files inside it.</p>
  
  <p>In my code i am iterating through all the xml files and creating absolute path for all xml files. Code is working fine. </p>
  
  <pre><code>#!/usr/bin/perl
  
  use File::Spec;
  
  $num_args = $#ARGV + 1;
  if ($num_args != 1) {
     print "\nUsage: $0 &lt;input directory&gt;\n";
     exit;
  }
  
  my $dirPath = $ARGV[0];
  
  opendir(DIR, $dirPath);
  my @docs = grep(/\.xml$/,readdir(DIR));
  
  foreach my $file (@docs) 
  {
     my $abs_path = join("",$dir,$file);
  
     print "absolute path is $abs_path";
  }
  </code></pre>
  
  <p>Question i have here is, 
  joining $dirPath and $file with no separator which means that $dirPath must end in a "/". So is there any way or built in function in perl which take cares of this condition and replaces the join method.</p>
  
  <p>All i want is not to worry about the separator "/". Even if script is called with path as "/test/dir_to_process" or "/test/dir_to_process/", i should be able to produce the correct absolute path to all xml files present without worrying about the separator.</p>
  
  <p>Let me know if anyone has any suggestions.</p>