Grammar question: having had

Please explain to me the difference, if there is one, between:
“After begging for a living, John was happy with his free luxury penthouse”
and
“After having had to beg for a living, John was happy with his free luxury penthouse”

The second sentence emphasizes the forced or coerced nature of the begging. The first simply states that he did so. Similar to “I left the party,” vs. “I had to leave the party.”

Actually, the main difference here is in the content of the “lead” verb in the first part of the sentence. The first sentence has ‘beg’ while the second has ‘have to’. Besides that, there’s the aspect difference, with the first sentence having a present participle and the second a past participle.

Perhaps you wanted to know the difference between a sentence where the verb is in the present participle and one where it’s in the past participle. Thus:

“After begging for a living, John was happy with his free luxury penthouse”

“After having begged for a living, John was happy with his free luxury penthouse”

Both forms of the non-finite verb (‘begging’ and ‘having begged’) contain a continuous element (represented by -ing), which typically conveys a meaning of temporariness (compare “I live in Parkview” with “I’m living in Parkview”). The past form ‘begged’ adds a ‘perfective’ (or completed) element. But since this element of completion is already marked lexically by the word ‘after’, it’s really redundant. So, the upshot is that both forms carry very similar meanings in a context such as the one you present.

Thankyou Roger, most informative. Is the second sentence in the OP incorrect, then?

The second form isn’t technically incorrect, I don’t think.

We can turn the sentence around a bit:

John was happy with his free luxury penthouse after having had to beg for a living.

Within the X-bar schema it’s easy to tree the sentence, and the results follow the predictive pattern of linguistics. “Having” is serving as the specifier for “had”, and prepositional phrases are one of the complements allowed to follow a verb.

Having said that, I would write the sentence as:

John was happy with his free luxury penthouse after having to beg for a living.

It conveys the same idea with less confusion. We could still turn it back around and say:

After having to beg for a living, John was happy with his free luxury penthouse.

To me, it becomes a style choice rather than one of grammar.

No, it’s fine. As MLS points out, it just means that circumstances forced upon John the necessity of begging. One could also write “After having to beg for a living…”, to sort of complete the set.

Having decided to eat only natural foods, he had to give up all of his favorite junk food.

The second sentence is slop, and no decent writer would use it.

It is, technically speaking, grammatically “correct,” but is so off the mark in terms of style that it is as good as incorrect. In the same way that the following sentence is “correct”: “He has not ever needed to have to be required to have done so.” The parts are each used correctly but the whole is crap.

It is also a tricky example in that it is hard to imagine a context in which the first half of the sentence would be written as is. The “having had” without a time adverb is what, in the end, makes the clause seem quite odd.

The other odd thing here, I think, is that in the phrase “having had” the “had” usually does not mean “must” but is used in some other sense: “Having had bad luck for the past ten years, Joe was elated to find a dime on the sidewalk.”

Basically the meaning is, “John had to beg, so now he enjoys his free penthouse.” As other posters here have noted, there are infinite ways of expressing this. The “having had,” at best, seems forced.