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:
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |