Wednesday, October 28, 2009
Tuesday, October 20, 2009
Friday, October 9, 2009
Perl Special Literals list
__FILE__ = represent the current filename
__LINE__ = line number
__PACKAGE__ package name
If there is no current package (due to an empty package; directive),
__PACKAGE__ is the undefined value.
The two control characters ^D and ^Z, and the tokens __END__ and __DATA__ may be used to indicate the logical end of the script before the actual end of file. Any following text is ignored.
Text after __DATA__ may be read via the filehandle PACKNAME::DATA, where PACKNAME is the package that was current when the __DATA__ token was encountered. The filehandle is left open pointing to the contents after __DATA__. It is the program's responsibility to close DATA when it is done reading from it. For compatibility with older scripts written before __DATA__ was introduced, __END__ behaves like __DATA__ in the top level script (but not in files loaded with require or do) and leaves the remaining contents of the file accessible via main::DATA.
See SelfLoader for more description of __DATA__, and an example of its use. Note that you cannot read from the DATA filehandle in a BEGIN block: the BEGIN block is executed as soon as it is seen (during compilation), at which point the corresponding __DATA__ (or __END__) token has not yet been seen
__LINE__ = line number
__PACKAGE__ package name
If there is no current package (due to an empty package; directive),
__PACKAGE__ is the undefined value.
The two control characters ^D and ^Z, and the tokens __END__ and __DATA__ may be used to indicate the logical end of the script before the actual end of file. Any following text is ignored.
Text after __DATA__ may be read via the filehandle PACKNAME::DATA, where PACKNAME is the package that was current when the __DATA__ token was encountered. The filehandle is left open pointing to the contents after __DATA__. It is the program's responsibility to close DATA when it is done reading from it. For compatibility with older scripts written before __DATA__ was introduced, __END__ behaves like __DATA__ in the top level script (but not in files loaded with require or do) and leaves the remaining contents of the file accessible via main::DATA.
See SelfLoader for more description of __DATA__, and an example of its use. Note that you cannot read from the DATA filehandle in a BEGIN block: the BEGIN block is executed as soon as it is seen (during compilation), at which point the corresponding __DATA__ (or __END__) token has not yet been seen
Friday, October 2, 2009
How to determine Total memory (Total RAM, Used RAM, Free RAM) on Unix/Linux
'free' tool prints pretty much everything.
total used free shared buffers cached
Mem: 514592 274136 240456 0 20228 134104
-/+ buffers/cache: 119804 394788
Swap: 1052216 0 1052216
or
cat /etc/meminfo - has all the information.
total used free shared buffers cached
Mem: 514592 274136 240456 0 20228 134104
-/+ buffers/cache: 119804 394788
Swap: 1052216 0 1052216
or
cat /etc/meminfo - has all the information.
Thursday, October 1, 2009
How to find out which process is listening upon a port
For standard processes, Services names can be seen in /etc/services files associated with port numbers. This is pretty much standard TCP/IP.
For non-standard user defined services,
lsof -i :port_number
For example:
So to see which process is listening upon port 80 we can run:
root@mystery:~# lsof -i :80
This gives us the following output:
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
apache2 10437 root 3u IPv6 22890556 TCP *:www (LISTEN)
apache2 10438 www-data 3u IPv6 22890556 TCP *:www (LISTEN)
apache2 10439 www-data 3u IPv6 22890556 TCP *:www (LISTEN)
apache2 10440 www-data 3u IPv6 22890556 TCP *:www (LISTEN)
apache2 10441 www-data 3u IPv6 22890556 TCP *:www (LISTEN)
apache2 10442 www-data 3u IPv6 22890556 TCP *:www (LISTEN)
apache2 25966 www-data 3u IPv6 22890556 TCP *:www (LISTEN)
apache2 25968 www-data 3u IPv6 22890556 TCP *:www (LISTEN)
For non-standard user defined services,
lsof -i :port_number
For example:
So to see which process is listening upon port 80 we can run:
root@mystery:~# lsof -i :80
This gives us the following output:
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
apache2 10437 root 3u IPv6 22890556 TCP *:www (LISTEN)
apache2 10438 www-data 3u IPv6 22890556 TCP *:www (LISTEN)
apache2 10439 www-data 3u IPv6 22890556 TCP *:www (LISTEN)
apache2 10440 www-data 3u IPv6 22890556 TCP *:www (LISTEN)
apache2 10441 www-data 3u IPv6 22890556 TCP *:www (LISTEN)
apache2 10442 www-data 3u IPv6 22890556 TCP *:www (LISTEN)
apache2 25966 www-data 3u IPv6 22890556 TCP *:www (LISTEN)
apache2 25968 www-data 3u IPv6 22890556 TCP *:www (LISTEN)
Thursday, May 14, 2009
Best practices for a high performance Perl program
http://makepp.sourceforge.net/1.50/perl_performance.html
Wednesday, March 4, 2009
Validating data types in PERL
Since perl data types are very typeless and depends upon where they are used. There are some situations, when this design is awkward.
To validate data types,
Data::Types module can be installed and used.
However if you dont want to install, here are few quickies:
- To Check
% An Integer, Use regex /^[+-]?\d+$/ and ofcourse, not matched ones are non-intger
% A Decimal, /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/
% Whole number, /^\d+$/
% Float number, /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/
%
To validate data types,
Data::Types module can be installed and used.
However if you dont want to install, here are few quickies:
- To Check
% An Integer, Use regex /^[+-]?\d+$/ and ofcourse, not matched ones are non-intger
% A Decimal, /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/
% Whole number, /^\d+$/
% Float number, /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/
%
Subscribe to:
Posts (Atom)