Hi PerlMonks,

I am interested in uploading a text file which has been just created on desktop to save results. For this I have written a script m1.pl given below. The cmd is showing error "Use of uninitialized value $new". I am at my wit's end to solve this problem. Please help me.

Here goes the script m1.pl:

#!/usr/bin/perl use warnings; ################################## # Output to a text file: ################################## $output1="j.txt"; open (my $fh1,">",$output1) or die"Cannot open file '$output1'.\n"; ################################## $a="John is"; $b="a good boy"; $join=$a.$b; # Concatenate print "\n Complete sentence:\n $join\n\n"; print $fh1 "\n Complete sentence:\n $join\n\n"; ####################################### # To input textfile j.txt from desktop: ####################################### open FILE,"j.txt" or die "Can't open file:$!"; while (<FILE>) { $new .=$_;} close FILE; print "\n Uploaded file content:\n $new\n\n"; exit; #########################

Incorrect results of cmd:

Microsoft Windows [Version 6.1.7600] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\x>cd desktop C:\Users\x\Desktop>m1.pl Complete sentence: John isa good boy Use of uninitialized value $new in concatenation (.) or string at C:\U +sers\x\Desktop\m1.pl line 30. Uploaded file content:

In reply to How can one input a textfile from desktop just created? 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.