Hi Mr./Ms. Wang,

a few notes on your code.

On Fri, 6 Feb 2015 02:53:52 +0000
"Wang, Zeng-Sheng (TS-GSD-China-ZZ)" <zengsheng.w...@hp.com> wrote:

> Dear Uri,
> 
> First thanks for your kindly help and a read-friendly instruction, I will not
> use $a and $b for variables. According to your explanation, I finish the code
> as below: 

First of all, next time - do not include the line numbers when showing the code
because it makes copy+paste more difficult.

> #!/usr/bin/perl -w 2 use strict;

Don't use the "-w" flag - use "use warnings;" instead:

http://perl-begin.org/tutorials/bad-elements/#the-dash-w-flag


>   3 open(FH,'<',"file1");

Don't use bareword filehandles and either add "use autodie;" or throw an
exception on open:

http://perl-begin.org/tutorials/bad-elements/#open-function-style

>   4 my @first_file = <FH>;
>   5 close (FH);
>   6
>   7 open(FH,'<',"file2");
>   8 my @second_file = <FH>;
>   9 close (FH);
> 10
>  11 open(FH,'<',"file3");
> 12 my @third_file = <FH>;
> 13 close (FH);
> 14
>  15 chomp @first_file;
> 16 chomp @second_file;
> 17 chomp @third_file;

@first_file, @second_file, and @third_file really should be an array of arrays.
See:

http://perl-begin.org/topics/references/

> 18
>  19 my ($out_line,$number);
> 20 $number = @first_file;
> 21 $out_line='';

Please do not predeclare variables:

http://perl-begin.org/tutorials/bad-elements/#declaring_all_vars_at_top

> 22 for(0..$number){

You have an off by one error here.

> 23         $out_line.= shift @first_file;
> 24         $out_line.= "\t".shift @second_file;
> 25         $out_line.="\t".shift @third_file;
> 26         $out_line.="\n";}

This should really be done using join.

> 27
>  28 print $out_line;
> 
> I realize my target, however, there are some warnings in the prompt, how can
> I eliminate them? Why? perl format.pl
> Use of uninitialized value in concatenation (.) or string at format.pl line
> 23. Use of uninitialized value within @second_file in concatenation (.) or
> string at format.pl line 24. Use of uninitialized value within @third_file in
> concatenation (.) or string at format.pl line 25. 

Maybe the arrays are of different lengths.

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
UNIX Fortune Cookies - http://www.shlomifish.org/humour/fortunes/

There is no IGLU Cabal! Its members can be arranged in N! orders to form N!
different Cabals. The algorithm to find which order formulates the correct
IGLU Cabal is NP‐Complete.

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/


Reply via email to