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!

Using a Filehandle

Status
Not open for further replies.

mama12

Programmer
Oct 18, 2005
22
NL
HI,
I want to save all number between -100 and 100 in file,but I get error in line 11

line 11
open IN,"text" or die "Can't open input file: $!\n";

regards


#!/usr/bin/perl -w

# with a for loop
for ( my $count= -100; $count<=100; $count++ ) {
print $count++,"\n";
}
print "give a file name: ";

$count = <STDIN>

open IN,"text" or die "Can't open input file: $!\n";

while ($count = <IN>) {
print OUT $count;
}
close IN or warn "Errors while closing filehandle: $!";

exit;

 
not sure what you are doing, but the 'for' loop is only printing -100 through 100 to the screen.
 
Code:
#!/usr/bin/perl -w

print "give a file name: ";
$count = <STDIN>;
open FH, ">nums.txt" or die "Cant open File $!";

# with a for loop
  for ( my $count= -100; $count<=100; $count++ ) {
     print $count,"\n";
     print FH $count,"\n";
  }
close FH;



Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Code:
#!/usr/bin/perl -w

print "give a file name: ";
$fname = <STDIN>;
open FH, ">$fname.txt" or die "Cant open File $!";

# with a for loop
  for ( my $count= -100; $count<=100; $count++ ) {
     print $count,"\n";
     print FH $count,"\n";
  }
close FH;

Sorry bout that ... ;-)

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top