Professional Web Applications Themes

Style question: print v. printf - PERL Beginners

-----Original Message----- From: Rob Dixon [mailto:robdixon.port995.com] Sent: Thursday, October 16, 2003 2:26 AM To: [email]beginnersperl.org[/email] Subject: Re: how to read from more than one files at a time <snip> You need tp think about what happens when the two files are different lengths. You may not expect that to happen but your code should still handle that case. Some symmetry between the handling of the two files would also be nice. Finally you should really use 'print' here instead of 'printf'. <snip> Hello Rob and rest of the list... When would you use print, when printf and why? AdThanksvance, Chris ...

  1. #1

    Default Style question: print v. printf



    -----Original Message-----
    From: Rob Dixon [mailto:robdixon.port995.com]
    Sent: Thursday, October 16, 2003 2:26 AM
    To: [email]beginnersperl.org[/email]
    Subject: Re: how to read from more than one files at a time


    <snip>

    You need tp think about what happens when the two files are different
    lengths. You may not expect that to happen but your code should still
    handle that case. Some symmetry between the handling of the two files
    would also be nice. Finally you should really use 'print' here instead
    of 'printf'.

    <snip>



    Hello Rob and rest of the list...

    When would you use print, when printf and why?

    AdThanksvance,
    Chris

    Chris Mortimore
    Graceland University
    Chris Mortimore Guest

  2. #2

    Default Re: Style question: print v. printf

    From: "Chris Mortimore" <CMORTIMRgraceland.edu>
    > When would you use print, when printf and why?
    I'd only use printf() if I really needed to format something. Like if
    I wanted to print some date and wanted to be sure it'll be 2003/09/03
    and not 2003/9/3.

    Jenda
    ===== [email]JendaKrynicky.cz[/email] === [url]http://Jenda.Krynicky.cz[/url] =====
    When it comes to wine, women and song, wizards are allowed
    to get drunk and croon as much as they like.
    -- Terry Pratchett in Sourcery

    Jenda Krynicky Guest

  3. #3

    Default Re: Style question: print v. printf

    Chris Mortimore wrote:
    >
    > Rob Dixon wrote:
    > >
    > > <snip>
    > >
    > > You need to think about what happens when the two files are
    > > different lengths. You may not expect that to happen but
    > > your code should still handle that case. Some symmetry
    > > between the handling of the two files would also be nice.
    > > Finally you should really use 'print' here instead of
    > > 'printf'.
    >
    > <snip>
    >
    > Hello Rob and rest of the list...
    >
    > When would you use print, when printf and why?
    The code in question was

    printf OUT "$in1$in2\n"

    I thought 'printf' was wrong because it wasn't using print
    formatting at all: the scalar variables would be interpolated
    into the (then constant) format string. It make sense to me to
    write either

    print OUT "$in1$in2\n"

    or

    printf OUT "%s%s\n", $in1, $in2

    but not a combination of the two.

    HTH,

    Rob



    Rob Dixon Guest

Similar Threads

  1. Nested Paragraph Style Question
    By Kenny_Hoff@adobeforums.com in forum Adobe Indesign Macintosh
    Replies: 5
    Last Post: September 12th, 01:13 AM
  2. alert style question
    By globalview in forum Macromedia Flex General Discussion
    Replies: 0
    Last Post: July 15th, 08:55 PM
  3. Newbi Font Char style question
    By Raffi_Bearmant@adobeforums.com in forum Adobe Indesign Windows
    Replies: 0
    Last Post: April 12th, 08:24 PM
  4. Replies: 5
    Last Post: August 3rd, 11:00 AM
  5. FM XML to EXCEL Style Sheet Question
    By Martti Humppi in forum FileMaker
    Replies: 0
    Last Post: July 31st, 08:21 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