Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Turning a questionable string into a number

by bradcathey (Prior)
on Jun 29, 2017 at 19:40 UTC ( [id://1193866]=note: print w/replies, xml ) Need Help??


in reply to Re: Turning a questionable string into a number
in thread Turning a questionable string into a number

Good questions, but the only thing I haven't given you is a self-contained example that you could run. Apologies. However, I just resaved the file out as unicode 8-bit and everything worked just fine. So, problem solved. A big thanks to all who took the time to response.

—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot

Replies are listed 'Best First'.
Re^3: Turning a questionable string into a number
by haukex (Archbishop) on Jun 29, 2017 at 19:53 UTC
    I just resaved the file out as unicode 8-bit and everything worked just fine.

    Ah yes, Windows does like UTF-16...

    use warnings; use strict; use Encode 'encode'; my $in = "1130\t"; my $str = encode('UTF-16', $in, Encode::FB_CROAK); $str=~s/^\xFE\xFF|\t//g; # remove BOM & tab print $str*1, "\n"; __END__ Argument "\01\01\03\00\0" isn't numeric in multiplication (*) at - lin +e 7. 0

    An alternative for you would also be open($fh, '<:raw:encoding(UTF-16)', 'filetoparse.txt') ... (Updated to add :raw as per choroba's reply, thanks!)

      Also note that on Windows, you need to specify :raw first when specifying a file encoding. See e.g. Re^3: unicode in windows.
      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (7)
As of 2024-03-28 21:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found