0

I'm writing a python script using regex expressions and I found what is needed in perl, but as I am not strong in perl I don't clearly understand what is written. Here is the code:

'\\b' . $2 .'\\b.{0,15}' . $3 . '[^\\d]{0,5}' . $4 . ((defined $5) ? '[^\\d]{0,5}' . $5 : ''

The problem is mainly in the of line where it checks if $5 is defined. Can you please help me undertand this line ?

1
  • You have an unmatched bracket at the ternary (?:) expression Commented Sep 3, 2014 at 13:03

1 Answer 1

4

That is the Conditional Operator:

(defined $5) ? '[^\\d]{0,5}' . $5 : ''
^^^^^^^^^^^^   ^^^^^^^^^^^^^^^^^^   ^^
 condition      take this if true   take this if false

will return '[^\\d]{0,5}' . $5 if $5 is defined, empty string otherwise.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.