473,326 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

assigning contents to file name............

Hi,

quick question,

how would you assign a contents to file in perl

i was thinking

$filename=`echo newvalue > filename`;

would work, but it does not, can someone please let me know what
i am missing?

thanks in advance

part of the codes--------------------------------------------

#!/usr/bin/perl -w

$filename=`cat filename`;
print "\$filename has $filename \n";

if ($filename eq 'today') {
$file_value=tomorrow;
$filename=`echo tomorrow > filename`;}
else {
$file_value=today;
$filename=`echo today > filename`;
}
Jul 19 '05 #1
5 3910
rx****@hehe.com wrote:
how would you assign a contents to file in perl
What on earth do you mean by "assign a contents to file"?
i was thinking
$filename=`echo newvalue > filename`;
would work, but it does not, can someone please let me know what
i am missing?
part of the codes--------------------------------------------
Your code doesn't even compile!
#!/usr/bin/perl -w

$filename=`cat filename`;
print "\$filename has $filename \n";

if ($filename eq 'today') {
$file_value=tomorrow;
Unquoted string "tomorrow" may clash with future reserved word at ...
$filename=`echo tomorrow > filename`;}
else {
$file_value=today;
Unquoted string "today" may clash with future reserved word at ...
$filename=`echo today > filename`;
}


Are you simply trying to write something to a file?

Then you may want to read
perldoc -f open (pay particular attention the mode indicator)
perldoc -f print
perldoc -f close

jue
Jul 19 '05 #2
"Jürgen Exner" <ju******@hotmail.com> wrote in message news:<Ev******************@nwrddc01.gnilink.net>.. .
rx****@hehe.com wrote:
how would you assign a contents to file in perl


What on earth do you mean by "assign a contents to file"?
i was thinking
$filename=`echo newvalue > filename`;
would work, but it does not, can someone please let me know what
i am missing?
part of the codes--------------------------------------------


Your code doesn't even compile!
#!/usr/bin/perl -w

$filename=`cat filename`;
print "\$filename has $filename \n";

if ($filename eq 'today') {
$file_value=tomorrow;


Unquoted string "tomorrow" may clash with future reserved word at ...
$filename=`echo tomorrow > filename`;}
else {
$file_value=today;


Unquoted string "today" may clash with future reserved word at ...
$filename=`echo today > filename`;
}


Are you simply trying to write something to a file?

Then you may want to read
perldoc -f open (pay particular attention the mode indicator)
perldoc -f print
perldoc -f close

jue


I am trying to do (task A) on one day and (Task B) on next
day(alternating).
I thought about how to do it, and thought that only way to do it would
be
to write what whether I did A or B and put that value into file(let's
say file_name, and put A since I did A today) and next day I would do
what's opposite based on what's in that file(file_name, since A is in
this file, I would now do B ). and run this for 24x7.....

I didn't want to run the open/print/close commands. Was just wondering
if there was simple way to do it or just use ` ` to excute unix
command and assign to the file name.
Jul 19 '05 #3
On 6/2/04 9:09 am, in article
8a**************************@posting.google.com, "rx****@hehe.com"
<rx****@hehe.com> wrote:
Hi,

quick question,

how would you assign a contents to file in perl

i was thinking

$filename=`echo newvalue > filename`;

would work, but it does not, can someone please let me know what
i am missing?

thanks in advance

part of the codes--------------------------------------------

#!/usr/bin/perl -w

$filename=`cat filename`;
print "\$filename has $filename \n";

if ($filename eq 'today') {
$file_value=tomorrow;
$filename=`echo tomorrow > filename`;}
else {
$file_value=today;
$filename=`echo today > filename`;
}


evaluating the backticks operator in a scalar context
returns the success result of the command executed

you could use..

use strict;
my @ex_filename = `cat filename`' # 'filename' is fully qualified
my $contents = $ex_filename[0]; # we're assuming lots about 'cat' here!
($contents =~ /today/) ? `echo tomorrow > filename` : `echo today >
filename`;
exit;
not much checking going on though! would like to see some error
catching if the file isn't there etc. :)

david
emology.com

Jul 19 '05 #4
david scholefield wrote:
$filename=`cat filename`;
print "\$filename has $filename \n";


evaluating the backticks operator in a scalar context
returns the success result of the command executed


No, it does not. It returns the entire contents of the output
from the command; all the lines concatinated into a single string.
The success result is in $?, as described in
perldoc perlvar
-Joe
Jul 19 '05 #5
On 1/3/04 9:31 am, in article 4qD0c.8525$ko6.196434@attbi_s02, "Joe Smith"
<Jo*******@inwap.com> wrote:
david scholefield wrote:
$filename=`cat filename`;
print "\$filename has $filename \n";


evaluating the backticks operator in a scalar context
returns the success result of the command executed


No, it does not. It returns the entire contents of the output
from the command; all the lines concatinated into a single string.
The success result is in $?, as described in
perldoc perlvar
-Joe


Yup - you're quite right. *duh* Never do it personally, always
read into list :)


Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: yawnmoth | last post by:
say i have a zip file - test.zip - with a file - somefile.txt - in it, whose contents are as follows: this is a test when i try running the following script on the above zip file, i get...
33
by: Jason Heyes | last post by:
I would like to modify the contents of a file, replacing all occurances of one string with another. I wrote these functions: bool read_file(std::string name, std::string &s); bool...
1
by: Jeremy Chapman | last post by:
How can I display a file open dialog by clicking a button in an aspx page, have the user select a text file then display the contents into a control such as a text box
3
by: Mark | last post by:
For purposes of sending the contents of a file to a function that requires a string, I am trying to find a way to read a file to a string variable & pass it along. For example, if the file...
1
by: Beowulf | last post by:
I have a report laid out in Design View as shown at the end of this message. I have code that performs the following steps: 1. In main report's Report_Open(), DELETE any old rows in tblTOC for...
10
by: Steve Pope | last post by:
The first of the following functions compiles, the second gives what I think is a spurious error: "cannot convert `const char' to `char *' in assignment". void foo(int m) { char *str; if (m...
1
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
3
by: =?Utf-8?B?R3JlZyBN?= | last post by:
Hello, I'm running an asp.net, intranet web application using .net framework 1.1 on IIS5.1 / 6.0. Through the web application, I would like to press a button on the web page, have another window...
2
by: hotflash | last post by:
Hi Master CroCrew, I found a good PURE ASP that will allow you to upload 10MB file to the server and the file contents such as Network, Author, Title, etc... will insert to MS Access at the same...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.