Function - return value?
Posted: 21 Apr 2015 23:35
E.g.:
The first "return $drive" is imho fine, the function exits on the first match.
How should the last return statement look like (I guess the best way is to return an empty string)?
- return;
- return "";
- remove it?
The call to the function looks like:
I don't want the function to return the current path if there is no match for the $vsn parameter because this could lead to a removed virtual filter / quick search...
Is there a better way to handle either the call or the function itself?
Code: Select all
// Resolve the volume serial number and return the corresponding drive letter
function resolveVolumeSerialNumber($vsn) {
foreach($drive, get("drives")) {
$drive = trim($drive, "\", "R");
$match = regexmatches(runret("cmd /c vol $drive", "%windir%"), "[A-Z0-9]{4}-[A-Z0-9]{4}");
if ($match == $vsn) { return $drive; }
}
return "";
}How should the last return statement look like (I guess the best way is to return an empty string)?
- return;
- return "";
- remove it?
The call to the function looks like:
Code: Select all
$serial = "1ECD-8A2C";
$dst = resolveVolumeSerialNumber($serial);
if ($dst) { goto $dst; }
Is there a better way to handle either the call or the function itself?