auto scope question?

WhatMeWorry kheaser at gmail.com
Tue Oct 25 22:07:15 UTC 2022


I'm naturally getting a undefined identifier `s` error in the 
return.  Is there some way to refactor my code?  I tried to 
declare s outside of the else brackets like:

auto screen = executeShell(cmdLine);
auto s;
...
{
     s = screen.output.findSplit("REG_SZ");
}

but that doesn't compile either.



string[] getPath(string cmdLine)
{
     auto screen = executeShell(cmdLine);
	
     if (screen.status != 0)
     {
         writeln(cmdLine, " failed");
     }
     else
     {
         writeln("screen.output = ", screen.output);	
	auto s = screen.output.findSplit("REG_SZ");
         writeln("s[0] = ", s[0]);
         writeln("s[1] = ", s[1]);
         writeln("s[2] = ", s[2]);		
     }
     return (s.split(';'));  // Error: undefined identifier `s`
}


More information about the Digitalmars-d-learn mailing list