Parag Kalra wrote:
Hello All,

Hello,

This code is working:

 #!/usr/bin/perl

use warnings;
use strict;

You should include those two pragmas to let perl help you find mistakes in your code.


  2 my @column_names=(A..ZZ);

Why are you creating an array with 702 entries when you are only using the first 26? Why are you using bareword strings instead of properly quoted strings?

my @column_names = 'A' .. 'Z';


  3 for(my $i=0; $i<26; $i=$i+1) {

That is usually written as:

for my $i ( 0 .. 25 ) {


  4     my $tmp_file = "$column_names[$i]".".out";
  5     open $i, ">column_names/$tmp_file" or die "Could not create the
file - $tmp_file \n";
  6     print $i "This is working\n";
  7     close $i or die "Could not close the file - $i\n";
  8 }

Probably better as:

for my $column_name ( @column_names ) {
    my $tmp_file = "$column_name.out";
open my $FH, '>', "column_names/$tmp_file" or die "Could not create the file - $tmp_file - $!";
    print $FH "This is working\n";
    close $FH or die "Could not close the file - $tmp_file - $!";
}



John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity.               -- Damian Conway

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to