rkmase has asked for the wisdom of the Perl Monks concerning the following question:

Can anyone tell me why the following code won't return anything for $gooddata if {content} equals an integer?:
foreach $record (@{$data->{present_response}->{record}}){ $gooddata=$record->{datafield}->{210}->{subfield}->{a}->{content}; print $gooddata; }
eg: if 'content' => 'This is a string of characters'
then I'll get back "This is a string of characters",

but if 'content' => '123412341234'
then I'll get back nothing - like $gooddata doesn't even have a value.

Thanks! Perl newb, out.

Replies are listed 'Best First'.
Re: Deconstructed array won't return scalar value if integer?
by toolic (Bishop) on Nov 29, 2007 at 18:08 UTC
    Are you sure your '123412341234' string is really where you expect it to be in your data structure? You could use the following to make sure:
    use Data::Dumper; ... print Dumper($record);
      Yeah, Dumper returns nothing either. Real world code example:
      '016' => { 'ind1' => ' ', 'ind2' => ' ', 'subfield' => { 'a' => { 'content' => '2009600369' } } }, '546' => { 'ind1' => ' ', 'ind2' => ' ', 'subfield' => { 'a' => { 'content' => 'English' } } },
      Like I said before - 546's content will return English, while 016 will return an uninitialized value
        I wonder if the leading 0 in 016 is causing problems. Perhaps when referencing, you could try to force this number to be a string as follows:
        $gooddata=$record->{datafield}->{'016'}->{subfield}->{a}->{content};
        Just a thought.