[TriLUG] perl programming question

Andrew Perrin andrew_perrin at unc.edu
Thu Mar 21 10:01:51 EST 2002


Hey, cool, a question I can answer :)

On Thu, 21 Mar 2002, John F Davis wrote:

> [snip]

> for ($i=0, $i < $numOfPartitions; $i++) {
>       #cylinder info is manipulated and not needed for this example
>                 print "$begCyl, $endCyl, $partHash("$drive$i"), $boot \n";
                                                    ^^        ^^
Two problems here:
1.) the parens should be braces; and
2.) you're doubling up double-quotes (one set in the print command, the
other set around the $drive$i). You don't need them in the $drive$i
section; hash lookups interpolate automatically.

print "$begCyl, $endCyl, $partHash{$drive$i}, $boot \n";

By the way, the for() loop is ugly although functional; this is prettier:
for my $i (0..$numOfPartitions) {

Best,
Andy


----------------------------------------------------------------------
Andrew J Perrin - andrew_perrin at unc.edu - http://www.unc.edu/~aperrin
 Assistant Professor of Sociology, U of North Carolina, Chapel Hill
      269 Hamilton Hall, CB#3210, Chapel Hill, NC 27599-3210 USA







More information about the TriLUG mailing list