Front page | perl.beginners |
Postings from February 2002
RE: Hash Question
Thread Previous
|
Thread Next
From:
Chas Owens
Date:
February 1, 2002 13:00
Subject:
RE: Hash Question
Message ID:
1012597216.20245.82.camel@tert.icallinc.com
On Fri, 2002-02-01 at 15:23, Balint, Jess wrote:
> A scalar value based on the number of command line arguments put into an
> array.
>
> if( $ARGV[$_] =~ /^-f/ ) {
> # PARSE TABULATION VALUES
> if( $table ) {
> $table = $ARGV[$_];
> $table =~ s/-f//;
> $table = $ARGV[$_+1] if( length( $table ) == 0 );
> $tables[$tblcnt] = $table;
> $tblcnt++;
> } else {
> $table = $ARGV[$_];
> $table =~ s/-f//;
> $table = $ARGV[$_+1] if( length( $table ) == 0 );
> $tables[0] = $table;
> $tblcnt++;
> }
>
<snip />
First off, you don't need $tblcnt. @tables in a scalar context will
return the number of elements and you can simply push the value onto the
array (see perldoc -f push). This also gets rid of the if $table
business.
Second off, I assume that you are trying to treat -f table and -ftable
the same. In which case shouldn't you increment $_ if you grab the next
arg?
if ( $ARGV[$_] =~ /^-f(.*)/ ) {
# PARSE TABULATION VALUES
if (defined($1)) { #if there was something after -f
push @tables, $1;
} else { #otherwise use next arg
$_++;
push @tables, $ARGV[$_];
}
}
print "There were ", scalar(@tables), "tables on the cmdline.\n";
Thirdly, where are the keys for the hashes going to come from? And how
are you going to know at which level in the hash you want to store the
data?
To clarify:
In my example I read the keys from the first three words of a line where
the first word was the first key, the second word was the second key,
and the third word was the the third key and then treated the fourth
word as the data.
--
Today is Boomtime the 32nd day of Chaos in the YOLD 3168
Hail Eris!
Missle Address: 33:48:3.521N 84:23:34.786W
Thread Previous
|
Thread Next