Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Perl: Reading Single Characters from the standard input

#!/usr/bin/perl -w
  use Term::ReadKey;
  ReadMode('cbreak');
  print "Press keys , Ctrl-C to exit.n";
  while (1)
  {
      $myKey = ReadKey(0);

Perl: How to check end

#!/usr/bin/perl -w
print "Enter text: ";
$line=;                        
foreach $elem ($line) {
    if ($elem =~ /perl$/)
    {
        print "	Perl

Perl: Reading Passwords from the standard input

 #!/usr/bin/perl -w
use Term::ReadKey;
print "Enter your password: ";
ReadMode('noecho');                  
$password = ReadLine(0);
chomp $pass

Perl: Reading Microsoft Excel File

use Spreadsheet::Read;
# Read MS Excel .xls
my $ref  = ReadData( 'test.xls' );
my $fval = $ref->[1]{A3};
my $uval = $ref->[1]{cell}[1][3];

Perl: How to check beginning

#!/usr/bin/perl
print "Enter a text: ";
foreach $elem ($ligne=)    
{
    if ($elem =~ /^perl/)
    {
        print "Perl Found perl at startn'$elem'.

Perl: remove whitespace of a String

sub trim
{
    my @out = @_;
    for (@out) {
        s/^s+//;          
        s/s+$//;         
    }
    return @out == 1
              ? $out[0]

Perl: Check if word is a palindrome

@mySequence=("Otto","Madam, I'm Adam", "demo");
foreach $word(@mySequence)
{
if ($word =~ /^(w+)w?(??{reverse $1})$/ )
{
    print "$word is a palind

Perl: get website title

  use LWP;
  die "Please, get website URL" unless @ARGV;
  foreach $url (@ARGV) {
      $ua = LWP::UserAgent->new( );
      $res = $ua->get($url);

Perl: Approximate Matching

#!/usr/bin/perl -w
use String::Approx qw(amatch);
open(FH, "c:/test.txt")                 
	 or die "Cannot open this file: $!";
while()
{
    # Fi

Perl-regularExpression: Testing for a Valid Pattern

do {
    print "Enter your pattern? ";
    chomp($pat = <>);
    eval { "" =~ /$pat/ };
       warn "Invalid pattern $@" if $@;
} while $@;

Perl: find the number of days between two dates or times

use Date::Calc qw(Delta_Days);
@date1 = (2011, 1, 30);        
@date2  = (1985, 3, 05);     
# calculate the difference between the dates
$difference