How to use Perl interactive console?[1]
perl -e 1 -d
What is the difference between "exit" and "last" in flow control?
exit: exit the program (when the execution is successful).
last: escape from the current loop.
qw?
($t, $u, $v)=qw(this is grace huang); ($a, $b, $c, $d)=qw(this is grace);
$v="grace" , $d="". make sense?
How to pronounce these computer punctuation?
punctuation
find all the occurrences? do a "global".
s/cat/dog/g
variables in Perl are default set to GLOBAL
how to make file handler as argument
splutter(\*STDOUT); sub splutter { my $fh = shift; print $fh "her um well a hmmm\n"; }
Perl sort[2]
When I used "require" to include subroutines from other files, "sub-name sub-arg" did not work, but "sub-name(sub-arg)" worked.
reason: you can only use sub without parentheses, when the sub is predeclared.[3]
How do you treat a number like 19? a word?
What are the differences between "my $line = @_" and "my ($line) = @_"?
a. $line is the length of the array @_
b. $line is the first element of @_
see an example at http://www.simonf.com/perl/fp_perl.html
SVN Error
svn: Commit failed (details follow):
svn: Can't connect to host 'localhost': Connection refused
Solution:
Reboot SVN DAEMON by
svnserve -d
Search and replace over file(s) with Perl
perl -pi -e 's/source/destination/g' *.html
SVN: Commit replaced directories[4]
Problem
If it replaces the directory, the .svn subfolder is lost and you get this ugly status message:
~ subfolder
Which means subversion knows about it (the current folder contains an entry like "directory: subfolder"), but the directory itself is not a working directory (no .svn folder present in subfolder). That status is called "~ replaced"; unfortunately the description in the SVN manual is incomplete: "Item is versioned as a directory, but has been replaced by a file, or vice versa." It should better read: "Item is versioned as a directory, but has been replaced by a file with the same name, or vice versa. It could also indicate that it is versioned as a directory, but has been replaced by a directory of the same name without the important .svn folder inside."
Solution
It's normally a three step process on a standard UNIX command line:
mv subfolder subfolder-temp
svn up subfolder
cp -R subfolder-temp/* subfolder
Note that subfolder-temp is just a temporary name which must not exist yet. The important step is the copy with -R and *, which under UNIX means to copy the tree below subfolder-temp into the existing tree under subfolder. This is technically a simple forward merge. And here is the tricky part: it works for added and modified files, but not for deleted files. You will have to manually delete them. To find out which files are actually deleted, you can use the diff command in recursive and brief mode:
diff -rq subfolder subfolder-temp
For each file it says "Only in subfolder/: foobar", you can delete it:
svn del subfolder/foobar
To make sure everything is correct now, check the status:
svn st subfolder
You should probably also run your (test) code on this "rebuilt" directory or check the files with whatever program is using them. If everything is ok, you can commit it and throw away the temporary copy:
svn ci subfolder
rm -rf subfolder-temp
How to open a new bash window with the current dir?[5]
#!/bin/sh
if [ $# -ne 1 ]; then
PATHDIR=`pwd`
else
PATHDIR=$1
fi
osascript -e "tell application \"Terminal\"" -e "do script \"cd $PATHDIR\"" -e "end tell"
Save this script somewhere in your $PATH with executable permissions. Now instead of hitting Command-N then typing “cd really/long/path/to/your/current/directory”, you can simply type the name of the script (I used “term”):
term
Chain them together to open multiple windows. The following would open three new windows with the same current directory:
term; term; term
It can also take an optional directory path argument to override the current directory:
term /System/Library/
remove all .svn folders
find . -name .svn -exec 'rm -rf {}\;'
Several useful commands
Wrap the entire content. Good view of the code and helps avoid moving cursors around.
:set wrap
Ignore case in the searches
:set ignorecase (:set ic)
:set noignorecase
Check disk space
Show the disk space usage
df -h
Show how much space a directory take up. The slash is important.
du -hs folder/
Check SVN log by username
svn log | sed -n '/username/,/-----$/ p'
Conflict can happen when mergeing
Merge only merge changes of the specific revision. The to-be-merged-into revision is so different from the merged-from revision, then SVN will get confused and the conflict will happen.
Ubuntu Linux: How do I install .deb packages?[6]
How do I install .deb file?
To install package called package.deb type the following command:
Go to directory where package.deb is kept. For example if it is in /tmp directory:
$ cd /tmp
Type the following command:
$ sudo dpkg -i package.deb
Linux command: print out the argument of previous command
!$





