perl_all_9.html

Perl More

Last | Next



Code

dedup.pl
            
!#/usr/bin/perl

open (IN, "< CBLPrivacy.tab");
open (OUT, "> CBLPrivacy-new.tab");

while (<IN>) {
  chomp;
  if ( $_ ne $oldline ) {
    print OUT "$_ \n";
  }
  $oldline = $_; 
}
close (IN);
    
sort.pl
            
!#/usr/bin/perl

#open (IN, "< VMP.DAT");
open (IN, "< vmp-test-cycle3.dat");
open (CYCLE3, "> cycle3.txt");
open (NOTCYCLE3, "> not-cycle3.txt");

while () {
  chomp;
  if ( $_ =~ m/3$/  ) {
    print CYCLE3 "$_ \n";
  }
  else {
    print NOTCYCLE3 "$_ \n";
  }
}
close (IN);
close (CYCLE3);
close (NOTCYCLE3);
  
Command line to change DOS-infested CR-LF to Unix LF "only"
            
perl -pi -e 's/\r\n/\n/;' file.txt
  
compare_two_files/compare.pl
            
open (IN1, "< in1.txt");
open (IN2, "< in2.txt");
open (OUT, "> out1.txt");

while ( $in1 = <IN1> ) {
	chomp();
	while ( $in2 = <IN2> ) {
		chomp();
		print "\$in1 = $in1 and \$in2 = $in2 \n";
		if ( $in1 =~ $in2 ) {
			print OUT "match $in1 $in2 \n";
		} else {
			print OUT "no match \n";
		} 
	}
	
}
close (IN1);
close (IN2);
close (IN2);
  
read_change_write/rcw.perl
            
#!/usr/bin/perl 

# this line: $_ =~ s/(.)(.)(.)/$2$3$1/;
# does the work.
# It captures position 1, 2 and 3 in the first compartment.
# In the second compartment, it changes the order to $2$3$1
# And writes it to outpass1.txt

  open (IN, "< x") || die "no input file"; 

  open ( OUT, "> outpass1.txt" );
  while ( <IN> ) {
    chomp;
    if ( $_ =~ /22/ ) {   
	$_ =~ s/(.)(.)(.)/$2$3$1/;
      print OUT ( "$_ \n" );
    } 
  }
  close ( IN );
  close ( OUT );
sr/bin/perl

open (IN1, "< in1.txt");
open (OUT, "> out1.txt");

while ( <IN1> ) {
	chomp();
	if ( $_ !~ /pattern/ ) {
		print OUT " $_  \n";
	}
}

close (IN1);
close (OUT1);

  


www.trialwebsite.biz(c) 2007