Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

Comment on Example of a book
Re: Example of a book
by rnewsham (Hermit) 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 (Hermit) 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.

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

    poj
      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.

        OGB

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2014-07-22 20:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (127 votes), past polls