Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Hi

I've been writing some code to trundle through Mozilla Thunderbird's mbox format (with an eventual aim to copying all the folder structure and the emails to an IMAP server), and I've come up against the following problem. I think this is where my lack of a computer science education fails me. I'm trying to parse the X-Mozilla-Status field, which is stored as a string. I've thought of prepending a "0x" and evaling the result, but, after reading Pack/Unpack Tutorial (aka How the System Stores Data) I thought I should be able to do this with pack.

#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my $string = "0002"; my $MSG_FLAG_READ = 0x0001; my $MSG_FLAG_REPLIED = 0x0002; my $MSG_FLAG_MARKED = 0x0004; my $MSG_FLAG_EXPUNGED = 0x0008; my $MSG_FLAG_HAS_RE = 0x0010; my $MSG_FLAG_ELIDED = 0x0020; my $MSG_FLAG_OFFLINE = 0x0080; my $MSG_FLAG_WATCHED = 0x0100; my $MSG_FLAG_SENDER_AUTHED = 0x0200; my $MSG_FLAG_PARTIAL = 0x0400; my $MSG_FLAG_QUEUED = 0x0800; my $MSG_FLAG_FORWARDED = 0x1000; my $MSG_FLAG_PRIORITIES = 0xE000; my $value = pack("H4", $string); #print Dumper(\$value); if($value && $MSG_FLAG_READ) { print "Message has been read\n"; } else { print "Unread message\n"; }
I would expect this to produce "Unread message", but the "if" is always successful. I'd also expecting the writing of this node to lead me to the answer as usual, but there you go.


davis
Kids, you tried your hardest, and you failed miserably. The lesson is: Never try.

In reply to Using pack to evaluate text strings as hexadecimal values by davis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (7)
    As of 2014-12-21 21:50 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (108 votes), past polls