in reply to Re^2: Strange Behavior with XML::Simple when pulling info out of an XML file
in thread Strange Behavior with XML::Simple when pulling info out of an XML file

In most languages, you can only use an identifier in one context - not so in Perl! You can have $x (scalar), @x (array), %x (hash), sub x{...} all in the same program. So $x is a completely unrelated thing to @x. As you have correctly surmised, the value of an array evaluated in a scalar context is the length of that array.

$element = scalar(@{$datasource});
$element = @$datasource; #same thing $element is a scalar so explicit conversion not required.
$x < @$datasource #also scalar context
You only need the extra curly braces when there is a subscript involved - so deference applies to the whole thing.

  • Comment on Re^3: Strange Behavior with XML::Simple when pulling info out of an XML file