in reply to Saving my output to a folder

The following will loop until the user first types in a PPID, then until they type 'y' to confirm it.

It then writes the PPID to $outfile in the $dir directory.

use strict; use warnings; my $outfile = 'ppid_file.txt'; my $dir = 'c:/users/lastgen/docs/saved_ppid'; my $input; my $ok = ''; while ($ok !~ /[Yy]/){ print "SCAN PPID: "; $input = <STDIN>; chomp $input; print "Make sure you confirm the PPID before you proceed...\n\n"; print "PPID: $input \n\n"; print "ok? [y/n]: "; $ok = <STDIN>; } open my $wfh, '>', "$dir/$outfile" or die "can't open the damned output file! $!"; print $wfh $input;

Replies are listed 'Best First'.
Re^2: Saving my output to a folder
by LastGen Monk (Novice) on Apr 19, 2016 at 20:06 UTC
    Thank you so much. I really appreciate. You're a lifesaver.
      If you will be running this script multiple times, each run will overwrite the previously saved ppid.

      If you want to preserve/append to the PPID instead, use this construct to open the file in "append" mode:

      open my $wfh, '>>', "$dir/$outfile" or die "ERROR: Can't open/append the damned output file! The OS says +:$!";

              This is not an optical illusion, it just looks like one.

        Thanks, If I want to add every new scanned PPID as a new text file in that folder what should I do? Like having a list of text files in the destination folder. I will really appreciate any help.
Re^2: Saving my output to a folder
by LastGen Monk (Novice) on Apr 20, 2016 at 11:46 UTC
    Steveib, Is it possible I can name the output text file in the destination folder as whatever text or number that is scanned or entered? for example if I scan or enter the PPID as ABCDEDEF..., can auto-save the text file as scanned item's name i.e. ABCDEDEF.... and so on? At least how can save each scanned item as a new txt file in the destination folder?