parsed.org

Tips by tag: foreach

Removing Comments by xinu on Jan 15, 2005 03:09 PM

If you're having to match lines that start with # you can avoid using an expression if you do something like this:

foreach ($lines as $line) {
    if ($line{0} != '#') {
        // We have a non-comment, print it.
        echo $line . '<br />';
    }
}
foreachlanguagesphpprogrammingsyntax
Replace CR/LF with CR by xinu on Jun 07, 2005 11:21 AM

Given an array @slobber, replace all the CR-LF with CR:

foreach (@slobber) {
   s/\015\012$/\n/; print;
}
dosforeachlanguagesline-endingsperlprogrammingsyntaxunix
RSS