in reply to Perl starter with big problem.

hi try out this one.
#!/usr/bin/perl open(FILE,"txt1.txt"); while(<FILE>){ ($val1,$val2,$val3)=split(/\s+/,$_); ($val3)=split(/-/,$val3); $vv=sprintf "$val1".'/'."$val2".'/'."$val3"."%3s".'/'; chop($vv); print $vv; } close(FILE);

Replies are listed 'Best First'.
Re^2: Perl starter with big problem.
by toolic (Bishop) on Nov 04, 2008 at 14:47 UTC
    <critic level="harsh">
    • Your code does not produce the output desired by the OP.
    • You should use warnings; because it will generate warning messages which point to bugs in the code, particularly the odd usage of sprintf.
    • You should always check the success of open.
    • There is no indentation, which makes it difficult to understand the code.
    • use strict; to avoid other common programming mistakes.
    • It is a good practice to use the 3-argument form of open and to use lexical filehandles:
    open my $fh, '<', 'txt1.txt' or die "Can not open txt1.txt: $!";