Coding

Coding

Sorted By Creation Time

Perl links

Contact:http://www.packetnexus.com

http://madhaus.utcs.utoronto.ca/doc/mysqlperl.html

http://www.cs.purdue.edu/homes/cs290w/perlLecs/PerlDB.html


Back to the Index

mysql import test file

Contact:http://www.packetnexus.com

http://www.phpbuilder.com/forum/read.php3?num=5&id=1889&loc=0&thread=1889


Back to the Index

HTML script

Contact:http://www.packetnexus.com

tohtml.pl: put a HTML wrapper around a text 
 
#!/usr/local/bin/perl
#change a text file to html
$first = 1;
print <html>;
print "\<head\>\n";
while ($line = <>) {
	if ($first) {
		$first = 0;
		print "\<title\>$line\</title\>\n";
		print "\</head\>\n";
		print "\<body\>\n";
		$line =~ s!(.*)!\<h1\>\1\</h1\>!;
		print $line;
	}
	else {
		# next 3 lines presume there isn't any html markup already 
		# in the file
		$line =~ s/&/&/g;
		$line =~ s/\</</g;
		$line =~ s/\>/>/g;
		# blank line = new paragraph
		$line =~ s/^$/\<p\>/;
		print $line;
	}
}
print "\</body\>\n";
print "\</html\>\n";
dehtml.pl: strip HTML markup from a text 
 
#!/usr/bin/perl
#strip html tags
while (<>) {
    $_ =~ s/<[^>]*>//g;
    print;
}


Back to the Index

AWK Search and replace

Contact:http://www.packetnexus.com

GLOBAL REPLACE in the files:
 awk '{gsub("call", "mall", $0); print > FILENAME}' *.kumac
 change call to mall in all *.kumac files 


Back to the Index

Perl Search and Replace

Contact:http://www.packetnexus.com

#!/bin/perl
#
# Kevin Kadow ([email protected]) <A&NBSP;HREF="HTTP: ? kadow
www.msg.nethttp://www.msg.net/kadow/
# Can be downloaded from <A&NBSP;HREF="HTTP: www.msg.net search.html? small
utilityhttp://www.msg.net/utility/small/search.html
# For 1stomni, free for all to use as long as the comments are kept intact!
#
# Search and replace strings in html files
#
require 'find.pl';

#
# Change these variables as needed.
#
$dir="/export/home/worldwide/htdocs";

$search="http://www.1888wwsports.com/1stomni.com/virtuflex.cgi";

$replace="http://www.1888wwsports.com/phpshop/cart.php3?action=add";

warn <<"EOF";
Starting search/replace script $0
  Search all files below $dir
  Looking for string $search
  Replace the string with $replace

EOF


#
# Do the actual work
#
&find($dir);
warn "Scanned $files making $changes changes.\n";
exit(0);

################ SUBROUTINES FOLLOW #################################

#wanted
#
# This routine is called by 'find', once for each file, directory, etc.
#
sub wanted {

#Skip everything except files named .html or .shtml
return unless( -f $_ && m/\.[s]*html$/);

&update("$dir/$_");
}


#update
#
# Do the search-and-replace on a given file
#
sub update {
local($file)=@_;

local(@contents);

# Open the file for reading and writing (the + does that)
unless(open(FILE,"+<$file")) {
	warn "Cannot open $file for updating, Error: $!\n";
	return;
	}

warn "Updating $file\n";
$files++;

# Read the contents into an array, replacing the string as we go
while ($_=) {
	$changes += s/$search/$replace/ig;
	push(@contents,$_);
	}

# Go to the beginning of the file
seek(FILE,0,0);

# Update the contents with the data from our array
print FILE (@contents);
close(FILE);
}

###EOF###


Back to the Index

PHP intro

Contact:http://www.packetnexus.com

http://www.nwfusion.com/columnists/2001/00301768.html

Last week we started looking at the Web server scripting language PHP.
As we saw, the open source language is not only wildly popular, but also
supported by a range of commercial tools. Add to that a great support
site and a tremendous library of documentation and you can see why PHP
is so highly regarded.


Back to the Index