How to find world writable directories by "find" command? 
find . -type d -perm -a+w -exec ls -lah {} \; > ww.txt

[ add comment ]   |  permalink  |  related link  |   ( 3 / 150 )
perl - handling sigint 
Write a small Perl program that waits for 30 seconds and exits with printing “Bye”. If interrupted by any key before 30 second then print “Hello” before exiting.

perl -e "$SIG{INT}= sub {print 'Hello';exit;};for ($i=0;$i<30;$i++){sleep 1;}; print 'bye';"

[ add comment ]   |  permalink  |   ( 2.6 / 122 )
Perl - Difference Between my local our 
The variables declared with my() are visible only within the scope of the block which names them. They are not visible outside of this block, not even in routines or blocks that it calls.

local() variables, on the other hand, are visible to routines that are called from the block where they are declared.

Neither is visible after the end (the final closing curly brace) of the block at all.


Whereas our() has Package scope.

[ add comment ]   |  permalink  |  related link  |   ( 3 / 20 )
After Registration Email 
$content = "
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'
'http://www.w3.org/TR/html4/loose.dtd'>
<html>
<head>
<title>TotalESL</title>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
</head>

<body>

<table width='600' border='0' cellspacing='2' cellpadding='2'>
<tr>
<td align='left' class='textbig'><strong>Dear ".$username.":</strong><br><br>
Thank you for joining TotalESL.com, First Stop for Your Second Language Needs. <br>Please note your account information <br />
<br />
<table width='100%' border='0' cellspacing='2' cellpadding='2'>
<tr valign='top'>
<td width='140' align='left' class='text'> <strong>Username:</strong></td>
<td align='left' class='text'>".$username."</td>
</tr>
<tr valign='top'>
<td align='left' class='text'><strong>Password:</strong></td>
<td align='left' class='text'>".$password."</td>
</tr>
<tr valign='top'>
<td align='left' class='text'><strong>IM/Chat Username:</strong></td>
<td align='left' class='text'>".$username."</td>
</tr>
</table>
<br></td>
</tr>
<tr>
<td class='text' align='left'>Congratulations! You may to proceed and use our member features:<br>
</td>
</tr>
<tr>
<td class='text' align='left'>&nbsp;</td>
</tr>
<tr>
<td class='text' align='left'>Thank you.
<br />
<br />
Admin
<br />
TotalESL.com <a href='http://www.totalesl.com'><br />
http://www.totalesl.com</a></td>
</tr>
</table>
<br>

</body>
</html>";

[ 1 comment ] ( 12 views )   |  permalink  |   ( 3 / 87 )
PERL OOP - Destructors  
If constructors can have arbitrary names, then why not destructors? Because while a constructor is explicitly called, a destructor is not. Destruction happens automatically via Perl's garbage collection (GC) system, which is a quick but somewhat lazy reference-based GC system. To know what to call, Perl insists that the destructor be named DESTROY. Perl's notion of the right time to call a destructor is not well-defined currently, which is why your destructors should not rely on when they are called.

Why is DESTROY in all caps? Perl on occasion uses purely uppercase function names as a convention to indicate that the function will be automatically called by Perl in some way. Others that are called implicitly include BEGIN, END, AUTOLOAD, plus all methods used by tied objects, described in the perltie manpage.

[ add comment ]   |  permalink  |   ( 3 / 62 )
PERL OOP - Inheritance 
Like the special per-package variables recognized by Exporter (such as @EXPORT, @EXPORT_OK, @EXPORT_FAIL, %EXPORT_TAGS, and $VERSION), the @ISA array must be a package-scoped global and not a file-scoped lexical created via my(). Most classes have just one item in their @ISA array. In this case, we have what's called ``single inheritance'', or SI for short.

Consider this class:
package Employee;
use Person;
@ISA = ("Person");
1;

Not a lot to it, eh? All it's doing so far is loading in another class and stating that this one will inherit methods from that other class if need be. We have given it none of its own methods. We rely upon an Employee to behave just like a Person.

