morgon has asked for the wisdom of the Perl Monks concerning the following question:
recently I've done things like this (sorry, I am a bit drunk and too lazy to look up the actual code - but you get the gist...):
And I was wondering if there was a better way to do this, some kind of Groovy "safe navigation" operator that would allow one to write:my $subtree = $dom->find($whatever); $subtree->delete if $substree;
i.e. a method-invocation that would check if the receicer was defined at all and simply does nothing if the receiver is undefined.#pseudo-code - does not run!!! $dom->find($whatever)?->delete;
I ask because something in the back of my mind tells me that I may have heard something to this effect at a conference, but as I said - I am a bit drunk...
Many thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: safe navigation in perl?
by marto (Cardinal) on Dec 17, 2017 at 09:30 UTC | |
|
Re: safe navigation in perl?
by AnomalousMonk (Archbishop) on Dec 17, 2017 at 04:31 UTC | |
|
Re: safe navigation in perl?
by Your Mother (Archbishop) on Dec 17, 2017 at 05:37 UTC | |
|
Re: safe navigation in perl?
by choroba (Cardinal) on Dec 17, 2017 at 13:44 UTC | |
|
Re: safe navigation in perl?
by marto (Cardinal) on Dec 27, 2017 at 15:34 UTC |