open(data,' variable problem

N

NoViagraHere

I am trying to open a text file in the same directory as the script is
located to retrieve stored info. The text file is simply named:
216.1.1.2


This code will NOT work:

$ip = '216.1.1.2';
open (data, $ip);
@mailtext=<data>;
close data;
print @mailtext;


however if I replace $ip as below, It DOES work. Any ideas?

open (data, '216.1.1.2');
@mailtext=<data>;
close data;
print @mailtext;
 
M

MM

NoViagraHere said:
I am trying to open a text file in the same directory as the script is
located to retrieve stored info. The text file is simply named:
216.1.1.2


This code will NOT work:

$ip = '216.1.1.2';
open (data, $ip);
@mailtext=<data>;
close data;
print @mailtext;


however if I replace $ip as below, It DOES work. Any ideas?

open (data, '216.1.1.2');
@mailtext=<data>;
close data;
print @mailtext;

It works both ways on a Linux system using perl 5.8.1.

MM
 
N

Nick Santos

I'd say try making it look like "open (data, '$ip');" or "open (data,
"$ip");" I doubt it'll work, but it's worth a shot
 
J

Jim Gibson

NoViagraHere said:
I am trying to open a text file in the same directory as the script is
located to retrieve stored info. The text file is simply named:
216.1.1.2


This code will NOT work:

$ip = '216.1.1.2';
open (data, $ip);
@mailtext=<data>;
close data;
print @mailtext;


however if I replace $ip as below, It DOES work. Any ideas?

open (data, '216.1.1.2');
@mailtext=<data>;
close data;
print @mailtext;

You don't say why it is not working. You should be checking if the open
succeeded:

open( data, $ip ) or die("Can't open $ip: $!");

FYI: this newsgroup is defunct. Use comp.lang.perl.misc in the future
for better response.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top