The following codes are not accepted by Perl and even string
concatenation doesn't work.
Doesn't work is not a good problem description.
See below.
use strict;
use warnings;
$infile = $ARGV[0];
foreach $k (0..10) {
You realize that loops 11 times, right?
$outfile = $infile . $k;
open (OFP$k, ">$outfile");
First off, you should check if open succeeded. Second, what makes you
think you can use OFP$k where Perl expects a filehandle.
This looks like a very poor attempt at using symbolic file handles (if
such a thing even exsits, I don't know).
When you find yourself wanting to index something using an integer, you
should use an array.
}
$i = $size/10000;
print OFP$i "something"; #0-10k, 10-20k, .... 90-100k...
#!/usr/bin/perl
use strict;
use warnings;
my ($prefix) = @ARGV;
die "No prefix specified\n" unless defined $prefix;
my @out;
for my $i ( 0 .. 9 ) {
my $name = "${prefix}${i}";
if ( open my $fh, '>', $name ) {
push @out_h, { name => $name, handle => $fh };
}
else {
warn "Error opening '$name': $!\n";
}
}
for my $file ( @out ) {
my $handle = $file->{handle};
my $name = $file->{name};
print $handle "This is $name\n";
unless ( close $handle ) {
warn "Error closing '$name': $!";
}
undef $file->{handle};
}
__END__
Sinan
--
A. Sinan Unur <
[email protected]>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/