#! /usr/local/bin/perl # dos2unix.pl by David Efflandt # Modification of script from "Learning perl" p.353 # O'Reilly & Associates, Inc. # # Run after transfering text files from DOS to UNIX system. # Strips carriage returns from DOS files for use UNIX. # Transfers file permissions to new file (except suid bit). # # Usage:\tdos2unix.pl FILELIST # where FILELIST = one or more filenames # # If you edit this file in DOS you can run it on itself by typing: # perl dos2unix.pl dos2unix.pl # # Modify variables below for other search and replace functions. $find = "\r"; # find this $sub = undef; # substitute with this $rm_bak = 1; # remove old file after conversion: 0 = no, 1 = yes while (<>) { if ($ARGV ne $oldargv) { ($dev,$ino,$mode,$nlink,$uid,$gid) = stat($ARGV); $backup = $ARGV . '.bak'; rename($ARGV, $backup); open (ARGVOUT, ">$ARGV"); chmod $mode, $ARGV; select(ARGVOUT); $oldargv = $ARGV; } s/$find/$sub/; } continue { print; if (eof) { print STDOUT "Converted: $oldargv\n"; unlink $backup if $rm_bak; } } select(STDOUT); #________________________________________________________________________ # Title : read_dir_names_only # Usage : @all_dirs_list = @{&read_dir_names_only(\$absolute_path_dir_name, ....)}; # Function : read any dir names and and then put in array. # Example : # Warning : This does not report '.', '..' # Only file names are reported. Compare with &read_any_dir # Class : # Keywords : # Options : # Package : # Reference : # Returns : one ref. of array. # Tips : # Argument : takes one or more scaler references. ('.', \$path, $path, ... ) # Todo : # Author : A Biomatic # Version : 3.1 # Used in : # Enclosed : #-------------------------------------------------------------------- sub read_dir_names_only{ my($in_dir, $i,$k, @possible_dirs, @final_files, $full_dir, $pwd, $path,@read_files); $pwd=`pwd`; chomp($pwd); $full_dir=1; for($k=0; $k < @_; $k++){ if ( ($_[$k] eq '.') || !(defined($_[$k]))){ $in_dir=$pwd; } elsif(!(ref($_[$k]))){ $in_dir=$_[$k]; } elsif(ref($_[$k])){ $in_dir =${$_[$k]}; } if($in_dir =~ /^([\w\-\.]+)$/){ $in_dir="$pwd\/$in_dir"; $full_dir = 0; } else{ $full_dir =1; } ########## Main READING PART ########## opendir(DIR1,"$in_dir"); @read_files = readdir(DIR1); for($i=0; $i < @read_files; $i ++){ $read_files[$i]="$in_dir\/$read_files[$i]"; if( ($read_files[$i] !~ /\/\.\.?$/) && ( -d $read_files[$i]) ){ $read_files[$i]=~s/\.\///; ## removing ./ in front of dirs (in bash) push(@final_files, "$read_files[$i]"); } } } return([sort @final_files]); }