[ add comment ]   |  permalink  |   ( 3 / 65 )
PERL OOP - Constructor 
sub new {
my $self = {};
$self->{NAME} = undef;
$self->{AGE} = undef;
$self->{PEERS} = [];
bless ($self);
return $self;
}

[ add comment ]   |  permalink  |  related link  |   ( 2.8 / 78 )
Autovivification 
Autovivification is a distinguishing feature of the Perl programming language involving the dynamic creation of data structures. Autovivification is the automatic creation of a variable reference when an undefined value is dereferenced. In other words, Perl autovivification allows a programmer to refer to a structured variable, and arbitrary sub-elements of that structured variable, without expressly declaring the existence of the variable and its complete structure beforehand.

In contrast, other programming languages either: 1) require a programmer to expressly declare an entire variable structure before using or referring to any part of it; or 2) require a programmer to declare a part of a variable structure before referring to any part of it; or 3) create an assignment to a part of a variable before referring, assigning to or composing an expression that refers to any part of it.

[ add comment ] ( 1 view )   |  permalink  |  related link  |   ( 3 / 43 )
Exporting symbols 
There are rare occasions when you do want to export methods or variable names into the calling package. I only do this occasionally for static helper methods I need very, very often. In order to export symbols, inherit from the Exporter class and fill the @EXPORT array with the symbols you'd like to export:

package Util;
use base 'Exporter';
our @EXPORT = ('foo', 'bar');

Try not to pollute another package's namespace unless you have a very good reason for doing so! Most packages on CPAN explicitly state which symbols get exported with their use, if any.

It might be a good idea to leave it up to the requiring package to decide which symbols get exported into its namespace. In that case you simply use the @EXPORT_OK array instead or @EXPORT.
package Util;
use base 'Exporter';
our @EXPORT_OK = ('foo', 'bar');

[ add comment ] ( 1 view )   |  permalink  |  related link  |   ( 3 / 20 )
Difference between 'use' and 'require' 
USE
Imports some semantics into the current package from the named
module, generally by aliasing certain subroutine or variable
names into your package. It is exactly equivalent to

BEGIN { require Module; import Module LIST; }

except that Module *must* be a bareword.

The "BEGIN" forces the "require" and "import" to happen at
compile time. The "require" makes sure the module is loaded into
memory if it hasn't been yet. The "import" is not a
builtin--it's just an ordinary static method call into the
"Module" package to tell the module to import the list of
features back into the current package. The module can implement
its "import" method any way it likes, though most modules just
choose to derive their "import" method via inheritance from the
"Exporter" class that is defined in the "Exporter" module. See
Exporter. If no "import" method can be found then the call is
skipped.



REQUIRE
Otherwise, demands that a library file be included if it hasn't
already been included. The file is included via the do-FILE
mechanism, which is essentially just a variety of "eval". Has
semantics similar to the following subroutine:

sub require {
my ($filename) = @_;
if (exists $INC{$filename}) {
return 1 if $INC{$filename};
die "Compilation failed in require";
}
my ($realfilename,$result);
ITER: {
foreach $prefix (@INC) {
$realfilename = "$prefix/$filename";
if (-f $realfilename) {
$INC{$filename} = $realfilename;
$result = do $realfilename;
last ITER;
}
}
die "Can't find $filename in \@INC";
}
if ($@) {
$INC{$filename} = undef;
die $@;
} elsif (!$result) {
delete $INC{$filename};
die "$filename did not return true value";
} else {
return $result;
}
}

Note that the file will not be included twice under the same
specified name.

The file must return true as the last statement to indicate
successful execution of any initialization code, so it's
customary to end such a file with "1;" unless you're sure it'll
return true otherwise. But it's better just to put the "1;", in
case you add more statements.

[ add comment ] ( 1 view )   |  permalink  |   ( 3 / 20 )

| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Next> Last>>