Hi Perl Monks,

I am a beginner in perl. I am interested in writing the results of a subroutine for data formatting to a text file. The cmd screen shows correct results but copying the results from cmd screen using the mouse is often difficult. So I want the results directly to a text file on desktop. Is there any perl syntax for this? I have given the perl code (fm.pl), the correct results of cmd and the incorrect text file Fmd.txt. below. How can I overcome this problem? Please suggest me some reading materials for writing to a text file in perl.

#!/usr/bin/perl-w $a="BATCATEATFATRAT"; $b=print_sequence($a,3); print"\n Scalar b=$b\n"; $output="Fmd .txt"; unless (open(RESULT,">$output")){ print"Cannot open file\"$output\".\n\n"; exit; } print RESULT"\n Formatted Data: $b\n\n"; close(RESULT); exit; sub print_sequence { my($sequence, $length) = @_; for (my $pos = 0; $pos < length($sequence); $pos += $length ) { print substr($sequence, $pos, $length), "\n"; } }

I have got the correct 3-letter words in cmd.

Microsoft Windows [Version 6.1.7600] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\X>cd desktop C:\Users\X\Desktop>fm.pl BAT CAT EAT FAT RAT Scalar b= C:\Users\X\Desktop><code> <p> But the text file Fmd.txt does not show the words:</p> <code>Formatted Data:

In reply to Is it possible to write the results of a subroutine for data formatting to a text file? by supriyoch_2008

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.