Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re^3: Turning a questionable string into a number

by haukex (Archbishop)
on Jun 29, 2017 at 19:53 UTC ( [id://1193867]=note: print w/replies, xml ) Need Help??

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

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!)

Replies are listed 'Best First'.
Re^4: Turning a questionable string into a number
by choroba (Cardinal) on Jun 29, 2017 at 20:00 UTC
    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?

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-06-25 13:20 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.