in reply to Re^2: Copy rows of file to new document
in thread Copy rows of file to new document
This is not doing what you think. The backslash has a special meaning in double quotes. Fortunately, you can use a normal slash /.my $dir_path="\Incoming\Temp";-
Where is $tmp_dir coming from? Do you mean $dir_path? Moreover, you cannot use a non-alphanumeric character in a dirhandle name. Remove the backslash. Even better - use a lexical dirhandle:opendir (Incoming\Temp, $tmp_dir) or die $!;opendir my $DIR, $dir_path or die $!; -
Not really an error, but can be improved: use a lexical filehandle, 3-argument version of open, and test for failure:open (MYFILE, '>>vehicles.txt');open my $OUT, '>>', 'vehicles.txt' or die $!; -
Also note that $file_content is empty and undeclared. You probably want to use it inside the while loop to populate the output file:
BTW, have you noticed the directory path must be prefixed to the filename?while (my $filename = readdir $DIR) { open my $FILE, '<', "$dir_path/$filename" or die $!; while (my $content = <$FILE>) { print $OUT $content; } }
Perl is case sensitive. The function is in lowercase: closedir. Also, give it an argument.CLOSEDIR;
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Copy rows of file to new document
by phineas629 (Novice) on Jan 25, 2013 at 21:32 UTC | |
by choroba (Cardinal) on Jan 25, 2013 at 21:49 UTC |
In Section
Seekers of Perl Wisdom