Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

comment on

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

The problem was in the

$combined =~ s/[^\x00].*//;
I tried to print the variable with</code> print "\$combined=",unpack("H*",$combined)," ($combined)\n"; </code> and was really surprised:
¢¼combined=0c0d060a183672756e33 (”Ļ ”č6run3) $combined=0a183672756e33 ( ”č6run3) Prefix is "model4r"
(I'd be even more surprised if this went through correctly.)

Guess what was the problem ... well the .* did not match everything. I forgot that without /s dot doesn't match newlines. So the fix is very simple

... $combined =~ s/[^\x00].*//s; ...
Actually thinking about this it would probably be better to change the last three lines to:
$combined =~ /^(\x00*)/; my $prefix = substr($first, 0, length($1)); print qq{Prefix is "$prefix"};

I should have tested my code better :-(

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
   -- Rick Osborne

Edit by castaway: Closed small tag in signature

In reply to Re: Re: Re: Re: Re: Find common prefix from a list of strings by Jenda
in thread Find common prefix from a list of strings by Albannach

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
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (4)
    As of 2020-02-18 03:17 GMT
    Find Nodes?
      Voting Booth?
      What numbers are you going to focus on primarily in 2020?

      Results (74 votes). Check out past polls.