I’m trying to change some lines of perl to python and I’m struggling to understand
what’s going on in the perl code. Any help would be greatly appreciated.
thanks!
my($junk1, $filename, $junk2) = $mydir =~ m/(.*\\)(.*\\)(.*)/;
$filename =~ s/\\//;
print $out $filename, "\n";
The first line (with
m/(.*\\)(.*\\)(.*)/splits$mydirinto three components, the first two ending in backslash.For example if
$mydirwasAsdf\fdsa\jkl, the first line sets$junk1 = Asdf\,$filename = fdsa\,$junk2 = jkl.The line
takes
$filename(fdsa\) and removes the last backslash (the syntax iss/stuff_to_match/stuff_to_substitute_with/).In python you can use the
remodule to do regex stuff, or in this case it looks like you could just split on backslash, removing the need for regex.