supriyoch_2008 has asked for the wisdom of the Perl Monks concerning the following question:
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:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How can one input a textfile from desktop just created?
by NetWallah (Canon) on Mar 08, 2014 at 05:02 UTC | |
by supriyoch_2008 (Monk) on Mar 08, 2014 at 06:54 UTC | |
|
Re: How can one input a textfile from desktop just created?
by Athanasius (Archbishop) on Mar 08, 2014 at 04:46 UTC | |
by supriyoch_2008 (Monk) on Mar 08, 2014 at 06:52 UTC | |
by Athanasius (Archbishop) on Mar 08, 2014 at 09:43 UTC | |
by Laurent_R (Canon) on Mar 08, 2014 at 17:03 UTC | |
|
Re: How can one input a textfile from desktop just created?
by ww (Archbishop) on Mar 08, 2014 at 12:34 UTC |