Pages

Showing posts with label Perl. Show all posts
Showing posts with label Perl. Show all posts

Tuesday, May 15, 2012

split integer value from others character



  #!/usr/bin/perl

  use strict;


  my $data = '2323424: 2434324, 3455543543';
  my @ftr =();
  my @values = ();
 
   @values = split(/(\d+)/, $data);

  foreach my $val (0 ..  $#values) {

unless ( $values[$val] =~/^[0-9]+$/)
{
splice(@values, $val, 1);

}

  }

  print " @values\n";
  exit 0;

Wednesday, May 2, 2012

Perl CGI for beginner

Good post for beginner:
http://www.perlmonks.org/?node_id=44536

Website to download apache : httpd-2.0.64-win32-x86-openssl-0.9.8o.msi
http://httpd.apache.org/download.cgi#apache24

Friday, April 20, 2012

read text file and store line in array



if (-e $file )
{
open(ori, $file);
while( my $line = )
{
if ($line =~ m/^connect/i)
{
push(@array,$line)
}
}
}
else
{
print" cannot find the file";
}


reference
1.http://stackoverflow.com/questions/1512729/how-can-i-search-multiple-files-for-a-string-in-perl

Thursday, April 12, 2012

verify whether variable is defined in perl

my $variable;

if (defined($variable))
{
print "defined";
}
else
{
print "not defined";
}

#---------------

unless (defined($variable)) {
print " not defined";
}
else
{
print" defined";
}

verify whether array is empty perl

use strict; use warnings;
my @array;

if (@array)
{
print "array not empty";
}
else
{ print "array empty";
}
------------------------------------------
unless (@array)
{
print "There is element inside array.";
exit(1);
}

Monday, April 2, 2012

split string by using regular expression

http://perlmeme.org/howtos/perlfunc/split_function.html

Wednesday, March 28, 2012

perl 2 array

my @num = qw (1 2 3 4 5); my @alp = qw (A B C D E); #One way for my $index (0 .. $#num) { print "$num[$index]-$alp[$index]\n"; } #Or print "$num[$_]-$alp[$_]\n" for (0 .. $#num);

Wednesday, March 21, 2012

@files = ;

Or if you just want a list of the files with the extension .html:


@files = ;



-e File exists.
-z File has zero size (is empty).
-s File has nonzero size (returns size in bytes).
-f File is a plain file.
-d File is a directory.
-l File is a symbolic link.

Thursday, November 10, 2011

Array Perl



To get the index and item

for my $i (0 .. $#x) {
print "$i: $x[$i]\n";
}
To get the last item in array
. $array[$#array] .
To get the total number of array

.  scalar @array .
To get the max index in array
$#array
To Output the item of array
foreach (@array)
{
$element = $_;
print " $element\n"

}




References :
1. http://www.tutorialspoint.com/perl/perl_arrays.htm
2. http://perlmeme.org/howtos/data_structures/arrays.html

Monday, October 17, 2011

Extract Excel contents from perl

This code is used to calculate no. of w/s in excel file and read the worksheets' name.

my $sheetcnt = $Book->Worksheets->Count();
foreach (1..$sheetcnt){
print "\t" .$Book->Worksheets($_)->{Name} ."\n";
}


While last row and column can be read by using this:-

Finding the last Column and Row

my $LastRow = $Sheet->UsedRange->Find({What=>"*",
SearchDirection=>xlPrevious,
SearchOrder=>xlByRows})->{Row};

my $LastCol = $Sheet->UsedRange->Find({What=>"*",
SearchDirection=>xlPrevious,
SearchOrder=>xlByColumns})->{Column};

All of above code are use Win32::OLE without using complicated spreadsheet perl module.

Reference
1. http://www.perlmonks.org/?node_id=153486
2. http://www.ngbdigital.com/perl_ole_excel.html
3. http://perlguru.com/

 

site weekly hits