New to programming, I've held the (self imposed) notion that the less lines (of code), the better. Thus, when programming something, rather than having separate variables for pieces, I've been nesting all that I can into a line. For example:
preg_match('~><a href=~', substr(file_get_contents($match[1])), strpos($match[1], "help")), $match_rating)
Would it be more professional/generally-preferable to break the line above into separate variable chunks, so that it looks more like:
preg_match($regExp, $bigString, $matches)
..With each variable/piece being defined above with its own line (and variable)?
I've wondered if this isn't really better or more efficient, since it seems like it would make it difficult for someone else to read and decipher it. I realize it's probably a personal preference type deal, but is there a generally held (professional) standard of which side to lean toward?
Your first and foremost goal should be producing readable code that statest your intent clearly (using common idioms).
Your second goal should be to ensure your program works as intended (keeping goal 1 in mind).
If you fulfilled the first to goals and you find that there is a performance/memory problem, then you need to think how you can make the code more efficient. If you get to this part the first step is to measure where the problem is; then fix that one part (possibly deviating from goal 1 above) -- rinse-and-repeat if there are still performance/memory issues.
In your particular example it is often beneficial to store partial expressions in variables (e.g. you can inspect them readily in a debugger or print them out when debugging). If you have a decent compiler, this should not impact efficiency much (the compiler can optimize your code if needed).
Also, it is preferable to keep lines short, so they are easy to read. Your first code sample should -- at least -- be broken into multiple lines (even if keeping the one expression)
If you use variables for storing partial expression results, choose names that indicate the role of that variable -- if there are multiple reg.ex's you could be using, chose a name that indicates which one that is. This way you will help your readers understand your intent better
Note: ordering of 1) and 2) is taste dependent, but if you go for "correctness" disregarding "readability", you will find yourself having a hard-to-understand, thus hard-to-debug and hard-to-maintain code