Re: Newbie help needed

[email protected] (Hunter Johnson) Thu, 10 Apr 2014 09:45:21 -0400
Newsgroups perl.gedcom
Message-ID <CAHW-QVyeO9jR1SgPOd=MRxEnviUssxVa96wjOV2n5bE=qEBDVw@mail.gmail.com>
--bcaec51dd551b1a83f04f6b06db7
Content-Type: text/plain; charset=ISO-8859-1

Perhaps something like

@array = $i->siblings;
for $x (@array) {print "Sibling ", $x->name, "\n";

?



On Thu, Apr 10, 2014 at 9:30 AM, Alan Cohen <[email protected]>wrote:

> I am a Gedcom newbie (also an OO newbie) challenged to get a most basic
> program using Gedcom.pm to work. Having opened a gedcom file, I can access
> a Gedcom::Individual and can retrieve scalar attributes from him. However,
> I fail when it comes to using methods that supposedly return an array.
> Instead I get things like "Gedcom::Individual=HASH(0x123456789)"
>
> Can someone please tell me where I'm going wrong in (say) the following
> example?
>
> #!/bin/perl -w
>
> use warnings;
> use strict;
>
> use Gedcom;
>
> my $ged = Gedcom->new(grammar_version => "5.5",
>                       gedcom_file     => shift,
>                       read_only       => 1);
> my $indi="I187";
> my $i;
> my @array;
> my $x;
>     $i = $ged->get_individual($indi);
> ####
> # These work...
> ####
>     $x = $i->name;           { print("       name = $x\n"); }
>     $x = $i->given_names;    { print("given_names = $x\n"); }
>     $x = $i->surname;        { print("    surname = $x\n"); }
>     $x = $i->get_value("birth date");{print(" birth date = $x\n"); }
> ####
> # The documentation suggests that many methods return arrays but all of
> # them seem to produce "values" such as
> #     "Gedcom::Individual=HASH(0x2ab6c30)"
> # (I looked at Individual.pm itself and "sub siblings" does seem to be
> #  returning an array.
> ####                    WHAT AM I DOING WRONG!
>     @array = $i->siblings();
>     for $x (@array)            { print("Sibling $x\n"); }
> Sincerely,
>   Alan Cohen
>   416-783-5383
>



-- 
J. Hunter Johnson <><
http://jhunterj.com

--bcaec51dd551b1a83f04f6b06db7
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Perhaps something like<div><br></div><div>@array =3D $i-&g=
t;siblings;</div><div>for $x (@array) {print &quot;Sibling &quot;, $x-&gt;n=
ame, &quot;\n&quot;;</div><div><br></div><div>?</div><div><br></div></div><=
div class=3D"gmail_extra">
<br><br><div class=3D"gmail_quote">On Thu, Apr 10, 2014 at 9:30 AM, Alan Co=
hen <span dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]" targ=
et=3D"_blank">[email protected]</a>&gt;</span> wrote:<br><blockquot=
e class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc sol=
id;padding-left:1ex">
<div dir=3D"ltr"><div>I am a Gedcom newbie (also an OO newbie) challenged t=
o get a most basic program using Gedcom.pm to work. Having opened a gedcom =
file, I can access a Gedcom::Individual and can retrieve scalar attributes =
from him. However, I fail when it comes to using<u></u> methods that suppos=
edly return an array. Instead I get things like &quot;Gedcom::Individual=3D=
HASH(0x123456789)&quot;<br>

<br></div>Can someone please tell me where I&#39;m going wrong in (say) the=
 following example?<br><div><div><br><span style=3D"font-family:courier new=
,monospace">#!/bin/perl -w<br><br>use warnings;<br>use strict;<br><br>use G=
edcom;<br>

<br>my $ged =3D Gedcom-&gt;new(grammar_version =3D&gt; &quot;5.5&quot;,<br>=
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 gedcom_file=A0=
=A0=A0=A0 =3D&gt; shift,<br>=A0=A0=A0 =A0=A0=A0 =A0=A0 =A0 =A0 =A0 =A0 =A0=
=A0 read_only=A0=A0=A0=A0=A0=A0 =3D&gt; 1);<br>my $indi=3D&quot;I187&quot;;=
<br>my $i;<br>my @array;<br>

my $x;<br>=A0=A0=A0 $i =3D $ged-&gt;get_individual($indi);<br>####<br># The=
se work...<br>####<br>=A0=A0=A0 $x =3D $i-&gt;name;=A0=A0=A0 =A0=A0=A0 =A0=
=A0 { print(&quot;=A0=A0=A0=A0=A0=A0 name =3D $x\n&quot;); }<br>=A0=A0=A0 $=
x =3D $i-&gt;given_names;=A0=A0=A0 { print(&quot;given_names =3D $x\n&quot;=
); }<br>

=A0=A0=A0 $x =3D $i-&gt;surname;=A0=A0=A0 =A0=A0=A0 { print(&quot;=A0=A0=A0=
 surname =3D $x\n&quot;); }<br>=A0=A0=A0 $x =3D $i-&gt;get_value(&quot;birt=
h date&quot;);{print(&quot; birth date =3D $x\n&quot;); }<br>####<br># The =
documentation suggests that many methods return arrays but all of<br>

# them seem to produce &quot;values&quot; such as<br>#=A0=A0=A0=A0 &quot;Ge=
dcom::Individual=3DHASH(0x2ab6c30)&quot;<br># (I looked at Individual.pm it=
self and &quot;sub siblings&quot; does seem to be<br>#=A0 returning an arra=
y.<br>####=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 WHAT AM I DOING=
 WRONG!<br>

=A0=A0=A0 @array =3D $i-&gt;siblings();<br>=A0=A0=A0 for $x (@array)=A0=A0=
=A0 =A0=A0=A0 =A0=A0=A0 { print(&quot;Sibling $x\n&quot;); }</span><br clea=
r=3D"all"><div>Sincerely,<br>=A0 Alan Cohen<br>=A0 <a href=3D"tel:416-783-5=
383" value=3D"+14167835383" target=3D"_blank">416-783-5383</a></div>

</div></div></div>
</blockquote></div><br><br clear=3D"all"><div><br></div>-- <br>J. Hunter Jo=
hnson &lt;&gt;&lt;<br><a href=3D"http://jhunterj.com" target=3D"_blank">htt=
p://jhunterj.com</a>
</div>

--bcaec51dd551b1a83f04f6b06db7--