Hello mmazlan67 and welcome to the monastery and to the wonderful world of Perl!

> got stuck on thinking how to open summary.txt file to read and open inout.txt to write at the same time.

This is very simple: you open a filehandle in read mode and another in write mode. You use the diamond operator <> too much: it is handy but also magic, infact instead of print "Enter the name of the file: "; my $base_dir = <>; you better my $base_dir = <STDIN>; ( $userinput is a better name than $base_dir anyway..) so start out with plain things:

# never forget the following!!! use strict; use warnings; # use diagnostics; # this can be skipped but is useful when starting # grab user input.. # choose a file name for the out file.. ... open my $readhandle, '<', $filetoread or die "Unable to read [$filetor +ead]!"; open my $writehandle '>', $filetowrite or die ""Unable to write [$file +toread]!"; # not <> but a named lexical filehandle while (<$readhandle>){ if ($_ =~ /somethingtosearch/){ # print to the write file print $writehandle $_; } } # always explicitally close filehandle: Perl will normally does the ri +ght thing but it is safer to close them anyway (good habit) close $readhandle; close $writehandle; # take the file and attach to an email ...

This is the basic. After you have a working skeleton code you can add some more feature as more error control or a more elegant way to parse command line arguments aka Getopt::Simple or Getopt::Long

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: How to ask user for file name and save the output to a new text file by Discipulus
in thread How to ask user for file name and save the output to a new text file by mmazlan67

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.