J
Joseph Ellis
I am writing a program / script (in Perl, yet) that will parse a text
database of genealogy information to generate a web-based family tree.
When invoking the script, I have to give it an ID such as "I108" to
search for. Development has been going fine so far, but since I often
forget to specify an ID, I'm making a little if {} block to allow me
to type in an ID when I forget to do so at invocation:
#!/usr/bin/perl
use strict;
use warnings;
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);
my $gedcom="Joseph Ellis Family.ged";
my $id = param('id');
if (not $id) { ## Just because I keep forgetting to specify the ID
print ("\n\nSpecify an ID to work with.\n: ");
chomp ($id = <STDIN>);
print "\n$id newline?\n\n"; ## for debugging
}
my %data;
my $found;
my @record;
my %indiv = &getrec($id);
print "Hash contents for ID: $id\n\n"; ## for debugging
foreach (sort keys %indiv) {
printf "%10s : %s\n", $_, $indiv{$_};
}
etc etc
The problem is that the chomp ($id = <STDIN>) seems to be killing $id
for the following print statement, but not for the print "Hash
contents... statement later in the program. Output looks like:
newline?
Hash contents for ID: I108
But if I get rid of the chomp, output is as expected:
I108
newline?
Hash contents for ID: I108
Any thoughts on this? I've searched perldoc -f and the perlfaqs to no
avail.
Thanks,
Joseph
database of genealogy information to generate a web-based family tree.
When invoking the script, I have to give it an ID such as "I108" to
search for. Development has been going fine so far, but since I often
forget to specify an ID, I'm making a little if {} block to allow me
to type in an ID when I forget to do so at invocation:
#!/usr/bin/perl
use strict;
use warnings;
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);
my $gedcom="Joseph Ellis Family.ged";
my $id = param('id');
if (not $id) { ## Just because I keep forgetting to specify the ID
print ("\n\nSpecify an ID to work with.\n: ");
chomp ($id = <STDIN>);
print "\n$id newline?\n\n"; ## for debugging
}
my %data;
my $found;
my @record;
my %indiv = &getrec($id);
print "Hash contents for ID: $id\n\n"; ## for debugging
foreach (sort keys %indiv) {
printf "%10s : %s\n", $_, $indiv{$_};
}
etc etc
The problem is that the chomp ($id = <STDIN>) seems to be killing $id
for the following print statement, but not for the print "Hash
contents... statement later in the program. Output looks like:
newline?
Hash contents for ID: I108
But if I get rid of the chomp, output is as expected:
I108
newline?
Hash contents for ID: I108
Any thoughts on this? I've searched perldoc -f and the perlfaqs to no
avail.
Thanks,
Joseph