|
| Browse files and folders
#!/usr/bin/perl -w |
CreateProcessuse Win32::Process;
Win32::Process::Create( $Win32processObj,
$ARGV[0],
"",
0,
NORMAL_PRIORITY_CLASS,
"." ) || die "Failed to create process.\n";
while ( !$Win32processObj->Wait( 1000 ) )
{
sleep(1);
print "waiting for process to finish\n";
}
$Win32processObj->GetExitCode( $exitcode );
if (0 != $exitcode)
{
$rv = 1;
}
print "Process Exit Code = $exitcode\n";
print "Return Value = $rv\n";
************************************************* use Win32::Process;
Win32::Process::Create ($Win32processObj,
$ARGV[0],
"",
0,
NORMAL_PRIORITY_CLASS,
"." ) || die "Failed to create process.\n";;
$pid = $Win32processObj-> GetProcessID();
if( $Win32processObj-> Wait(1))
{
print "Process is done\n";
}
else
{
print "Process is running as $pid\n";
}
|
| Make Upper String
#!/usr/bin/perl
|
| Read File open (LOGFILE,
"c:\\log.txt") or die "Kan c:\\log.txt niet openen"; |
| Read/write file
open(FILEREAD, "< c:\\log.txt"); |
| Replace Char/String
#!/usr/bin/perl |
| Replace Char/String
method sub replace |
| Replace slash/Backslash
sub replaceslash |
| Find string and give
place $string = "Woord1 Woord2 Woord3 Woord4"; |
| Time - print as string
($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, |
| Advanced - Find WISE
properties use strict; #use warning, and strict |
Example find Gurus #!/usr/bin/perl -w
use strict; #use warning, and strict
my $dir_root; #dir to start in
sub replaceslash
{
my $value = $_[0];
my $Slash = "/";
my $BackSlash = "\\";
my $value =~ s/$Slash/$BackSlash/g;
return $value;
}
sub dir_read
{
#parse directory for directories and files
#local to this function
my @dir_list;
my @file_list;
my $dir_prefix = $_[0];
#print "reading dir: ${dir_prefix}\n";
opendir(aDIR, $dir_prefix);
#read, add to array
while($_ = readdir(aDIR))
{
#if a dir
if(-d "${dir_prefix}/${_}")
{
#dont allow . or ..
if($_ ne "." && $_ ne ".." && $_ ne ".svn")
{
#add to array
push(@dir_list, "${dir_prefix}/${_}");
}
}
#else a file
else
{
#filter any files you don't want
my $str = $_;
$str = lc($str);
if( $str eq "properties.txt")
{
push(@file_list, "${dir_prefix}/${_}");
}
}
}
closedir(aDIR);
#search lower dirs
foreach $_ (@dir_list)
{
my $subsystem = $_;
$subsystem = lc($subsystem);
my $var = index($subsystem, "_v");
if ($var > 0)
{
my $tail = "\\adm\\properties.txt";
my $properties = "${_}${tail}";
push(@file_list, $properties );
}
else
{
&dir_read($_);
}
#&dir_read($_);
}
foreach $_ (@file_list)
{
my $line;
if (open (LOGFILE, $_))
{
while ($line = <LOGFILE>)
{
my $string = $line;
$string = lc($string);
my $var = 0;
$var = index($string, "gurus=");
#print "$line - $var\n";
if ($var eq 0)
{
print "\tFile: ${_}\n";
open(FILEWRITE, ">> d:\\gurus.txt");
#my $new = replaceslash($_);
print FILEWRITE $_;
print FILEWRITE "\t";
my $gurus = substr($string,6);
print FILEWRITE $gurus;
close FILEWRITE;
}
}
close LOGFILE;
}
}
}
if(! $ARGV[0])
{
#print usage
print "Usage: perl dirlist.pl rootpath\n";
}
else
{
#check if path exists
$dir_root = $ARGV[0];
if( -d $dir_root)
{
#dir is ok
print "root directory: ${dir_root}\n";
}
else
{
#end
die("root directory: ${dir_root} does not exist!, stopped\n");
}
#read dir, and sub directories
&dir_read($dir_root);
print "done.\n";
}
|
Example DBI use DBI;
$sqlstatement = "select * from [table]";
#open connection to Access database
$dbh = DBI->connect('dbi:ODBC:driver=microsoft access driver (*.mdb);dbq=[DBPATH]', [USERNAME], [PASSWORD]);
#prepare and execute SQL statement
$sth = $dbh->prepare($sqlstatement);
$sth->execute
|| die "Could not execute SQL statement ... maybe invalid?";
#output database results
while ( @row = $sth->fetchrow_array() )
{
print "@row\n";
}
|
Example DBX (email file use Mail::Transport::Dbx;
my $dbx = eval { Mail::Transport::Dbx->new("Inbox.dbx") };
die $@ if $@;
# more convenient
for my $msg ( $dbx->emails )
{
print $msg->subject . "\n";
}
|
Example DBX to XML
use strict;
use Mail::Transport::Dbx;
use Data::Dumper;
use XML::TreePP;
my $dbx = eval { Mail::Transport::Dbx->new("inbox.dbx") };
die $@ if $@;
my $data;
if ( -e "data.xml" )
{
$data = _XMLtoHash("data.xml");
}
my %arr;
# more convenient
for my $msg ( $dbx->emails )
{
my $id = "ID".$msg->msgid;
if ($msg->msgid =~ /^<(\w+)\@?.*>/)
{
$id = "ID".$1;
}
if ( !defined $data->{$id} )
{
my %new = parseBody($msg->body);
%arr->{$id} = {%new};
}
else
{
my %new = %{$data->{$id}};
%arr->{$id} = {%new};
}
}
_hashToXML(\%arr, "data.xml");
sub parseBody
{
my $body = shift;
my @body = split("\n", $body);
my %out;
my $item;
foreach my $line (@body)
{
chomp($line);
$line =~ s/\n//sg;
$line =~ s/\r//sg;
if ($line =~ /^\[(.+)]: (.+)/)
{
$item = $1;
$line = $2;
}
if ($line =~ /^\[END\]/)
{
$item = "";
}
if ($item ne "")
{
if (%out->{$item} ne "")
{
%out->{$item} .= "
|
| Example OO use
Class::Struct; |