Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

triyng to built a module

by Raymond (Novice)
on Jul 22, 2013 at 18:53 UTC ( #1045698=perlquestion: print w/ replies, xml ) Need Help??
Raymond has asked for the wisdom of the Perl Monks concerning the following question:

Iam try built module to learn and teach perl, by practice, and I have the following bug:

#!/usr/bin/perl use strict; use warnings; $char = chr(0x394); $code = ord($char); printf "char %s is code %d, %#04x\n", $char, $code, $code;
and it has this mistakes:

Global symbol "$char" requires explicit package name at 3.pl line 5.

Global symbol "$code" requires explicit package name at 3.pl line 6.

Global symbol "$char" requires explicit package name at 3.pl line 6.

Global symbol "$char" requires explicit package name at 3.pl line 8.

Global symbol "$code" requires explicit package name at 3.pl line 8.

Global symbol "$code" requires explicit package name at 3.pl line 8.

Execution of 3.pl aborted due to compilation errors.

I will have more sample like this, pls help

Comment on triyng to built a module
Download Code
Re: triyng to built a module
by kennethk (Monsignor) on Jul 22, 2013 at 18:57 UTC
    The consequent of using strict is that you must either 'declare' variables with my or our, or use a fully qualified package name (see strict vars). The above code can be repaired with
    #!/usr/bin/perl use strict; use warnings; my $char = chr(0x394); my $code = ord($char); printf "char %s is code %d, %#04x\n", $char, $code, $code;

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Re: triyng to built a module
by toolic (Chancellor) on Jul 22, 2013 at 18:57 UTC

    Tip #1 from the Basic debugging checklist: use diagnostics:

    (F) You've said "use strict" or "use strict vars", which indicates + that all variables must either be lexically scoped (using "my" or +"state"), declared beforehand using "our", or explicitly qualified to say which package the global variable is in (using "::").

    Declare all variables with my:

    use strict; use warnings; my $char = chr(0x394); my $code = ord($char); printf "char %s is code %d, %#04x\n", $char, $code, $code;

    See also: perlintro

    UPDATE: Geez, this problem was solved for you a month ago :(

Re: triyng to built a module
by Loops (Hermit) on Jul 22, 2013 at 19:10 UTC

    Previous answers should get you to the point where your script runs, but you may then see a warning about printing wide characters. If this is the case, you can add the following to the top of your script to enable Unicode support:

    use feature 'unicode_strings'; use open qw(:std :utf8); use utf8;
Re: triyng to built a module
by davido (Archbishop) on Jul 22, 2013 at 19:39 UTC

    #!/usr/bin/perl use strict; # <--- Because of this... use warnings; use diagnostics; my $char = chr 0x394; #^-----------------------You must do this. (my) my $code = ord $char; #^----------------------- And this. (my)

    Dave

Re: triyng to built a module
by Laurent_R (Parson) on Jul 22, 2013 at 21:07 UTC

    Iam try built module to learn and teach perl,

    Do you seriously intend to teach Perl? It sounds sort of premature to me.

    Or perhaps it is a mistake in the English language... Or possibly you meant to teach yourself Perl...

      That's true, the examples are from a book, and I hope to

      help more people, i'm thinking in writting the examples to

      chapter 5, and put them online on my small website.

Re: triyng to built a module
by wee (Beadle) on Jul 24, 2013 at 20:50 UTC
    I'm sorry but this has to be the laziest submission I've seen in years. The very first result of a google search for "perl requires explicit package name at" will answer this "bug". Are we reduced to this?

      No, I have more, should I put them all, or one at a time?

Re: triyng to built a module
by Anonymous Monk on Jul 25, 2013 at 15:34 UTC

    If you want to learn how to do modules, I'd strongly suggest you getting and fully reading a book called "Object Oriented Perl" by Damian Conway. In addition to modules, the first 50 or so pages are a very good overview of Perl. I think you need to work thru that first before you head into modules ... although modules are a good goal.

    HTH...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1045698]
Approved by toolic
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2014-09-16 21:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (50 votes), past polls