Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Example of a book

by Raymond (Novice)
on Jun 15, 2013 at 10:06 UTC ( #1039100=perlquestion: print w/replies, xml ) Need Help??
Raymond has asked for the wisdom of the Perl Monks concerning the following question:

This is the code: #!/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 the output should be: char "delta simbol" is code 916, 0x394 But the code has a bug, and I can't fix it; help. Best Reagrds Ray

Replies are listed 'Best First'.
Re: Example of a book
by rnewsham (Chaplain) on Jun 15, 2013 at 10:28 UTC

    Please remember to use code tags around your code examples.

    When using strict you need to declare any variables with my.

    #!/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;
Re: Example of a book
by thomas895 (Chaplain) on Jun 15, 2013 at 10:31 UTC

    Please, please put code tags around your program. Otherwise, I or others will probably miss key parts of it, and is also just a mess. See How do I post a question effectively? and Markup in the Monastery.

    And with "a bug", that's not very specific. Help here requires the following from you:

    1. All relevant code that you used. You have provided that; good start.
    2. Your expected output. You did provide that.
    3. What actually came out. Without that, I have no idea what could have gone wrong.

    I am making a guess as to what could be the problem, and I assume it has to do with what you expect printf to do. The %s format string does not print the name of the given character; rather, it prints that string. If you need that, you will need to consult a character table, available in many formats and mediums, it is just a matter of looking for them. They're really easy to find, too, so do your research first.

    Good luck, and without specific information, I regret I cannot help you.

    "Excuse me for butting in, but I'm interrupt-driven..."
Re: Example of a book
by poj (Monsignor) on Jun 15, 2013 at 10:48 UTC
    The 'book' in the title is presumably the Perl Cookbook 2nd Edition, page 5.

      Yes how did you know, you have one?
        As I look up to the left of my monitor I see both first and second editions of the Cookbook; the first, second, third, and fourth editions on the Camel; and the first and second editions of Modern Perl. Some of us are bibliomanes as well as Perl speakers.

        I Go Back to Sleep, Now.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1039100]
Approved by sundialsvc4
[robby_dobby]: Corion: Yes, I know it's fun. We met at LPW last year. First time volunteer and all, it was fun! :-)

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2018-04-19 12:42 GMT
Find Nodes?
    Voting Booth?