in reply to Re: Error coming while using Use Strict
in thread Error coming while using Use Strict

hi,

use strict; my $start='<?xml version="1.0" encoding="utf-8"?> <MultifamilyProperty xmlns:xsi="http://www.w3.org/2001/XMLSchema-insta +nce" xmlns:xsd="http://www.w3.org/2001/XMLSchema">'; my @key=("1","2","3","4","5"); my ($file_handle,$output_file); $output_file=".xml"; for(my $i=0;$i<$#key;$i++) { my $val=$key[$i]; $output_file=$val.$output_file; open($val,'>:utf8',"$output_file"); print $val $start."\n"; print $val "\t\t".'<Address>'."\n"; close $val; }

You may understand this code

print $val $start."\n"; which is used to assigning $start variable content to my each file handler

Regards,

Senthil

Replies are listed 'Best First'.
Re^3: Error coming while using Use Strict
by jethro (Monsignor) on Oct 13, 2011 at 10:03 UTC

    You don't need a different filehandle when you access files sequentially. Also the previous contents of the filehandle variable is quite meaningless to its use as a filehandle. So just use something like this:

    for(my $i=0;$i<$#key;$i++) { my $val; #No need to put anything in it $output_file=$key[$i].$output_file; open($val,'>:utf8',"$output_file");

      hi,

      I am creating five file .So i expect unique file handler for each file.That program is running without using strict

        No, you are creating one file, so you need one file handle. Then, you are creating one file, so you again need one file handle. Then, you are creating one file, so you again need one file handle. Then, you are creating one file, so you again need one file handle. Then, you are creating one file, so you again need one file handle.
        Which makes it one file handle in total.

        Your are creating five files, but one after another. So you can reuse one filehandle for all five files. Only if you had more than one file open at the same time(!) would you need more than one filehandle. In that case use this:

        my @key; for(my $i=0;$i<5;$i++) { $output_file=$key[$i].$output_file; open($key[$i],'>:utf8',"$output_file"); my $f= $key[$i]; print $f $start."\n"; ...
Re^3: Error coming while using Use Strict
by Corion (Patriarch) on Oct 13, 2011 at 11:13 UTC

    How is this post supposed to answer the two questions I asked?