c_lhee has asked for the wisdom of the Perl Monks concerning the following question:

c_lhee@yahoo.com

Everytime the script runs it should replace the word "monk" with

values for @array = (perl1, perl2, perl3);

However, there seems to be a problem when i put the value $total_$array....

 

    $total_monk1 = $total_monk;

    if ( ($monktot == 0) && ($total_monk1 == 0)) {$total_monk == 0;}

    else {

        $total_monk = $total_monk1 /($monktot-$total_monkna);

        $total_monk = sprintf("%0.2f%", $total_monk);}

Replies are listed 'Best First'.
Style, and maybe post entire program?
by cebrown (Pilgrim) on Jul 31, 2002 at 03:06 UTC
    I'm having a hard time understanding the question. You're not printing "$total_array" anywhere. Could you post the whole program?

    And while you're at it, you may want to check out "perldoc perlstyle" as the wisdom therein will make your code much easier to read.

Re: changing value to ones on array
by DamnDirtyApe (Curate) on Jul 31, 2002 at 03:51 UTC

    Use a regular expression something like this:

    $string =~ s/monk/shift @array/eg ;

    Take a look at perlre for more details.

    __END__
    _______________
    D a m n D i r t y A p e
    Home Node | Email
Re: changing value to ones on array
by japhy (Canon) on Jul 31, 2002 at 10:08 UTC
    Use a hash. You want to use a hash here, instead of similarly named variables.
    for ("john", "jacob", "jingleheimer") { $total{$_} = ...; }
    Now you'll have a hash, %total, whose keys are "john", "jacob", and "jingleheimer".

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;