LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-23-2011, 08:33 PM   #1
jimtony
Member
 
Registered: Jan 2011
Location: Shanghai,China
Distribution: fedora
Posts: 73
Blog Entries: 1

Rep: Reputation: 2
PERL: How to write a new file?


Hi all,
I have a problem when writing text to a new file.
Code:
#!/usr/bin/perl

use strict;
use warnings;

open( my $fh," > output.txt");

print $fh,"this is test1.\n";
print $fh,"this is a test2.\n";

close $fh;
And the output of this script is:
Quote:
GLOB(0x8d52768)this is test1.
GLOB(0x8d52768)this is a test2.
And the output.txt file is empty.
I do not know why.
 
Old 11-23-2011, 09:50 PM   #2
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 709

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
Hi.

There should be no comma between file handler and text:
Code:
print $fh "this is test1.\n";
print $fh "this is a test2.\n";
 
1 members found this post helpful.
Old 11-23-2011, 10:33 PM   #3
jimtony
Member
 
Registered: Jan 2011
Location: Shanghai,China
Distribution: fedora
Posts: 73

Original Poster
Blog Entries: 1

Rep: Reputation: 2
Thank you.firstfire.
That is the root cause.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
perl - writing to file - keep open or only during write? eherron.lanline Programming 2 05-27-2011 07:28 PM
Shell Script or perl help. to write sections of a log to a tmp file for mailing pobman Programming 2 02-02-2009 03:30 PM
How to write to a file from a form with perl, and not leave the form page. OldGaf Programming 3 11-12-2008 07:53 PM
perl write to file Xris718 Programming 7 06-03-2005 09:10 AM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration