Hi, a few comments on your code:
On Tuesday 09 November 2010 10:52:39 yo RO wrote: > Hello > I need to read some data in a file and add in another file part of the > line with some changes > > input data > ./data01;data02;data03;data04;data05;data06;data07; > ./data11;data12;data13;data14;data15;data16;data17; > ./data21;data22;data23;data24;data25;data26;data27; > ./data31;data32;data33;data34;data35;data36;data37; > > out put data need > can be like zis > > data01;data02;data03;data01_sametexttoall;data04 > data11;data12;data03;data11_sametexttoall;data14 > data21;data22;data23;data21_sametexttoall;data24 > data31;data32;data33;data31_sametexttoall;;data34 > > out data can be also > > ./data01;data02;data03;data01_sametexttoall;data04 > ./data11;data12;data03;data11_sametexttoall;data14 > ./data21;data22;data23;data21_sametexttoall;data24 > ./data31;data32;data33;data31_sametexttoall;;data34 > > I have tryed this but not not working some error "Global symbol "@f" > requires explicit package name" I am using activeperl if I need to add > some pach please tell me what is this because I add all filesys and > same error > > my code is this but not working :( > > use strict; > use warnings; > It's good that you have strict and warnings on. > > # GET a value for accout.txt and outaccount > my $OUTPUTFILE ="acounts.txt"; > my $ACC_FILE = "outaccounts.txt"; > > #open input file > open my $ACC_IN "<", $ACC_FILE > or die "Cannot open '$ACC_FILE' for reading - $!; Nice - but you need a comma after $ACC_IN. Also please consider naming at least some of the variables in lowercase. Uppercase make it look like you are shouting. > > #split by line > while (my $line = <ACC_IN>) > > { @F = split(';' $line); 1. You need to fix you rindentation. 2. Please declare @F using my (Perl will accept it otherwise because @F is a built-in - see http://perldoc.perl.org/perlvar.html ). 3. this should read: my @f = split (/;/, $line); > chomp ($line); Why do you chomp the line *after* you've split it instead of before that. > #open output file > open $OUTPUTFILE; That does not do the right thing. Please use three-args open with or. Also make sure you open it before the loop. so you can use it later. > #print value what is interested for me in the file and then go to the > next line This comment should read: [code] # Print the interesting values in the file and then go to the next line. [/code] > print {$OUTPUTFILE} > "$f[0]",'/',"$f[1]",'/',"$f[2]","$f[0]","$f[3]"\n"; You don't need to explicitly stringify $f[0], etc. because they are strings. And you can use interpolation for clarity. You also cannot print into the filename. And naturally, Perl distinguishes between @f (in lower-case) and @F (in upper- case). Which one do you want? Write it as: print {$out_fh} "$f[0]/$f[1]/$f[2]$f[0]$f[3]\n"; > #close outfile > close $OUTPUTFILE; The comment here is redundant. Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Apple Inc. is Evil - http://www.shlomifish.org/open-source/anti/apple/ <rindolf> She's a hot chick. But she smokes. <go|dfish> She can smoke as long as she's smokin'. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/