Friday, April 4, 2014

delete block of content in VIM

capital V mark the start of block,move cursor to end of block, delete block with x or d,
if you want delete to end if file,use capital G move cursor to end of file,the x or d delete

hang linux terminal

ctrl+s will hang linux terminal,and ctrl+Q will resume it.

three important signals in linux

The 3 most important "kill" signals on the Linux/UNIX command line

Most Linux or UNIX users know that there is a kill(1) command to stop processes, but what are the options, what do they mean?
These options are called signals, which can be expressed in either numbers or words. Some known once are "-1" or "-HUP". Also well known is "-9" (aka "-KILL")
  • -1 or -HUP - This argument makes kill send the "Hang Up" signal to processes. This probably originates from the modem/dial-in era. Processes have to be programmed to actually listen to this process and do something with it. Most daemons are programmed to re-read their configuration when they receive such a signal. Anyway; this is very likely the safest kill signal there is, it should not obstruct anything.
  • -2 or -SIGINT - This is the same as starting some program and pressing CTRL+C during execution. Most programs will stop, you could lose data.
  • -9 or -KILL - The kernel will let go of the process without informing the process of it. An unclean kill like this could result in data loss. This is the "hardest", "roughest" and most unsafe kill signal available, and should only be used to stop something that seems unstoppable.
  • -15 or -TERM - Tell the process to stop whatever it's doing, and end itself. When you don't specify any signal, this signal is used. It should be fairly safe to perform, but better start with a "-1" or "-HUP".

Thursday, April 3, 2014

perl private variables

Private Variables in a Subroutine:

By default, all variables in Perl are global variables which means they can be accessed from anywhere in the program. But you can create private variables called lexical variables at any time with the my operator.
The my operator confines a variable to a particular region of code in which it can be used and accessed. Outside that region, this variable can not be used or accessed. This region is called its scope. A lexical scope is usually a block of code with a set of braces around it, such as those defining the body of the subroutine or those marking the code blocks of if, while, for, foreach, and eval statements.
Following is an example showing you how to define a single or multiple private variables using my operator:
sub somefunc {
   my $variable; # $variable is invisible outside somefunc()
   my ($another, @an_array, %a_hash); # declaring many variables at once
}

pass parameter into perl sub fucntion

Passing Arguments to a Subroutine:

You can pass various arguments to a subroutine like you do in any other programming language and they can be acessed inside the function using the special array @_. Thus the first argument to the function is in $_[0], the second is in $_[1], and so on.
You can pass arrays and hashes as arguments like any scalar but passing more than one array or hash normally causes them to lose their separate identities. So we will use references ( explained in the next chapter ) to pass any array or hash.

perl language variables

We have learnt that Perl has following three basic data types:
  • Scalars
  • Arrays
  • Hashes
Accordingly we are going to use three types of variables in Perl. A scalar variable will precede by a dollar sign ($) and it can store either a number, a string, or a reference. A array variable will precede by sign @ and it will store ordered lists of scalars. Finally Hash variable will precede by sign % and will be used to store sets of key/value pairs.
Perl maintains every variable type in a separate namespace. So you can, without fear of conflict, use the same name for a scalar variable, an array, or a hash. This means that $foo and @foo are two different variables.


perl test console

perl -d -e 1
last one is number "1", not letter "l".

find current shell

ps -p $$

Wednesday, April 2, 2014

delete more line from vim

upper V,then upper G go to end of file,then x,it will delete filr content
or rm file,then touch to create a new empty file.

grep binary or hex search

grep -P "\x1A" file_name

for VIM  use /\%x1A or /\%x1a, "\%1A" is search pattern