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

Comment on

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

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.

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

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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?

    What's my password?
    Create A New User
    [corenth]: Good morning (in my neck of the woods)
    [Cosmic37]: hello perly kings and queens
    [jedikaiti]: 'ello Monks
    [Cosmic37]: and monkeys too...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (8)
    As of 2018-02-20 18:09 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (274 votes). Check out past polls.