Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Turning a questionable string into a number

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

in reply to Turning a questionable string into a number

Based on what you've shown us that is quite strange. Are you sure you're grabbing the correct field with $data[12], and have you looked at the hex dump of the entire line? Could you provide us with enough data to reproduce this, like an entire line of input from your file? Have you by any chance reduced the code that you're showing us a little too much, like perhaps you use the ^, |, or & operators somewhere (the latter two maybe accidentally instead of || resp. &&)? See also Short, Self-Contained, Correct Example. Update: Oh yes, and please turn on $Data::Dumper::Useqq=1; or use Data::Dump instead.

Replies are listed 'Best First'.
Re^2: Turning a questionable string into a number
by bradcathey (Prior) on Jun 29, 2017 at 19:40 UTC

    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.

    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot
      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?

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-06-23 21:01 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.