in reply to How to read a GEDCOM file

There are quite a few problems in your code, but the main one is that you open the file, but never actually read it, which you could do with something like this:
@MyGed = <MYFILE>;
That should probably solve your problem and make your script work. I would suggest, however, that you rewrite the script in accordance with commonly accepted best practices. For example as follows:
#!/usr/bin/perl use strict; use warnings; my $file_in = "C:/Users/Jill/Documents/Genealogy/birdt.ged"; open my $FILE, "<", $file_in or die "could not open $file_in $!"; # t +hree-argument open syntax my @ged = <$FILE>; # s +lurp the file contents into @ged my $count = $.; # or, as you had it: my $count = @ged; print "10th record : $ged[10]\n"; # n +ote that $ged[10] is really the 11th record (array subscripts start a +t 0) print "No. of records : $count \n";

Replies are listed 'Best First'.
Re^2: How to read a GEDCOM file
by JillB (Novice) on Nov 19, 2017 at 19:47 UTC

    Thanks you for this quick and very helpful reply. It now works perfectly with your code, and I have learnt lessons from your post regards, Jill

      It's clear from this node (if the janitors haven't already tidied it away) that you haven't yet quite gotten the hang of editing your posts. :) Please see How do I change/delete my post? for site etiquette and protocol regarding changing your posts. Bottom line: Don't Destroy Context!


      Give a man a fish:  <%-{-{-{-<