Dear Monks, I have an input file which has 4 entries per line. But I am not sure how many lines will be there in the input file.
Jakarta 30 indonesia 40 Beijing 50 China 20
I want to print out something like
1. Temperature in Jakarta is 30, but average temp in indonesia is 40 d +egrees. 2. Temperature in Beijing is 50, but average temp in China is 20 degre +es.
I am not sure how to save the 4 words and split them using delimiter so that I can actually use them somewhere. I think I am way off in the coding part, since I am new to perl. This is what I wrote, but this doesnt work.
open(my $fh, '<', 'Citytempfile.txt') or die "Cannot open cellnames.txt: $!"; my $i = 0 while (<$fh>) { my @array = split ' ', <$fh> print $fileHandle_drc $i+1, 'Temperature in ',$array[0], ' is ', $arr +ay[1], 'but average temp in ', $array[2], 'is', $array[3] ; $i++; }

In reply to read text file and generate an output file with information present in text file. by Ganesh Bharadwaj1

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.