I have an input file of the form :
MML v2.0; import defaultunit; unit conversion on; math top { t.min = 0; t.max = 3600; t.delta = 5; .........
I need to extract the t.min and t.max values. The code i have written does not print the value but prints t.min and t.max a 1000 times.
#!usr/bin/perl use strict; use warnings; use Getopt::Long; my $file; GetOptions("f|file=s" => \${file}) or die "invalid option\n"; if ($file) { my $fname = $file; open (INFO,"<",$fname) or die " Could not open\n" ; open (OUTFO,">>","text.txt") or die "Could not open\n"; my (@line, $myline); @line=<INFO>; foreach $myline(@line) { if($myline=~ /(t\.min=)(.*)(;)/) {print OUTFO "tmin = $2\n";}; if($myline=~ /(t\.max=)(.*)(;)/) {print OUTFO "tmax = $2\n";}; } close OUTFO; close INFO; }
Please help. Thankyou for all the help. I have to parse the whole file and print to a text file, i have gotten stuck in the first step itself, am kind of worried now. Thanks again.

In reply to Help : Regular expression by kitty

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.