Technology news and Jobs
The Linux distillery
Legends of FOSS: Perl 5.10 is here
The Linux distillery
Legends of FOSS: Perl 5.10 is here | Legends of FOSS: Perl 5.10 is here |
|
| by David M Williams | |
| Wednesday, 02 January 2008 | |
|
Page 3 of 3 Defined-or operatorEver one for obscure operators, Perl 5.10 also introduces the // operator, which means defined-or. This operator fundamentally provides a shortcut to test if a variable is defined, and if not to give it a value – but if it is defined, leave it be. Featured Whitepaper
5 Best Practices for Smartphone Support
$a // $b is equivalent to defined $a ? $a : $b That is, “is $a defined? If not, give it the value $b.” Additionally, the statement $c //= $d; is syntactically equivalent to $c = $d unless defined $c; That is, “is $c defined? If not, give it the value $d.” Recursive regular expression patterns Not one for the faint-hearted, regular expressions – or regexs – are a mainstay of Computer Science and an essential component of string handling. Perl 5.10 makes it easier to write recursive patterns – ie ones that can backtrack over themselves and try multiple paths. To illustrate, consider the following regex pattern which matches nested balanced angle brackets. By nested, we mean the string will contain multiple occurrences of the brackets, and by balanced we mean for each opening angle bracket there is a closing one too. / ^ # start of line ( # start capture buffer 1 < # match an opening angle bracket (?: # match one of: (?> # don't backtrack over the inside of this group [^<>]+ # one or more non angle brackets ) # end non backtracking group | # ... or ... (?1) # recurse to bracket 1 and try it again )* # 0 or more times. > # match a closing angle bracket ) # end capture buffer one $ # end of line /x
|
| < Next story in category | Previous story in the category > |
|---|




Tags




