Hi, i am really new to Perl because before this i worked on Excel VBA. For now i have 3 different perl scripts in VNC that i plan to combine them into one.

The first script will ask user for file name (e.g summary.txt), find the matching string in the summary.txt and saved the output in inout.txt using command on console "perl step1.pl summary.txt > inout.txt". But error will occur Then, i run the second script just to take all the necessary data based on the requirement and saved the output in result.txt using command on console "perl step2.pl inout.txt > result.txt. The third script will send result.txt to an email which can be viewed in Windows. I know that it is possible but i have no idea on how to do it as i got stuck on thinking how to open summary.txt file to read and open inout.txt to write at the same time.

I add this code below in step1.pl but then i cannot run the script on console using "perl step1.pl summary.txt > inout.txt"

print "Enter the name of the file: "; my $base_dir = <>; chomp($base_dir);open( my $DATA, "<" , $base_dir) or die "Can't open f +ile '$base_dir': $!"; while ( <$DATA> )

step1.pl

#! /tools/perl/5.8.8/linux/bin/perl use strict; use warnings; while (<>) { if ($_ =~ /^\s\s(\S+)*delay\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+ +(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+) +/) { print "$_"; } }

step2.pl

#! /tools/perl/5.8.8/linux/bin/perl use strict; use warnings; while ( <> ) { #if my ( $set ) = m/^\s+(\S+)/; #get the first word my ( $name,$value ) = m/-name (\S+) (\S+)/; #get the name and value my ( $mode ) = m/mode == (\S+)\"/; #get the mode print "$mode $name $set $value\n"; }

step3.pl

#! /tools/perl/5.8.8/linux/bin/perl use strict; use warnings; my $name='inoutdata'; system("uuencode /home/user/set/result.txt | mailx -s '$name' email");

In reply to 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.