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

Hello everyone, Ive run into some problems compiling my perl script and if anyone can assist me to compile this function, I would greatly appreciate it.
sub fireball{ my $uint32_t = \buffer my $word_count my $bias ( checksum = bias while(word_count) { checksum += \buffer word_count-- buffer++ } return checksum )
The errors that I'm getting are "syntax error at test.pl line 8, near "buffer my "

Global symbol "$word_count" requires explicit package name at test.pl line 9."

Thanks for your help!

Replies are listed 'Best First'.
Re: Function Confusion
by ikegami (Patriarch) on Jul 09, 2009 at 21:03 UTC
    • All the semicolons are missing.
    • Most variables are missing their sigil (dollar sign).
    • A few variables are undeclared.
    • The arguments are passed via undeclared/global variables.
    • uint32_t is an odd variable name, and it's not used.
    • Sums of references aren't very useful. Surely a bug.

    I hope you're using use strict; and use warnings;.

    Update: Added points.

      Haha, thanks. that was a careless mistake.
Re: Function Confusion
by mzedeler (Pilgrim) on Jul 09, 2009 at 22:32 UTC

    Try writing a very small script that works. Extend it in small steps until it does what you want, where you run it each time you have added a line.

    You could start with this one:

    use strict; use warnings; sub fireball { my $bias = shift; print "Bias: $bias\n"; } fireball(2);
Re: Function Confusion
by Anonymous Monk on Jul 09, 2009 at 21:31 UTC
    Actually, I ran into a few other syntax errors. If anyone can help.
    sub fireball{ my $uint32_t = \buffer; my $word_count; my $bias; ( uint23_t checksum = $bias while($word_count); { checksum += \buffer word_count-- buffer++ } return checksum )
    Im getting an syntax errors near $bias and buffer++. do i need semicolons after these, because when i put them in, it still does not work. Thanks.
      uint23_t checksum = $bias is not Perl syntax. and \ is not a sigil. And checksum and word_count and buffer still don't have sigils.

      your syntax on the while loop is still incorrect.

      You have:

      while ($string_tested); { statement statement statement }

      It should read like this:

      while (test) { statement0; statement1; statement2; }

      I echo the approach suggested by mzedeler and also that you have a look at the tutorials section. Oh and always  use strict; use warnings;.