in reply to Character Counts

Thank you all for your input, Here is what I have so far:
#--------Clean Phone Number $newphone = $phone $newphone = =~ s/[^0-9]//g; #-----Length of cleaned Number $phonelength = length($newphone) #-----Update Counter and Print Output if (length($newphone) != 4 and length($newphone) != 10) { # add asterisks $emph = "****" } else { $emph = "" # print number Print PHONELIST, sprintf "%16d %100s", $phone[1], $abs_filename[2], + "\n"; Print SUMMARY, sprintf "%16d %12d %4s %100s", %ctr++; $phone, $newphone[1], $emph[2], $phonelength[3], $abs_filename[4] "\n"; }
Now my problem is adding/updating a counter for the output.

Added code tags and indents - dvergin 2003-04-07

Replies are listed 'Best First'.
Re: Re: Character Counts
by graff (Chancellor) on Apr 07, 2003 at 22:24 UTC
    Now my problem is...

    • most of your statements are missing the final semicolon
    • "print" is not supposed to be capitalized
    • there shouldn't be a comma after the filehandle in the print statement
    • you have the wrong sigil on the variable named "ctr" ("%ctr" needs to be "$ctr")
    • you seem to be confused about the usage of sprintf, and how to provide values for placeholders in the format string (those numbers in square brackets next to the variable names don't belong there)
    • setting "$emph" to "****" doesn't do you any good, since you never print any record with that value.

    (whew -- it's all a bit of a mess) Better hit a book or two a little harder... To get you started, here's a cleaned up version:

    $newphone = $phone; $newphone =~ s/\D+//g; # NOT " = =~ " !! $phonelength = length( $newphone ); $emph = ( $phonelength == 4 or $phonelength == 10 ) ? "" : "****"; printf( PHONELIST "%16d %100s\n", $phone, $abs_filename); printf( SUMMARY "%3d %16d %12d %4s %100s\n", ++$ctr, $phone, $newphone, $emph, $abs_filename );
    And, please look at the "Site How To" and learn about the use of <code> tags when posting actual code -- it really helps.