Learning PERL


Practice 1. printf statement (Code Download: prac1.pl)
(It is simply the formatted 'print' function.)

    $a=100;
    printf("%5d", $a);
    printf("\n");

    $a=5;
    $b=3;
    printf("%d is greater than %d. \n", $a, $b);
    printf("%d is greater than %d. \n", 5, 3);
    printf("%3d is greater than %3d. \n", $a, $b);
    printf("%3d is greater than %5d. \n", $a, $b);



    Format Summary:
    • %d: integer to decimal number (1, 2, -4, 10 / %10d, %05d)
    • %x: integer to hexadecimal number (1, a)
    • %X: integer to hexadecimal number (1, A)
    • %f: float number (0.10, 13.457 / %10.3f, %.3f)
    • %c: integer to ASCII code character (1, A)
    • %s: string (ABC, hello / %10s )