Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Converting ASCII string to Decimal

by monkfan (Curate)
on Dec 22, 2008 at 14:46 UTC ( #732096=perlquestion: print w/replies, xml ) Need Help??
monkfan has asked for the wisdom of the Perl Monks concerning the following question:

Most Revered Monks,
How can I convert the ASCII strings like this, for example:
_DATA__ ORQ>IK FDC
into its decimal format like this:
79 82 81 62 73 75 70 68 67
Hence, the output for each strings is an array of decimal values. Each decimal values correspond to every character in ASCII string.

Is there a compact way to do it with Perl?

Regards,
Edward

Replies are listed 'Best First'.
Re: Converting ASCII string to Decimal
by jdporter (Canon) on Dec 22, 2008 at 14:51 UTC
    map ord, split //
    As in:
    local( $,, $\ ) = ( ' ', "\n" ); while (<DATA>) { chomp; print map ord, split // }
Re: Converting ASCII string to Decimal
by BrowserUk (Pope) on Dec 22, 2008 at 14:57 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://732096]
Approved by moritz
help
Chatterbox?
[Corion]: 1nickt: Would be great, especially for naming parameters in @_.
[Corion]: When you pass an arrayref, you get to treat it like a local array. But then, I'm cautious with the experimental features, because just when I thought function signatures were a set thing, there is a proposal to use sub [ $foo, $bar ] { ... } to ...
[Corion]: ... declare the parameters, instead of the more common sub ($foo, $bar) { ... }

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2017-11-17 20:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (272 votes). Check out past polls.

    Notices?