ok, i'm trying to convert a text file of subtitles for a video clip from this format:
1 00:00:38,585 --> 00:00:40,519 What's wrong? 2 00:00:40,554 --> 00:00:43,148 I think I hit something.
to this one:
#1 00;00;38;59 00;00;40;52 What's wrong? #2 00;00;40;55 00;00;43;15 I think I hit something. #3 00;00;43;92 00;00;45;41 You think it's a rock?
so, i wrote this script to do the job, but im having problems and its prolly some blatantly obvious thing i cant see cause i wrote it...please help:
open(IN,"./$file"); @infile = <IN>; close(IN); open(OUT,">$file-FORMATTED.txt"); @sections = split(/\n/, @infile); foreach $i (@sections) { ($l1,$l2,@l3) = split(/\n/,$i); $output = "#",chomp($l1); $l2 =~ s/(\d\d)\:(\d\d)\:(\d\d),(\d\d\d) --> (\d\d)\:(\d\d)\:(\d\d +),(\d\d\d)/\1;\2;\3;\4 \5;\6;\7;\8/; $x = $4; $y = $8; if(substr($x,2,1) > 5) { $x = substr($x,0,2); $x++; } else { $x = substr($x,0,2); } if(substr($y,2,1) > 5) { $y = substr($y,0,2); $y++; } else { $y = substr($y,0,2); } $l2 =~ s/(\d\d;\d\d;\d\d;)\d\d\d (\d\d;\d\d;\d\d;)\d\d\d/\1$x \2$y +/; $output .= "$l2\n", join("\n",@l3), "\n"; print OUT $output; undef $l1; undef $l2; undef $x; undef $y; undef @l3; } close(OUT);

In reply to text reformatting woes by Anonymous Monk

Title:
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, details, 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, summary, 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.