Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6899375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:24:50+00:00 2026-05-27T07:24:50+00:00

I created two subs one to do Fibonacci and the other to test even

  • 0

I created two subs one to do Fibonacci and the other to test even numbers. When I call it though it is saying my for loop in line 7 the sub Fibonacci is illegal why?

#!/usr/bin/perl
use strict;
use warnings;


my ($x,$y);
my $num = 0;

sub Fibs($start,$stop){
    for ($start..$stop){
        ($x, $y) = ($y, $x+$y);
            my $total += $y;
        }
    print "$total \n"
}

sub even($num){
    if ($num % 2 == 0){
        return $num;}
}

my $big_total = Fibs(even($num), 3999999)

Edited from suggestions below.

Clearly I am missing something. From feedback updated to new version.

#!/usr/bin/perl
use strict;
use warnings;


my ($x,$y);
my $num = 0;

sub Fibs{
    my ($start, $stop) = @_ ;
    for ($start..$stop){
        my ($x, $y) = (0,2);
            if ($x % 2 == 0){
                ($x, $y) = ($y, $x+$y);
                    my $total += $y;
        }
}

my $big_total = Fibs(0, 3999999)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:24:51+00:00Added an answer on May 27, 2026 at 7:24 am

    In addition to the missing opening braces, Perl doesn’t support that kind of declaration for subroutine parameters.

    Rather than

    sub Fibs($start, $stop) {
        ...
    }
    

    you need to write something like:

    sub Fibs {
        my($start, $stop) = @_;
        ...
    }
    

    (Perl does have prototypes, but they’re not really intended for declaring the types of parameters, and they don’t provide names. See this article for a discussion.)

    Other problems:

    You should add

    use strict;
    use warnings;
    

    You never use the $x and $y that you declare in the outer scope.

    Your even function appears to be incomplete. It doesn’t (explicitly) return a value if its argument is an odd number. What exactly is it intended to do?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created two simple testpages. One loads the other one using XMLHttpRequest. (just a
I created two temp tables, one table is for orders and the other is
I created two very simple Heroku apps to test out the service, but it's
I created two apps one free and one PRO and published them to the
I created two modules, one with def _func(): print hi and another def func():
I have created two forms in my Windows Application. One Form acts as a
I created two classes in objective c and I would like to use one
I created two apps, one for iphone and one for mac. They communicate back
I created two action sheets in one view. There are two buttons, each will
Ive created two frames my main frame is Home and the second one is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.