>>>>> "I" == Ian  <pcs...@gmail.com> writes:

you asked for some code review earlier and here it is.

  I> use strict;

use warnings ;

  I> my $inpf = 'student.txt';
  I> my $uidf = 'uidf.txt';
  I> open (DATA, $inpf) or die "Can't open file $inpf!\n";

don't use the DATA handle for your own files. DATA is the standard
handle for data lines at the end of the source file.

also use lexical handles as they won't conflict with globs
elsewhere. bareword glob names are global

open (my $in, $inpf) or die "Can't open file $inpf!\n";


  I> open (UIDF, ">$uidf") or die "Can't open output file!\n";

use the 3 args form of open with the '>' being the second argument.

  I> #read file
  I> my $line;
  I> while ($line = <DATA>) {

while( my $line = <$in> ) {

  I>         chomp($line);

  I>     if ($line =~ /^dn:\s+uid=(s\d{2}-\d{1}-\d{1}-\d{1,3})/) {

why put the {1} quantifiers in there? the default is 1 anyway. it just
adds to the noise. and sometimes \d\d is more readable than \d{2} (it is
fewer chars at least! :).

  I>             print UIDF ("$1\n");
  I>     }
  I> }
  I> close (DATA, UIDF);

close only takes one argument. those handles will be closed anyway at
the end of the program. if you used lexical handles as i say above, they
will be closed at the end of their scope.

  I> END;

that isn't normal perl. there is an END {} block thing but no plain
END. i am not even sure how that would be parsed but warnings (which you
didn't enable) should spit out something like bareword or expression in
void context or maybe an END {} without its code block.

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

-- 
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