Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: problem with File::Cat

by lidden (Curate)
on Apr 24, 2007 at 12:14 UTC ( [id://611704] : note . print w/replies, xml ) Need Help??

in reply to problem with File::Cat

Yes it is a nice feature see "perldoc perlrun"

What did you expect the -l option to do when you added it?

Replies are listed 'Best First'.
Re^2: problem with File::Cat
by tbone1 (Monsignor) on Apr 24, 2007 at 12:22 UTC
    Or, from the man page:

    It has two separate effects. First, it automatically chomps $/ (the input record separator) when used with -n or -p. Second, it assigns "$\" (the output record separator) to have the value of octnum so that any print statements will have that separator added back on. If octnum is omitted, sets "$\" to the current value of $/.

    Or, in the vernacular, if you include the -l option, it will add an end-of-line to each print.

    tbone1, YAPS (Yet Another Perl Schlub)
    And remember, if he succeeds, so what.
    - Chick McGee

Re^2: problem with File::Cat
by jeanluca (Deacon) on Apr 24, 2007 at 13:12 UTC
    Don't get me wrong, the -l is very nice, but not when you cat files (especially not with binary files)!
    I cannot think of a situation in which this kind of behavior can be useful!!

    Anyway from the suggested docs the answer to my problems was simple
    { local $\ ; # do 'cat' stuff here }
    Thanks a lot

    UPDATE: I checked the code from the cpan module File::Cat and I would suggest to change the following
    while (<FILE>) { print $handle $_; }
    while (<FILE>) { printf $handle $_; }
    (not tested)
      You definitely do not want to use printf like that!   The second argument in your example is the format string so any % characters in it will be interpreted by printf.
        hmm, thats a very good point. Then
        { local $\ ; while (<FILE>) { print $handle $_; } }
        would probably be the best solution, or do I miss something (again) ?