Professional Web Applications Themes

Problem with compiling a script - PERL Beginners

Dear All I am trying to run the script below, but I always get the following error: [pauluslocalhost scripts]$ secondperl Global symbol "$greeting" requires explicit package name at /home/paulus/scripts/secondperl line 6. Global symbol "$greeting" requires explicit package name at /home/paulus/scripts/secondperl line 7. Execution of /home/paulus/scripts/secondperl aborted due to compilation errors. The script is: #!/usr/bin/perl use warnings; use strict; $greeting = "World"; print "It matches\n" if "Hello World" =~ /$greeting/; Any ideas? Thanks in advance, Paul...

  1. #1

    Default Problem with compiling a script

    Dear All

    I am trying to run the script below, but I always get the following error:

    [pauluslocalhost scripts]$ secondperl
    Global symbol "$greeting" requires explicit package name at
    /home/paulus/scripts/secondperl line 6.
    Global symbol "$greeting" requires explicit package name at
    /home/paulus/scripts/secondperl line 7.
    Execution of /home/paulus/scripts/secondperl aborted due to compilation
    errors.

    The script is:

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

    $greeting = "World";
    print "It matches\n" if "Hello World" =~ /$greeting/;

    Any ideas?

    Thanks in advance,

    Paul

    Paul Guest

  2. #2

    Default Re: Problem with compiling a script

    Hi,
    Qualify the variable's in your perl script, since the script uses
    strict(use strict). For Eg: declare $greeting as "my $greeting"
    or comment "use strict" and that should work.

    Paul Smith wrote:
     

    Prasanna Guest

  3. #3

    Default Re: Problem with compiling a script

    On Jul 21, 2004, at 8:35 AM, Paul Smith wrote:
     

    Easy enough.
     

    Above, you are asking Perl to make you play by the Good Programmer
    rules. One of those rules is, you must declare a variable before
    using it.
     

    Here you use an undeclared variable. Usually, you'll declare a
    variable with "my", so change to above line to:

    my $greeting = 'World';

    Hope that helps.

    James
     

    James Guest

  4. #4

    Default Re: Problem with compiling a script

    Bingo, James! Sorry for my ignorance, but I am just beginning with Perl.

    Paul

    James Edward Gray II wrote: 
    >
    >
    > Easy enough.

    >
    >
    > Above, you are asking Perl to make you play by the Good Programmer
    > rules. One of those rules is, you must declare a variable before using
    > it.

    >
    >
    > Here you use an undeclared variable. Usually, you'll declare a variable
    > with "my", so change to above line to:
    >
    > my $greeting = 'World';
    >
    > Hope that helps.
    >
    > James

    >
    >
    >[/ref]


    Paul Guest

  5. #5

    Default Re: Problem with compiling a script

    On Jul 21, 2004, at 8:47 AM, Paul Smith wrote:
     

    Not a problem. Brand new to Perl and already using strict, you're off
    to the perfect start. Welcome.

    James

    James Guest

Similar Threads

  1. Compiling a perl script
    By Jenda Krynicky in forum PERL Beginners
    Replies: 2
    Last Post: September 14th, 09:27 PM
  2. Replies: 0
    Last Post: September 5th, 08:42 AM
  3. Script not compiling, Newb Student
    By JDex in forum Macromedia Director Lingo
    Replies: 1
    Last Post: August 13th, 05:09 AM
  4. Problem compiling gcc 3.3.
    By Larry Lindstrom in forum Sun Solaris
    Replies: 9
    Last Post: July 27th, 08:28 AM
  5. DB2 V.8.1 FP2 problem with compiling SP on AIX
    By Adam Kucharski in forum IBM DB2
    Replies: 5
    Last Post: July 23rd, 07:48 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139