in reply to Error coming while using Use Strict

The error happens in the following line. Please explain what the line is supposed to do:

print $file_handle $start."\n";

Please also explain what this line is supposed to do:

$file_handle=$val;

Maybe you want to read and understand open? None of the examples shown match your usage.

The relevant part for your error is

If FILEHANDLE is an undefined scalar variable (or array or hash element), a new filehandle is autovivified, meaning that the variable is assigned a reference to a newly allocated anonymous filehandle. Otherwise if FILEHANDLE is an expression, its value is the real filehandle. (This is considered a symbolic reference, so use strict "refs" should not be in effect.)

My advice is to just not do that and to use the documented examples instead.

Replies are listed 'Best First'.
Re^2: Error coming while using Use Strict
by Anonymous Monk on Oct 13, 2011 at 09:46 UTC

    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

      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

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