The equivalent to
$#array (which finds the last index of @array)
for an array reference $rArray is
$#{$rArray}
(note the second dollar sign)
And note that it is not
$#{ @{$rArray} }
where you're putting an array into a context where a reference to an array is expected. Beware, this fails without giving a warning.
Anti-nuisance lawsuit warning: The purpose of these notes is to remind me, Zoegond, of stuff or to help me work stuff out. They may contain mistakes.
Quick
- ($a, $b....) = unpack("A2A7...", $packed)
- push( array, list )
Friday, June 22, 2012
Wednesday, June 20, 2012
XPath
/ absolute path separator - /AAA/BBB selects BBB (not AAA)
// relative path separator - //AAA/BBB selects BBB (not AAA)
( ie, / means what it does in file paths, whereas // means sort of /.*/ with any number of hierarchy levels intervening )
( Starting the path with "/" means the path starts at the root node of the document. Even if you supplied a different node to document.evaluate as the context node, / still has this meaning. To search under a context node, which is usually why you supplied one in the first place, start the path with .// , ie "at any position among the descendants of the context node")
.. as in file paths - //AAA/BBB/.. selects AAA (not BBB)
* all matching elements (at one level only)
[n] nth element at that level (1+) - also last()
[otherelement] select elements that have otherelement as a child
@attr select an attribute (not the tag it belongs to)
[@attr] select an element that has an attribute
attr can be *. not() negates, so [not(@*)] = an element without any attrs
[@attr='...'] select an element that has attr set to a given value
[expression] eg saying name()='BBB' is the same as //BBB
text() select all text node children - can be subscripted etc (use a predicate with string(.) or string() to select on the content of the text, eg [contains(string(.),'dog')]
Axes:
/AAA = /child::AAA (ie, child:: is the default axis)
/AAA/BBB = /child::AAA/child::BBB
//descendant::* = all elements below the specified level
//parent::* = all parents
//parent::DDD = all DDDs which are parents
ancestor::
following-sibling::, preceding-sibling::
//A/B/following-sibling:: = all following siblings of a B which has an A parent
following::, preceding::
descendant-of-self::, ancestor-of-self:: ('and' not 'or')
self::
Other functions:
normalize_space() = ltrim(rtrim())
starts_with(name(), 'BBB')
contains(name(), 'x')
string-length() remember < and > represented as entities
floor(), ceiling()
Beware using unfamiliar functions looked up on net, they may be from XPath 2 which browsers don't implement. Useful list of functions which do work in XPath 1 here (Appendix C) http://www.w3.org/TR/xpath-functions/#xpath1-compatibility
Other operators
div, mod
String value: I'm being told that nodes have a string-value, which for purposes of parsing HTML is all the text in themselves and their descendant nodes. This means that . in an XPath expression represents the text in a node, so you can specify things like //span[contains(.,'Dalek')] to pull out all spans containing the string "Dalek".
// relative path separator - //AAA/BBB selects BBB (not AAA)
( ie, / means what it does in file paths, whereas // means sort of /.*/ with any number of hierarchy levels intervening )
( Starting the path with "/" means the path starts at the root node of the document. Even if you supplied a different node to document.evaluate as the context node, / still has this meaning. To search under a context node, which is usually why you supplied one in the first place, start the path with .// , ie "at any position among the descendants of the context node")
.. as in file paths - //AAA/BBB/.. selects AAA (not BBB)
* all matching elements (at one level only)
[n] nth element at that level (1+) - also last()
[otherelement] select elements that have otherelement as a child
@attr select an attribute (not the tag it belongs to)
[@attr] select an element that has an attribute
attr can be *. not() negates, so [not(@*)] = an element without any attrs
[@attr='...'] select an element that has attr set to a given value
[expression] eg saying name()='BBB' is the same as //BBB
text() select all text node children - can be subscripted etc (use a predicate with string(.) or string() to select on the content of the text, eg [contains(string(.),'dog')]
Axes:
/AAA = /child::AAA (ie, child:: is the default axis)
/AAA/BBB = /child::AAA/child::BBB
//descendant::* = all elements below the specified level
//parent::* = all parents
//parent::DDD = all DDDs which are parents
ancestor::
following-sibling::, preceding-sibling::
//A/B/following-sibling:: = all following siblings of a B which has an A parent
following::, preceding::
descendant-of-self::, ancestor-of-self:: ('and' not 'or')
self::
Other functions:
normalize_space() = ltrim(rtrim())
starts_with(name(), 'BBB')
contains(name(), 'x')
string-length() remember < and > represented as entities
floor(), ceiling()
Beware using unfamiliar functions looked up on net, they may be from XPath 2 which browsers don't implement. Useful list of functions which do work in XPath 1 here (Appendix C) http://www.w3.org/TR/xpath-functions/#xpath1-compatibility
Other operators
div, mod
String value: I'm being told that nodes have a string-value, which for purposes of parsing HTML is all the text in themselves and their descendant nodes. This means that . in an XPath expression represents the text in a node, so you can specify things like //span[contains(.,'Dalek')] to pull out all spans containing the string "Dalek".
Saturday, June 16, 2012
DOM basics & gotchas
Get element attributes with .getAttribute(attrname). Element tag names in .tagName - in upper case seemingly. (tagName is a property of Element btw, not HTMLElement or Node. But className is a property of HTMLElement, presumably because HTML elements are expected to have 'class' whereas SGML ones aren't, necessarily. Not that this matters in practical terms.)
You can supply an XPath evaluation with a context node by supplying that node in the contextnode parameter. That node will then be the one represented by "." in the XPath expression.
NodeList is returned by childNodes and the getElementsBy... methods among others. It takes .item() or [] and has .length . If there are no nodes to return, you get an empty NodeList (not null).
You can supply an XPath evaluation with a context node by supplying that node in the contextnode parameter. That node will then be the one represented by "." in the XPath expression.
NodeList is returned by childNodes and the getElementsBy... methods among others. It takes .item() or [] and has .length . If there are no nodes to return, you get an empty NodeList (not null).
Friday, June 15, 2012
Scheduled task issues
Don't forget that if the command in a scheduled task contains redirections, or is an internal command, it needs "cmd /c" in front of it. This is a nasty one as it doesn't show up when you test from the command line (because you're inside cmd there...)
Thursday, June 14, 2012
Firefox and the DOM
Firefox is very conscientious about whitespace - it often (if not always) creates a separate text node for whitespace, rather than ignoring it. It's as if its rule is 'not even whitespace must be thrown away'.
This means that you cannot assume that, for example, a TR node's nextSibling will be the next TR in the table. It may well be a whitespace text node - one which will be invisible when you inspect the structure, too. So if your scripts don't find the siblings they expect, put in a loop to seek the next non-text node sibling (or parent, or child etc etc).
Monday, June 11, 2012
on v. where
It seems that the functional difference between specifying a predicate in 'join..on' and specifying it in 'where' is that, if the predicate only involves a field from one table (eg tax_year <= 2005), then with 'join...on' it's applied to the table before the join is made, and with 'where' it's applied to the rows that result from the join.
So I suppose the most efficient place for this kind of predicate is in 'join...on'.
So I suppose the most efficient place for this kind of predicate is in 'join...on'.
Friday, June 8, 2012
Shield anchors
When I'm drilling holes for shield anchors for things that bolt into concrete floors or paving, there's usually at least two holes to drill, and every hole after the first tends to get gritty concrete dust down it, which makes the bolts seize up in the threads.
A bit of blue tack or chewing gum stuck over the top of each hole keeps the dust out effectively. (Don't resume chewing the gum after use).
A bit of blue tack or chewing gum stuck over the top of each hole keeps the dust out effectively. (Don't resume chewing the gum after use).
Saturday, June 2, 2012
Javascript variable initialisation
Don't expect to ++ on a variable if you haven't set it to contain a number. Even if it has been declared, it is not initialised to 0 or even to an undefined numeric value.
Similarly, you can't set properties on a new variable unless it's been initialised to {}, and you can't set array index values unless it's been initialised to [].
Similarly, you can't set properties on a new variable unless it's been initialised to {}, and you can't set array index values unless it's been initialised to [].
Friday, June 1, 2012
Javascript null, undefined, false etc etc
What counts as false
When Javascript is casting to a boolean, eg in an if statement, it treats as false the following values:
null
undefined
""
0 (or any number equivalent to 0 eg -0, 0.0 etc, or a string that represents such a number)
NaN
So !value will be true if value is any of the above.
What can't take a property setting or index
It's an error to try to set or get a property (with .) or an index (with []) on a null or undefined value.
When Javascript is casting to a boolean, eg in an if statement, it treats as false the following values:
null
undefined
""
0 (or any number equivalent to 0 eg -0, 0.0 etc, or a string that represents such a number)
NaN
So !value will be true if value is any of the above.
What can't take a property setting or index
It's an error to try to set or get a property (with .) or an index (with []) on a null or undefined value.
Subscribe to:
Comments (Atom)