Tuesday, April 24, 2007

Cool path splitter in Perl



Oh, this one is so neat: A little Perl regexp to get the path and filename from a string:


my($text) = "/etc/sysconfig/network-scripts/ifcfg-eth0";
my($directory, $filename) = $text =~ m/(.*\/)(.*)$/;
print "D=$directory, F=$filename\n";