Mark,
A couple things:
1. if you have something like 099, Perl thinks that you mean the Octal value
of 99. The leading 0 makes Perl think you mean Octal instead of digit. For
example:
my $i = 99; #-- means the value 99
my $j = 099; #-- means the value 99 in Octal
Now, since the Octal number system only runs from 0-8, 9 is illegal and that's
the reason why you are getting the "Illegal octal digit '9'..." error
2. Your statement of:
map { 'zone x'} {1..3};
should be:
map { 'zone x'} (1..3);
if fact, you don't even need to put all the zip codes inside the (..) parens.
You only need the number of zip codes you are doing the hash slices. for
example:
@zip_codes{1,5,6,90,345,21} = map { 'zone 1'} (1,5,6,90,345,21);
is essentailly the same as:
@zip_codes{1,5,6,90,345,21} = map { 'zone 1'} (1..6);
since you have 7 zip codes to slice. this is simpler and much less to type.
:-) HTH
david
On Wednesday 20 November 2002 07:12, mark wrote:
> Thanks David, this works in the form that you gave me. However, I am
> butchering it up to try and see if it will work with all the values I have
> and I run into this error.
>
> Illegal octal digit '9' at noname.pl line 10, at end of line
>
> I get the impression that perl is interpreting one of my zips as something
> other than an integer or range of integers and I am unsure of why it is
> doing this or what to do to remedy it. I got the same error when I was
> trying to run the one I had written prior to your good advice. I assumed
> that I somehow had misunderstood what I could and could not do with a hash,
> but now I see that it is the numbers I am using. Can I escape this problem
> and still have my hash perform as expected?
>
> This is the end of line 10:
>
> map{'zone 6'}
> {043,044,046..049,567,576,577,582..588,592,593,693,798..820,822..830,865..8
>8 5};
>
> And the previous line 9:
>
> map{'zone 5'}
> {004,005,010..042,045,050..146,148,149,169,180..196,330..334,349,496..505,5
>0
> 8..516,521,539..566,570..575,580,581,664..666,668..672,674..692,730..739,74
>6 ..748,750..754,758,760..797};
>
> As you can see, the zones are a bit more involved, but the method should
> remain the same should it not?
>
>
> wiggins: Thanks for the perlcircus link.
>
> TIA,
> Mark
>
> > I don't think you need to do a lot of typing. your best approach(i think
>
> of
>
> > course) is to use the zip code as key and the zone code id as value. if
>
> you
>
> > use the other way around, you are bound to find your searching algr. slow
> > becasue you have to search through tons of zip codes on each search.
> >
> > try:
> >
> > #!/usr/bin/perl -w
> > use strict;
> >
> > my %zips;
> >
> > @zips{100..200} = map{'zone 1'} (100..200);
> > @zips{201..300} = map{'zone 2'} (201..300);
> > @zips{301..400} = map{'zone 3'} (301..400);
> >
> > while(<STDIN>){
> > exit if(/^exit/i);
> > chomp;
> > print "$_ is in $zips{$_}\n" if(exists $zips{$_});
> > }
> >
> > __END__
> >
> > run:
> >
> > 100
> > 100 is in zone 1
> > 300
> > 300 is in zone 2
> > 400
> > 400 is in zone 3
> > 123
> > 123 is in zone 1
> > exit
> >
> > david
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]