💾 Archived View for thrig.me › blog › 2023 › 10 › 30 › randline.pl captured on 2024-07-09 at 01:54:59.

View Raw

More Information

⬅️ Previous capture (2023-11-04)

-=-=-=-=-=-=-

#!/usr/bin/perl
# randline.pl - which is the same as the one-liner
#   perl -e 'rand($.) < 1 && ($p = $_) while <>; print $p'
while ( $line = readline ) {
    if ( rand($.) < 1 ) {
        $pick = $line;
    }
}
print $pick;