[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: gEDA-user: refdes_renum and pgskip
According to my copy of "Programming Perl",
"If you don't initialize your variables, they automatically spring into
existence with a null value that means either '' or 0 as necessary."
Which is why my change works as expected. If the --pgskip command line
option is not specified, $pgskip springs into being with a value of zero.
OK, evidence of how my change works. I created two simple files with a
single "refdes=U1" in each and then ran refdes_renum on them with
various options:
refdes_renum --verbose 1.sch 2.sch Processing input file #1: 1.sch
Refdes line "refdes=U1" has pre="U"
Renumbering refdes=U1 to U1
Processing input file #2: 2.sch
Refdes line "refdes=U1" has pre="U"
Renumbering refdes=U1 to U2
refdes_renum --verbose --pgskip 1.sch 2.sch
Processing input file #1: 1.sch
Refdes line "refdes=U1" has pre="U"
Renumbering refdes=U1 to U101
Incremented "U" counter to 200
Processing input file #2: 2.sch
Refdes line "refdes=U2" has pre="U"
Renumbering refdes=U2 to U201
Incremented "U" counter to 300
refdes_renum --verbose --pgskip 1000 1.sch 2.sch
Processing input file #1: 1.sch
Refdes line "refdes=U101" has pre="U"
Renumbering refdes=U101 to U1001
Incremented "U" counter to 2000
Processing input file #2: 2.sch
Refdes line "refdes=U201" has pre="U"
Renumbering refdes=U201 to U2001
Incremented "U" counter to 3000
I think that covers all of the possibilities.
With your suggested change, I get:
refdes_renum --verbose 1.sch 2.sch
Processing input file #1: 1.sch
Refdes line "refdes=U1001" has pre="U"
Renumbering refdes=U1001 to U101
Incremented "U" counter to 200
Processing input file #2: 2.sch
Refdes line "refdes=U2001" has pre="U"
Renumbering refdes=U2001 to U201
Incremented "U" counter to 300
refdes_renum --verbose --pgskip 1.sch 2.sch
Processing input file #1: 1.sch
Refdes line "refdes=U101" has pre="U"
Renumbering refdes=U101 to U1
Processing input file #2: 2.sch
Refdes line "refdes=U201" has pre="U"
Renumbering refdes=U201 to U2
refdes_renum --verbose --pgskip 1000 1.sch 2.sch
Processing input file #1: 1.sch
Refdes line "refdes=U1" has pre="U"
Renumbering refdes=U1 to U1001
Incremented "U" counter to 2000
Processing input file #2: 2.sch
Refdes line "refdes=U2" has pre="U"
Renumbering refdes=U2 to U2001
Incremented "U" counter to 3000
Which still fails the case of no pgskip option specified.
John Luciani wrote:
On 7/12/06, David W. Schultz <david.schultz@xxxxxxxxxxxxx> wrote:
John Luciani wrote:
> That line should be ---
>
> $pgskip = 100 unless defined $pgskip;
>
> (* jcl *)
>
> ---
> http://www.luciani.org
>
>
Really? I just tried it and it set pgskip to 100 even without the
--pgskip command line option specified. $pgskip gets defined when getopt
is invoked, or so it seems to me.
Using the :i specification you get an undefined value unless you
specify the option on the command line. If you specify the option name
without a value you get the default. There is still a condition where your
program could execute with an undefined value.
Try the little test program below with no command line options and then
try it with an option of "--test". With no command line options
the value is undefined. With "--test" the value is 100.
#--- cut here--
#!/usr/bin/perl
use strict;
use warnings;
use Carp;
use Getopt::Long;
my $Test;
GetOptions("test:100" => \$Test);
print "\$Test is undefined\n" unless defined $Test;
printf("\$Test is defined and equals %i\n", $Test) if defined $Test;
#-- cut here --
--
David W. Schultz
http://home.earthlink.net/~david.schultz/
Just because you're constitutionally entitled to a personal opinion
doesn't mean you're constitutionally entitled to a professional opinion
_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user