#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    Using numerical operation in the format Add: 7


    Please help me. I have the following in my text pad
    $a = 5;
    $b =2;
    $c = $a + $b;
    print "Add:\t$c\n";
    and the message I got while trying to run the program is
    (Global symbol "$c" requires explicit package name at line 3)
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,940
    Rep Power
    1225
    Please post your entire script.

    The error message indicates that you're using the strict pragma, which is good. The strict pragma requires you to declare your vars, which is normally done with the 'my' keyword.

    $a and $b are built-in global vars and don't need to be declared. Normally, they are reserved for use in sort routines, so using them as you are doing is not a recommended best practice.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    836
    Rep Power
    496
    You might try this:

    Perl Code:
     
    use strict;
    use warnings;
     
    my $aa = 5;
    my $bb =2;
    $c = $aa + $bb;
    print "Add:\t$c\n";
    Last edited by Laurent_R; June 30th, 2013 at 03:44 PM. Reason: Corrected a typo
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    Thumbs up compilation error


    Thanks that was helpful

IMN logo majestic logo threadwatch logo seochat tools logo