in reply to Re^3: String manipulation
in thread String manipulation

Thanks, moritz indicated that this was a "not so safe" way of doing this, any suggestions of a safer means?

Replies are listed 'Best First'.
Re^5: String manipulation
by graff (Chancellor) on Aug 07, 2007 at 22:28 UTC
    To be clear: moritz was talking about "removing all initial non-whitespace characters", and saying that it would be "not so safe" to do that -- and he would be right, in the sense that sometimes, initial non-whitespace characters might not be garbage, and it would be bad to remove them.

    GrandFather has proposed a different approach: just remove null bytes. There is nothing "unsafe" about this -- null bytes carry no relevant information, and they just get in the way. Deleting null bytes from your strings is a Good Thing.

Re^5: String manipulation
by GrandFather (Saint) on Aug 07, 2007 at 22:20 UTC

    What moritz suggested was stripping any non-whitespace characters. The regex I suggested just removes leading ASCII null characters. For the task at hand that should be completely safe.

    I strongly recommend that you learn about Perl regular expressions. See perlretut, perlre and perlreref. A browse around the Tutorials section here is likely to pay off too.


    DWIM is Perl's answer to Gödel