Skip to content

Instantly share code, notes, and snippets.

@epixoip
Created November 5, 2019 07:07
Show Gist options
  • Save epixoip/96fc3baa3992b1b13c7bcf92f4c13bd4 to your computer and use it in GitHub Desktop.
Save epixoip/96fc3baa3992b1b13c7bcf92f4c13bd4 to your computer and use it in GitHub Desktop.

Revisions

  1. Jeremi M Gosney created this gist Nov 5, 2019.
    27 changes: 27 additions & 0 deletions test_delims.pl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    #!/usr/bin/env perl

    use strict;
    use warnings;

    my @delims = ( 9, 11, 28, 29, 30, 31, 32 .. 47, 58 .. 64, 91 .. 96, 123 .. 126 );

    my $file = $ARGV[0] || die "Usage: $0 <filename>\n";

    open (my $fh, "<", $file) || die "Unable to open $file: $!\n";

    my $line = 0;

    while (my $row = <$fh>) {
    my %occur = ();

    chomp $row;

    foreach my $delim (@delims) {
    my $char = chr $delim;
    $occur{$delim} = length( $row =~ s/[^\Q$char\E]//rg );
    }

    my @occurs = sort { $occur{$a} <=> $occur{$b} } keys %occur;

    printf ("Line %s appears to be '%s' (chr %d) delimited\n", $line++, chr $occurs[-1], $occurs[-1]);
    }