LinuxQuestions.org
Help answer threads with 0 replies.
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 09-18-2004, 01:21 PM   #1
Tinku
Member
 
Registered: Jul 2004
Location: INDIA
Distribution: SusE, Gentoo,Debian,FreeBSD
Posts: 197

Rep: Reputation: 30
perl help


I wrote the following piece of code.
I want to modify it such that i can give the new_msg from outside the file,changing everytime , something like an argument.
how to do this?
i am new to perl

tia
tinku



Code:
#!/usr/bin/perl

  $new_msg = "My msg text here";

 open (msg, ">>msg.txt") || die ("Could not open file. $!");
 print msg ($new_msg);
 close (msg);
 
Old 09-18-2004, 01:47 PM   #2
mirradric
Member
 
Registered: May 2004
Location: Singapore
Distribution: Debian woody and debian sarge
Posts: 188

Rep: Reputation: 31
can't really remember but it should be in the @ARGV array/list
 
Old 09-18-2004, 01:51 PM   #3
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
$new_msg = @ARGV[0]
 
Old 09-18-2004, 01:57 PM   #4
Vookimedlo
Member
 
Registered: Jul 2004
Location: Czech Republic - Roudnice nad Labem
Distribution: Debian
Posts: 253

Rep: Reputation: 34
Code:
#!/usr/bin/perl
$new_msg = shift;
open (msg, ">>msg.txt") || die "Could not open file. $!";
print msg $new_msg."\n";
close (msg);
run it like this:
./t.pl 'Vookimedlo is watching you!'
 
Old 09-18-2004, 11:03 PM   #5
Tinku
Member
 
Registered: Jul 2004
Location: INDIA
Distribution: SusE, Gentoo,Debian,FreeBSD
Posts: 197

Original Poster
Rep: Reputation: 30
thnx guys,both the 2 methods r working

thnx
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Problem with perl module for w3c validator to work on my local Apache+PHP+perl instal tbamt Linux - Software 0 12-16-2004 05:37 PM
cgi perl : I cant get perl to append my html file... the_y_man Programming 3 03-22-2004 05:07 AM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM
chrooting apache v2 (php, ssl, perl support) ; perl configuration markus1982 Linux - Security 3 01-26-2003 06:15 PM
can i set ~/public_html/perl as a perl directory for apache? doublefailure Linux - Networking 1 07-09-2002 04:31 PM

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

All times are GMT -5. The time now is 04:55 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