Convert stdin text to HTML output

Perl No Comments »

#!/bin/perl
#az stdio input textfile-t html-ben menti ki
print "\n”;
while (<>) {
chop ($_);
print $_ . “
\n”;
}
print “\n”;

Web server cgi script sending out HTTP header

Perl No Comments »

#! /usr/bin/perl
BEGIN {
print "Status: 200 OK\nContent-Type: text/html\n\n";
}

How to extract email addresses from HTML sources?

Perl No Comments »

#!/usr/bin/perl

$cimek=1;
while (<>) {
if (/[\w.-]+\@(?:[\w-]+\.)+\w+/) {
print “$cimek: $&\n”;
$cimek=$cimek+1;
}
}
print “Total $cimek.\n”;

Printing ASCII table

Perl No Comments »

#!/usr/bin/perl

for $i (32..127) {
printf qq/kod=%3d. hex=%02X ( /, $i, $i;
print chr $i, " )\n";
}

How to use different long number formats?

Perl No Comments »

foreach $i (0xfffe,1_000_000, 0xfffeeaa1) {
printf "%12u\n", $i;
}

One in a Billion pseudo random probability test

Perl No Comments »

#!/usr/bin/perl
srand;
$c=0;
for ($i=0; $i<1e6; $i++) {$c++ if rand(1e9) < 1} print "One in a Billion occured $c times!\n";
print "\nMachines with randbits=15 it's about 30.\nChecking perl -V:randbits\n";
exec("perl -V:randbits\n");

How to play music from Windows command line?

Perl No Comments »

#!perl
use Win32::Sound;
my $wavfile = $ARGV[0];
die "Usage: sound32 wavefile\n" if $wavfile !~ /\.wav$/i;
Win32::Sound::Volume( '100%' );
Win32::Sound::Play( $wavfile );
Win32::Sound::Stop();

Ekicrypt credit card merchant transfer code test case

Perl No Comments »

#!/usr/bin/perl

use LWP::Simple;

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

$pTS=sprintf("%4d%02d%02d%02d%02d%02d",$year+1900,$mon+1,$mday,$hour,$min,$sec);
$pPID="IEB0001";
$pTRID="0000000000000001";
$pUID="IEB0001";
$pAMO="1000";
$pCUR="HUF";
$pLANG="HU";
$pURL = "http://www.webhauser.com/teszt.html";

$cleartext = "PID=$pPID".
"&MSGT=10".
"&TRID=$pTRID".
"&UID=$pUID".
"&AMO=$pAMO".
"&CUR=$pCUR".
"&TS=$pTS".
"&AUTH=0".
"&LANG=$pLANG".
"&URL=$pURL";

@args = ("-p","new/","-s",'"'.$cleartext.'"');
system("ekide",@args);

Very efficient method of sorting hashes

Perl No Comments »

One of the more interesting items Randal covered was the Schwartzian Transformation. Simply put, the Schwartzian Transformation is a very efficient way to sort hashes.
Here it is, in it’s entirety:

#!/usr/bin/perl

@sorted_files =
map { $_->[0] }
sort { $a->[1] < => $b->[1] }
map { [ $_, -s $_ ] }
< *>;

This example sorts a directory by file size but Randal assured us it can be easily modified to fit just about any situation.

Counting HTML / XML Tags from stdin

Perl No Comments »

#!/usr/bin/perl

undef $/; # enable "slurp" mode
$_ = <>; # whole file now here
$/ = \1234; # set back

while ( /< (([^ >]|\n)*?)>/ ) {
$count++;
print “$count. $&\n”;
$_ = $’;
}

WebSite Powered by webHauser
Entries RSS Comments RSS Login