Random Post: cURL Callback Function
RSS .92| RSS 2.0| ATOM 0.3
  • Home
  • About Me
  • My Publications
  • My Work Domain
  • phpResource Feeds

    Fastest Solution to Count Number of Lines Inside a File

    August 23rd, 2006

    Here is another PERL stuff to share.

    Many systems have a wc program to count lines in a file:
    $count = `wc -l < $file`; die "wc failed: $?" if $?; chomp($count); ------------------------------- You could also open the file and read line-by-line until the end, counting lines as you go: open(FILE, "< $file") or die "can't open $file: $!"; $count++ while ;
    # $count now holds the number of lines read

    Here’s the fastest solution, assuming your line terminator really is “\n”:

    $count += tr/\n/\n/ while sysread(FILE, $_, 2 ** 16);

    Enjoy PERL. Enjoy Programming.

    Browser Detection by PERL

    August 23rd, 2006

    I am enjoying PERL a lot. I am seeing everything new in PERL. I want to share interesting and important PERL stuffs through my blog.

    Here is a PERL subroutine that detects whether the browser is Firefox or NOT.

    sub is_firefox {
    my $agent = ”;
    $agent = $ENV{“HTTP_USER_AGENT”} || ”;
    if (length($agent) && $agent =~ m/firefox/si) {
    return 1;
    return 0;

    Enjoy PERL, the scripting pioneer.


    Prize “CGI Programming with Perl” to Dhaka

    July 25th, 2006

    Yesterday I got “Innovation Award” winning prize from PHP Classes, an O’relly book named “CGI Programming with Perl”. The prize reached to Dhaka three days earlier, I released it by UPS and got in my hand yesterday. I started my reading on “CGI Programming with Perl” just after receiving the book. I developed two projects by Perl, but I had no “hard copy” book on Perl. This book will help me to know more about Perl. I have already digged a bit and found a lot resources there.

    Once again my thanks to “PHP Classes” members for their votes that made me the winner of the “Innovation Award” of May 2006.

    I am happy in programming !


    Learning Perl

    February 11th, 2006

    I am a beginner in Perl learning. I have started my Perl learning!! And I have already written and run my first “Hello World” Perl program. I am reading Mohammed J. Kabir‘s “Perl for Beginners” tutorial. I collected it from EVOKNOW Blog. It’s a nice collection. My special thanks to Kabir for such nice thing.

    Happy Scripting !!