A Happy April Fool (me) wrote this and thought it would be fun to let everyone interested in all things Perl to have a little look and a big laugh. :O) #!/usr/bin/perl =pod IMPORTANT NOTE- V V | | | | V V You are really going to miss out on a lot of great things if you just run this code and don't read it. The comments themselves comprise, in my opinion, the greatest benefit you could take from looking over this code. This PUNware is free, and you may use and distribute it under the same terms as Perl itself. =cut use strict; &redirect(*STDOUT,'/var/tmp/$scriptname.output-log'); print(<<'__alpaca__') and exit; # !<is(Yet::Another::CamelStory) ? .so just H2XS : '(2;' < painstaking`; ++$i; UNIVERSAL::can(do); # lots of things that are trippin' # just a few lines of code # and I'm RSA cryptin' $C(amel_PAN) # is my /src for (@INCredible) { &code; # there^s more bad *$%@ camel spit # than ten centepedes' toes $this->{camel}=~s/the man//; foreach (@package) {} @I::carry::ISA = qw( yet another ); bless \@INC and $A=Brand->new('library'); taint(); $nothing=~s/more/cool/; # ...than Clyde Camel, I'd say. $cause=~s/it\'s the|plain/truth/; camel Clyde is ......................ok ......................ok ......................ok Passed 3 of 3 tests. for my($rhymes) ($were,$well,$woven) { # let your kit be complete # may your feet remain cloven } # the __END__ HOME: &mean while( ($back,@at,"@{[the_ranch()]}") ); # ... Yeah, yeah print('JAPH') and whatever. Nice poem. riiiiiight ;O) Clyde Camel -- world peace. linux. camels. [Clyde closes his email client, folds down the screen on his laptop, grabs a drink. roll camera.] And now, for our feature presentation... __alpaca__ # ------------------------------------- # redirect STDOUT/STDERR/ (or any open # filehandle which is not flock()-ed # ------------------------------------ sub redirect { my($FH,$dest) = @_; my($outfile) = $dest; my($dir) = ''; $dest =~ s / (?# This is an embedded comment. I like comments. ) (?x) (?# that little thingy up there with the question mark followed by an 'x' is a dirty little trick you can use to be really sneaky and make really cool-looking multi-line regex like this. You are instantly more cool when you use multi-line regexes. You can put whatever regex flag you want in it. For example, you can write one that has any number of the flags you need: ?gimsox Just make sure to keep the 'e' flag on the outside of the regex because it doesn't seem to work when placed on the inside of the regex. I don't know why, or if that is entirely correct, so go and look it up yourself. --then you can come tell me! heh, heh, heh ) ^(.*) (?# That little combo immediately above this comment is the regex syntax to say we want to match everything from the begining of the string we've got, all the way up to the last possible occurrance of the next part of the regex. ) (?:\\|\/|\:) (?# This next one, the combo right above, sets forth the pattern we're going to use in order to match that final directory seperator character to be found in the string. This pattern accounts for the filesystem notation on MS, *nix, Mac, and other platforms ) (.*) (?# this regex grouping above is asking Perl* to match from the place in the string immediately after that seperator character we found, all the way up to the very end of the string --which shouldn't be all that far really. That piece of text we had Perl* find for us should be the file name which follows the directory path which might also be present in the string. *Well actually... The formal name for the mechanism which implements the regular expression functionality in Perl is: "the Perl regular expression engine" ) (?# Finally, we tell Perl to take the pieces of text that matched each grouping in the pattern and assign them to this set of scalar variables below. That way, we can easily use them later. ) / $dir = $1; $outfile = $2; $dest; /e; # Now if I said that wasn't the most over-blown regex I ever # saw, I'm be the most big, fat, dirty, rotten liar I ever saw. # Uhmmm, would somebody take a moment for a second to write that # down in the book of redundancy book. # that regex is better written: # # $dest =~ s/^(.*)(?:\\|\/|\:)(.*)/$dir=$1;$outfile=$2;$dest/ex; # # ok, moving on... # make the stupid directory if it isn't there yet, but only if the # directory isn't named '' if ($dir ne '' and not -e $dir) { # make the directory with the access permissions that will # allow a Perl process to write new files in it. mkdir($dir, 777) # Just hack, sputter, and keel over and die if you can't even # handle that, you wussie. And if you can't, you better have # a good explanation cause I'll be all over your 'tail -f' or die(<<__err__); Can't mkdir "$dir" --$! ...Try making it manually __err__ } # close down whatever open IO handle you want, or... close($FH) and open($FH, qq[>> $dir/$outfile]) # cough, hack, keel over, and fix it yourself. or die(<<__err__); Can't open "$dir/$outfile" --$! ...Consider fixing this code. __err__ } -- -Tommy Butler, consultant Atrixnet, for Internet Business Software http://atrixnet.com 6711 Forest Park Drive Dallas, TX 76001 -- I need work! http://www.atrixnet.com/contracting/ Request a script! mailto:gimmecode@atrixnet.com Get help with code! mailto:helpme@atrixnet.com Get my resume! http://www.atrixnet.com/resume/ Visit the open source Perl archives at Atrixnet. http://www.atrixnet.com/pub/