[ create a new paste ] login | about

Link: http://codepad.org/YiqZWflu    [ raw code | output | fork ]

htoma - Perl, pasted on Nov 4:
use strict;
use warnings;
my $DATAIN_FILE = "test.txt";

open my $data_in_fh, "<", $DATAIN_FILE
or die "Cannot open '$datain_FILE' for reading - $!";

while (<$DATAIN_FILE>) {
chomp;
$var = $_;
@var= split ("|",$_);

#Create and put value of filename
my $fname_out = var[0];

#Spit data to have file name and information to put in the file
my ($fname;$data_out_fh) = split /|/, $;
#if name of file fname_out the same with the name of first value in the
line fname print line in the file
if (fname=fname_out)
{open $data_out_fh, ">", "$fname.txt"
or die "Cannot open '$fname.txt' for writing - $!";
print {$fname_out} "$data_out_fh\n";
}

}
else
{
#if fname not the same with firts value in the line then create a new file
with this name of firts value in line and add line in the file
$fname_out=$fname
open $data_out_fh, ">", "$fname.txt"
or die "Cannot open '$fname.txt' for writing - $!";

print {$fname_out} "$data_out_fh\n";
}

close($data_out_fh);


Output:
1
2
3
4
5
6
7
8
9
10
11
12
Semicolon seems to be missing at line 18.
Global symbol "$datain_FILE" requires explicit package name at line 6.
Global symbol "$var" requires explicit package name at line 10.
Global symbol "@var" requires explicit package name at line 11.
syntax error at line 14, near "var["
syntax error at line 17, near "$fname;"
Global symbol "$data_out_fh" requires explicit package name at line 17.
syntax error at line 17, near "$data_out_fh) "
Global symbol "$data_out_fh" requires explicit package name at line 21.
Global symbol "$data_out_fh" requires explicit package name at line 23.
syntax error at line 26, near "}"
t.pl has too many errors.


Create a new paste based on this one


Comments: