ITTips
How to use CPAN?
CPAN install module: to install a module
How to run a bash command in a Perl program:
http://perl.about.com/od/programmingperl/qt/perlexecsystem.htm∞
system("myCommand"); i.e.: system("/bin/ls");
How to get the file size:
http://www.perlmeme.org/faqs/file_io/filesize.html∞
$size =
(-
s 'ddserver.log');
print $size;
String comparison
if ($ticketList ne '')
##ne##: non equal
##eq##: equal
Pass array to sub-routines
Here is the post I found online that helped me to solve this problem:
http://www.nntp.perl.org/group/perl.beginners/2007/11/msg96639.html∞
Normally it is not possible to pass array to sub routines.
The only way to do so is to pass a reference to the array when calling the sub-routine and then to use it in the sub-routine
WriteChangesTofile
($new_configuration_file,\
@changed_file);
sub WriteChangesTofile
{
# Does not return anything. It OVERwrites the file
my $new_configuration_file=
$_[0];
my @changed_file = @
{$_[1]};
# This is the way to handle array passed to sub-routines. The array is passed as a reference
print "Updating: ".
$new_configuration_file.
"\n";
open(NEW_CONF_FILE,
">$new_configuration_file");
print (NEW_CONF_FILE
@changed_file);
close(NEW_CONF_FILE
);
}
Put some color in your life
Well, even if not in your life, at least in your script.
Reference website:
http://docstore.mik.ua/orelly/perl/cookbook/ch15_06.htm∞
use Term::
ANSIColor;
print color
("red"),
"Danger, Will Robinson!\n", color
("reset");
print color
("yellow"),
"Danger, Will Robinson!\n", color
("reset");
print color
("green"),
"Danger, Will Robinson!\n", color
("reset");
print color
("blue"),
"Danger, Will Robinson!\n", color
("reset");
Proper way to do a for loop
Do not ask me why though ...
for (; $i < $arraySize ; $i++ ) {
}
The way each behaves ...
http://www.cs.mcgill.ca/~abatko/computers/programming/perl/howto/hash/∞:
- Use each within a while loop. Note that each iterates over entries in an apparently random order, but that order is guaranteed to be the same for the functions keys and values.
There are no comments on this page. [Add comment]