469,916 Members | 2,251 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,916 developers. It's quick & easy.

open(data,' variable problem

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;
Jul 19 '05 #1
3 1543
MM
NoViagraHere wrote:
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

Jul 19 '05 #2

"MM" <mm*********@comcast.net> wrote in message
news:65MAb.327887$9E1.1609413@attbi_s52...
NoViagraHere wrote:
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;


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
Jul 19 '05 #3
In article <3f***********************@newscene.com>, NoViagraHere
<No**********@flyingballs.com> wrote:
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.
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by melledge | last post: by
5 posts views Thread by Richard Trahan | last post: by
23 posts views Thread by Markus | last post: by
1 post views Thread by Melissa | last post: by
3 posts views Thread by blackpuppy | last post: by
1 post views Thread by Laszlo Nagy | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.