All posts by WhiteWind

About WhiteWind

I'm a Perl-PHP Developer from India. I'm a great fan of Wordpress & Perl.

How to set a div fixed horizontally but not vertically?

To set the divs’ position horizontally fixed but not vertically, use the following code :

HTML

<div id="container">
    <div id="manu"></div>
</div>

CSS

<style type="text/css">
#container {
 position:relative;
    width:700px;
 height:1000px;
    top:50px;
    left:50px;
 background-color:yellow;

}

#manu{
    position:fixed;
    width:100px;
    height:100px;
    background-color:blue;
    margin-top:20px;
    margin-left:400px;
}
</style>

Jquery

<script type="text/javascript">
$(window).scroll(function(event) {
   $("#manu").css("margin-left", 400-$(document).scrollLeft());
});
</script>

To see demo please click the link below :

http://jsfiddle.net/kL33K/

How search a string in an array?

To search a content in an array in perl, we can use the following format,

my @a=('Hai','Leop','mac');
my @b = grep(/a/i, @a);
print join ",",@b;

The output will be as follows:

Hai,mac

How to get the size of a hash in Perl?

To get the hash in Perl ,

%hash=(
     a=>'Max',
     b=>'Rac',
     c=>'Neo'
);
print scalar keys(%hash);

The out put will be as follows:

3

replace() in Perl?

It’s as follows:

sub replace
{
	my($old,$new,$string)=@_;
	$string=~s/$old/$new/;
	return $string;
}

It should be called as follows:

print &replace($to_be_changed_from,$change_it_to,$full_string)

How to check wether a module is installed in Perl?

There are many scenarios  that we are in need to check the availability of a module both programatically and via the Terminal.

If we need to check it via Terminal or command prompt, use the following method :

perl -XML::RSSGEN -e 1

If you need to check it via the Perl program use the below script to get the result.

sub try_load {
  my $mod = shift;

  eval("use $mod");

  if ($@) {
    return(0);
  } else {
    return(1);
  }
}
my $module = "XML::RSSGEN";
if (try_load($module)) {
  print "loaded\n";
} else {
  print "not loaded\n";
}