Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

writing a var to a txt file 2

Status
Not open for further replies.

romerz

IS-IT--Management
Jul 19, 2006
29
GB
I have a file named returns.txt

I have the sql working correctly, if i just use

Code:
print $orderId;
print "<br>";

it lists everything I would expect.

However this doesnt seem to work.

Code:
open (RETURNFILE, '>returns.txt');
print RETURNFILE $orderId
clode (MYFILE);

Have I missed something, or is that not the way to write to a file?
 
Yes. AFAIK, 'clode' isn't a perl function, and if it was, you are cloding the wrong file handle...[smile]

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
haha it actually says close :p

that was a typo when i was typing the code :(
 
its all good in the hood, i forgot to add the path :)
 
try
Code:
open (RETURNFILE, '>returns.txt') or die "Can't open file: $!";

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
cheers (Y)

Dont supose you happen to know off hand how I would go about comparing the value of a variable to everything in the list :p ?
 
What list? You'd need to be more specific.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
well I have a list called returns.txt

I want to be able to basically:

if ($orderId eq anything in the list)
{
then do something
}

In a nutshell, ive been trying all sorts of read methods but im not fully getting them going as I thought or think they should work.
 
OK. Assuming that returns.txt is just a list of order numbers...
Code:
use strict;
use warnings;
my $orderId = 666;
my %list;

open(LIST, "returns.txt") or die $!;
while (<LIST>) {
   chomp;
   $list{$_}++;
}
close(LIST);

if (exists $list{$orderId}) {
   # do stuff
}
If not, you may have to parse it as you read it to get the order number.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
That doesnt seem to work, doesn't so anything :(
 
My bad, changed it a little bit and its spot on. Thanks alot for all of your help. Saved my ass :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top