Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: How to insert Hexadecimal characters

by dHarry (Abbot)
on Dec 03, 2009 at 09:53 UTC ( [id://810792]=note: print w/replies, xml ) Need Help??


in reply to How to insert Hexadecimal characters

I produce a lot of ASCII files that need to end in '0D0A'. The script can be run from both Windows and Linux. Normally I do something like:

my $line_delimiter = ($^O eq "MSWin32")?"\n":"\r\n"; sprintf("%-$line_width" . "s", $line) . $line_delimiter;

The line-width is typically 78 or 70 (excluding the 2 added by the line-delimiter) for my purpose. Tailor it according to your needs.

Cheers

Harry

Replies are listed 'Best First'.
Re^2: How to insert Hexadecimal characters
by johngg (Canon) on Dec 03, 2009 at 10:29 UTC
    sprintf("%-$line_width" . "s", $line) . $line_delimiter;

    I think all the concatenation in this line is a little confusing. I'd prefer to interpolate everything in the format string. My assumption is that you are using the sprintf as the return from a subroutine or a do block. Obviously, use printf if you expect actual output.

    sprintf qq{%-${line_width}s$line_delimiter}, $line;

    I hope this is of interest.

    Cheers,

    JohnGG

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://810792]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-24 02:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found