good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Intrepidby Intrepid (Deacon) |
on Jun 24, 2000 at 20:36 UTC ( [id://19724]=user: print w/replies, xml ) | Need Help?? |
Welcome to the home node of The Unreasonable Man! (Soren 'Tino, "somian", Soren Andersen) “The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore all progress depends on the unreasonable man.” — George Bernard Shaw
Other Favorite Quotes"[André Malraux said] Do what you believe you must and leave the interpreting of it to others."
|
What else is on this node? [an erratic, partial TOC] | |
I use multiple Operating System / Platforms and therefore several different ports of Perl. | last update 28 Dec 2011 |
Interesting CPAN modules: stuff I want to check out when I find the time. | |
"Tricky" for me to remember how to use: An assortment of Perl topics that I need to look up excessively often. | last update 02 Mar 2005 |
My GPG public key | |
Our Solemn Intonement -- something to be mindful of. | |
Some things are more important than Perl: a short rant. | last update 08 Aug 2004 |
The syntax-highlighted rendition of a snippet offered in Perl Monks' Meditations. | last update 04 Jul 2004 |
Shell scripting in service of Perl: download and view PM nodecode. | last update 07 Aug 2003 |
Terribly kewl CSS scheme for Perl Monks. | last update 02 Sep 2004 |
[...]AUTHORS/ID/S/SO/SOMIAN/
The most reasonable of suggestions has been made in Dealing with An(?:no|on)ytroll by tirwhan. It deserves serious thought.
One thing that I've noticed in my time spent chatting in the cb here at Perlmonks is that the level of ethical sophistication amongst a few of my fellow cb'ers can be terribly low. I make this generalization because there's one prime point of all ethical systems that I can feel any respect for, and that is:
Might does Not make RightBut it is clear that among the cb'ers are those who don't understand this. They have an enormous blind spot when it comes to issues in the workplace or the Perl (or other kind of) hacker community. Maybe it's a generational thing; I'm in my 40s and many Monks are in their 20s. I think the times are shaping young people to have much lower sensitivity to this. Most are very quick to point out the shortcomings of political leaders but very few seem able to see that abuse of privilige and power plays a big role close around them in their everyday lives.
There are two kinds of social power generally at work in our world:
Both these exert their influence generally (not always) to the detraction of good in the lives of human beings, to the enhancement of evil. People seem to regard the exercize of power by individuals like irc ops as some form of divine right, which is fine as long as such people who think this way don't try to pass themselves off as freedom-loving people. Furthermore: there seems to be a general assumption that if a person has contrary views to an irc #channel-op or a Perlmonks God, they are automatically wrong. This is childish, immature, dangerous and pathetic.
Just as bad is the pattern wherein supposedly intelligent people automatically assume that the person saying a new thing that insults (in their view) or challenges a comfortable dogma, or other item of "social consensus," is automatically wrong.
The only positive change that has ever taken place in the world has come about because of alienated, despised malcontents who dared to speak truth to power. The only kind of human being truly worth honoring is one who can summon the personal courage to speak truth to power, on whatever level or in whatever form it takes (embodied as either the despot or the mob). No-one lives a worthwhile life without ever falling afoul of some embodiment of power, sometime during their lives. The rest of humanity live like sheep, and no society that deserves to be remembered by history erects monuments of honor to sheep.
When a person gets banned in irc or otherwise "punished" somehow in any kind of hacker social context, they fairly often deserve it because their actions have been contrary to the general good of the group. But not always. This distinction between "always" and "not always" is the difference between the destruction of the world and its salvation. It is everything. Not understanding this is the distinction between an ignorant person and a real citizen, whether of the Happy Realm of Hacking Free Software or of the World.
From the Wikipedia entry for Internet Troll we see this quote:
[Likewise,] accusers are often motivated by a desire to defend a particular Internet project, and references to an Internet user as a troll might not be based on the actual goals of the person so named. As a result, identifying the goals of Internet trolls is most often speculative.
The use of the term "Troll" on Perlmonks by a certain group of people is an example of something like what's described above. It reflects not on the accused person but on the accusers, who are misusing a type of peer group -based power (being the Despotic Mob) to exercize coercion against someone whose aims are, as many others see, not those of a troll at all. The very best that can be said of such misuse is that the accusers are engaging in reckless and irresponsible speculation. The worst is that they themselves are far more despicable than any "Internet Troll", that they are in fact aiming to give themselves the twisted pleasure of seeing their group power effectively deny another participant the option of continuing to engage in a reasonable relationship with the site, community or project in question.
One can only feel pity for people living with the kind of impoverished inner lives and distorted emotional personalities that would derive pleasure from such a thing, but unfortunately the modern world at least, with its intense pressures and demands, often gives rise to such it seems.
I don't see posts by Anonymous Monk beginning at 6:30pm on 7 Dec 2005, by using CSS to override display settings. The texts of postings of any nature by any non-existing (Anonymous) Monk are invisible for me. This is a measure that I've taken until such time as the preferred solution comes to pass (the preferred solution being: the Perlmonks site no longer allows Anonymous posting at all).
A side note: The application at cb60 is the only cb history interface that is currently working (to my knowledge) at the time of this writing, and is the only one that can be configured to ignore users as the live chatterbox can.
There's a particularly annoying kind of conduct that very frequently takes place and lands users who commit it on the following list. This consists of coming into the chatterbox with a minimal but strange-sounding question - one that rings "warning bells" for some of the experienced Perl users. When it is suggested that more information is needed because the approach seems dubious (perhaps based on a mistaken understanding of how something in Perl works), such an individual committing this type of annoyance then leaves in a huff, saying something like Thanks for the kind help in a sarcastic and injured way that is intended to cause guilt feelings.
This is playing the "Newbie Victim of Mean Monks" card, and it is not only stupid, and not only pathetic, but also wrong - because the chatterbox or Perlmonks in general is a place where many give of their time to try to help less experienced Perlers. These volunteers don't need to put up with that kind of childishness, the attempted emotional manipulation and tantrums; and in my opinion, should not put up with it.
Again, it is (in my opinion), really ok to insist on minimum standards of mature behavior in order to qualify for help or attention at Perlmonks.
Obviously I prefer to spend more time on the former (my favorites are Ubuntu and its parent distribution, Debian). On MS Windows I use both ActivePerl and the new Win32 Perl that's being called StrawberryPerl. I often build my own Perl installations from source, as well.
The quality of the user experience one has with the MS Windwoes OSes is highly variable. Some users find little lacking in it and some are driven crazy by it. One inclination that is not well-served by Microsoft is the desire to use the CLI (Command-Line Interface, but if you are here reading, you knew that ;-) …and so I rely on the long-lived and community-supported Cygwin environment (this is important: Cygwin is supported by volunteers; do not act like a petulant spoiled brat if you go asking for support {if you happen to try Cygwin out}; if you do, you will just be ignored). Cygwin provides a port of Perl that tracks the major release cycle of mainstream Perl and "acts like" Perl running on a unix OS platform. Cygwin also provides the Bash shell and many other GNU userspace components that are common to all GNU/Linux and other free unix OSes.
Because I have acquired years of experience using Perl on MS Windwoes, I do not have the oblivious outlook about file name extentions that is customary from users who do only work on unix platforms. My decision is to name Perl programs with a .plx extention which disambiguates these files from those containing Perl library code. I use the appropriate MS Windows commands (from the CMD.exe cli) to create the right Registry settings so that the files named with .plx extentions are associated with the perl executable.
Ripped off from busunsl's node:
righteousness () { perl -e' print "The troublesome entities, irksome to Monks:\n " , ( join " and ", map{ sprintf qq{$_ is safe as }.q{&#}.qq{%d;}, ord ; } qw/[ ]/ ) , "\n"; ' }
"[" left sq brkt [ [ "]" right sq brkt ] &#93; "<" left angle brkt > < or < ">" right angle brkt < > or > "mdash" em-dash — — "ndash" en-dash – – "lsquo" left single quotation ‘ ‘ "rsquo" right single quotation ’ ’
sh-prompt $ perl -MText::Wrap='wrap,$columns' \ -MText::Textile=textile \ -lp000we \ 'INIT{$columns=78} s{\cM?\cJ} [ ]g; $_=wrap(q[],q[ ],textile($_)).$\;' DRAFT.TMP
This should work fine in a MS Windows CMD shell too, with the alterations that (a) all single quotes around the -e script and perl flags are changed to double quotes, and (b) the line-continuation backslash/newlines are removed.
Depending on your OS and your work habits / preferences, you might want to use a Unix sh means of wrapping the Perl code implementing this technique (second thing below), or you might need a MS Windows console helper (in the form of a DOSKEY macro, shown immediately below). I've named this critter different things in different manifestations on different machines at different times ... but now I am aiming to settle on it being named PMTEST.
PMTEST=perl -le "do{$modn=$_;s!::!/!g;$_.=q[.pm];do{print qq[$modn is +not installed.];next} unless eval qq#require(\"$_\");1# && !$@;$modv= +defined(${$modn.q[::VERSION]}) ? ${$modn.q[::VERSION]}:q{[version und +efined]};$numtyp=2>$modv=~tr/.// ?'%s':'% 6d';printf qq[ %-*s $numty +p in %s\n],(length>30 ? 5+length:15+length),$modn,$modv,$INC{$_}}for +@ARGV;" $*
Sorry, those long (wrapped) ugly pieces of code are what's required for MS Windows CMD shell. The command interpreter does not offer any means (that I have discovered) of using continuing statements on multiple lines when defining a DOSKEY macro. Don't try a COPY-PASTE of the above, either, or you'll have to figure out how to remove every introduced newline inside the macro definition before the code will work. Trust me, you won't feel good about the wasted time.
To use the above code, you must place it in a *.bat or *.cmd file and then "execute" it from the MS Windows console (the commandline interface, CLI, CMD.exe).
Invoke the macro (not the .bat file it was saved in, which you execute only once per each shell session or instance) with a single arg, the Perl-style name of a module (for ex. “pmtest CGI” or “pmtest File::Find”).
# pmtest: bash reusable function authored by Soren Andersen # license/terms of use/modification/redist: same as Perl pmtest () { perl -e' my$modn = my$mod = "'$1'"; $mod =~s@::@/@g; $mod.=q[.pm]; die ("module $modn not installed.\n",$@) if ! eval {require qq[$mod];}; my $modv = defined ${$modn.q[::VERSION]} ? ${$modn.q[::VERSION]} : q{[version undefined]}; my$numtyp= (2 > $modv =~tr/.//) ? "%s" : "% 6d"; printf " %-*s $numtyp in %s\n", length($modn) > 30 ? 5+length($modn) : 15+length($modn), $modn, $modv, $INC{$mod}; '; return 0 }
This also needs to be "gotten into" the bash session somehow. Ths canonical way of doing so is to include the above in a shell initialization file like ~/.profile or ~/.bashrc.
In contrast with Unix-like platforms, MS Windows has it's own sense of Well-known Folders (not absolute filesystem "folders" but instead pointers to locations which can reasonably be expected to exist on most Windows machines, with some divergence between the bog-ordinary Workstation and the more complex Server kind of Windows installation).
These are abstractions, meta-directories if you like, which exist above the level of the actual filesystem and happen to be represented in the typical, default Windows ENV by variables like %APPDATA% and %ProgramFiles% and %ALLUSERSPROFILE%.
We can access the values assigned to these meta-directories using the API calls wrapped in the Win32.pm module (not in the core namespace which is automatically built in when Perl is created for a Windows system; the user has to explicitly say use Win32; in order to make this work).
Here's a simple one-liner to demonstrate:
Note that we did not even need to know the particular names of the metadirectories available on the specific version of Windows on which this is run, which is Kinda Cool imho.perl -MWin32 -le "my @ds=grep {/CSIDL_/} @{ [keys %Win32::] }; do {printf qq/%31s => %s\n/, $_, Win32::GetFolderPath(&{$Win32::{ +$_}}) } for map { $_->[0] } sort {$a->[1] <=> $b->[1]} map { [$_,&{$Win +32::{$_}}] } @ds"
Here's a way to get the location of the meta-directory of your choice, assuming that you choose with some clue to begin with ;-/ ... :
This should display the Special Folders that are named *PROFILE* (in globbing terms) and display the actual location(s) of such folders.perl -MWin32 -le "my @ds=grep {/^CSIDL_/ && /\U$ARGV[0]/} @{ [keys %Wi +n32::] }; do {printf qq/%31s => %s\n/, substr($_,6), Win32::GetFolderPath(&{$ +Win32::{$_}}) } for @ds" profile
Note also that the above commandlines aren't broken up in actual use, and will have to be mended
by any who wish to try it out. MS Windows CMD shell doesn't allow multi-line commands
even inside quotes UPDATE:
You can create multi-line
Perl one-liner (console input) scripts in the interactive Windows CMD shell. You will escape the newline with
the ^ character (caret) but this does not work to span lines inside quotes.
Instead, you will use -e repeatedly, just as you may do in a *nix sh-type shell. Here's the
oneline demo above, thanks to pKai who educated me on this!:
perl -MWin32 -e "my @ds=grep {/CSIDL_/} @{ [keys %Win32::] };" ^ -e "do {printf qq/%31s => %s\n/, substr($_=>6), Win32::GetFolderPath(& +{$Win32::{$_}}) }" ^ -e "for map { $_->[0] } sort {$a->[1] <=> $b->[1]} map { [$_,&{$Win32: +:{$_}}] } @ds"
Here's a DOSKEY macro-ized version of the code above. Handy for interactive CMD shell use where you need to quickly check the list of Special Folders (or a particular group of them).
Remember to reformat the code above so that no linebreaks are present. The line that begins with DOSKEY needs to be one continuous line.:: MS Windows BAT/CMD syntax. Wraps a Perl one-liner program. DOSKEY SPECIALFOLDERS=perl -MWin32 -e "my @ds=grep {/CSIDL_/} @{ [key +s %%Win32::] }; do {printf qq/%%24s=>%%s\n/, substr($_=>6), Win32::GetFolderPath( & +{$Win32::{$_}} )} for map { $_->[0] } grep {(0+@ARGV ? $_->[0]=~m<$ARGV[0]>i : 1) +} sort {$a->[1] <=> ${b}->[1]} map { [$_,&{$Win32::{$_}}] + } @ds" $*
DOSKEY still exists on Windows XP, Vista, and 7. In a CMD shell you can query what macros you've defined by doing D:\ > DOSKEY /macros and can define new macros by saying something like this: D:\ > DOSKEY perlversion=perl -le "printf qq[%vd$/]=> $^V" This is a somewhat trivial and quite contrived example of course. ;-)
Here's a less contrived example. This will make cli work easier if you find yourself working in a directory named like C:\Documents and Settings\You There...
DOSKEY compactcwd=FOR /F "delims=*" %%N IN ("%CD%") DO CD %%~sN
There are some DOSKEY/Perl gotchas to look out for. Note that this is not an exhaustive list.
;= @echo off ;= rem Call DOSKEY and use this file as the macrofile ;= %SystemRoot%\system32\DOSKEY /listsize=1024 /macrofile=%0% ;= rem In batch mode, jump to the end of the file ;= goto end ;= rem *************************************************************** +*** ;= rem * Filename: DOSKEY-M1.cmd ;= rem * Version: 2.0 ;= rem * Author: Soren Andersen <somian08@gmail.com> ;= rem * Purpose: Some useful perl 1-liners ;= rem * license/terms of use/modification/redist: same as Perl ;= rem * Last modified: Wed 28 Dec 2011 ;= rem * History: ;= rem *************************************************************** +*** ;= rem PMTEST: Test for use of a Perl module PMTEST=perl -le "do{$modn=$_;s!::!/!g;$_.=q[.pm];do{print qq[$modn is +not installed.];next} unless eval qq#require(\"$_\");1# && !$@;$modv= +defined(${$modn.q[::VERSION]}) ? ${$modn.q[::VERSION]}:q{[version und +efined]};$numtyp=2>$modv=~tr/.// ?'%s':'% 6d';printf qq[ %-*s $numty +p in %s\n],(length>30 ? 5+length:15+length),$modn,$modv,$INC{$_}}for +@ARGV;" $* ;= rem SPECIALFOLDERS: Display Well-Known Folder pathnames SPECIALFOLDERS=perl -MWin32 -e "my @ds=grep {/CSIDL_/} @{ [keys %Win32 +::] }; do {printf qq/%24s=>%s\n/, substr($_=>6),Win32::GetFolderPath( +&{$Win32::{$_}})} for map {$_->[0]} grep {(0+@ARGV ? $_->[0]=~m#$ARGV +[0]#i : 1)} sort {$a->[1] <=> ${b}->[1]} map {[$_,&{$Win32::{$_}}]} @ +ds" $* ;= :end
ppm3 Documentation |
|
Note Added:
"Since Perl 5.6 and Perl 5.8 are not binary compatible, we started appending the Perl version number to the architecture string in ActivePerl 5.8. Try this:<ARCHITECTURE NAME="MSWin32-x86-multi-thread-5.8" />Both ppm2 and ppm3 in ActivePerl 8xx have been patched to use these architecture names." |
The recommended tool for building Perl from the source kit using a Free C/C++ compiler (MinGW), is dmake. This variant of the classic make tool is now maintained by OpenOffice.org folks ("tools" Project) and the dmake manpage is online. dmake on CPAN: is now maintained by Steve Hay and is no longer the extremely old code offered years ago by Gurusamy Sarathy. Steve is building it using MSVC++ from the OO.org source mentioned above. |
Tom Phoenix' script "Inside" on CPAN.
perl -MCPAN -l \ -e 'CPAN::Config->load;' \ -e '@pcnt= $^O eq "cygwin"? qw(-n 2):qw(-c 2);' \ -e ' do{ $fn=$_; if (s#^\w+p://([^/]+).*#$1#) { print $fn; system("ping",@pcnt,$_); print "\n","-"x52 } } for @{ $CPAN::Config->{urllist} }' # code tested on cygwin and GNU/Linux
perl -MFile::stat -MCPAN -MLWP::Simple=mirror -le 'CPAN::Config->load; + my $fhost;' \ -e 'my $Mdat = $CPAN::Config->{keep_source_where}.q[/MIRRORED.BY];' +\ -e 'if (-e $Mdat and -M _ < 14) { print qq[$Mdat: freshness OK, last + modified: ]' \ -e ' .gmtime stat($Mdat)->mtime()' \ -e '} else { ($fhost)=grep(/^http/,@{$CPAN::Config->{urllist}});' \ -e 'die "no suitable cpan http mirror host" if !$fhost;' \ -e 'printf q[%s],qq[File $Mdat not found or stale, will d/l fresh fr +om $fhost ...];' \ -e 'mirror($fhost .q[MIRRORED.BY] , $Mdat) and print q[ ].gmtime(sta +t($Mdat)->mtime)}'
Wrap the code above in a function in your shell initfile if you are a bash user and you like to have such conveniences at your "fingertips", as I do:
function mirrorsrefresh { < above perl code here > }
More tips on coping with CPAN.pm can be found here at "dumpcpanurls" Snippet.
#! /usr/bin/perl -l # *or* $\ = "\n"; # do it once and won't have to again.
%hash = ( key => grep [ chomp ], `which ps` ); which does the same things as: %hash = ( key => grep {chomp || 1} `which ps` );
Attribution: seen on comp.lang.perl.misc in msgid <3F447BDB.9928761A@acm.org>.
# Previous declaration of "$filename" is assumed. my $data = do{local(@ARGV,$/) = $filename;<>}
Attribution: here
my $data = do{ open local(*FH),$filename or die "can't open: $!" ; sysread( FH, my $buf, -s FH ) ; $buf ; };
(@a[0 .. ($#a = $#b)], @b) = @{[ @b, @a]} # swap two arrays
my $home = $ENV{'HOME'} || $ENV{'LOGDIR'} || (getpwuid($<))[7] || die "WAAAAA! I'm HOMEless!\n"; # from `perldoc perlop'.
Dump a string of opcode names that can be fed to Safe::new->permit. Based on knowledge / shell elan shared by ysth.
$ perl -MO=Concise,-exec <FILENAME.pl> \ | perl -lnaF -e '$_=$F[2]; s/\W.*//; $h{$_}=0; END{ print join " "=>k +eys %h}'
The goal is to eliminate duplicates without disturbing existing ordered-ness. Thus the property of mundane hash assignment such that duplicates disappear is not sufficient by itself, but in a combination demonstrated in this code below, the truth-ness of a hash value can be used to prevent duplicate array entries.
#! /usr/bin/env perl # "uniqnord" - remove dups from a list of identifiers. use strict; use warnings; $, = ! -t STDOUT ? "\n" : " " ; my %seen = (); $\ = "\n"; print STDOUT join($, => grep {!$seen{$_}++} map { if (/ +/) { $/=" " ; @_=split } else { chomp ; $_ }} <>) __END__ |
The real code:
|
Log In? | |||
---|---|---|---|
Domain Nodelet? | |||
Chatterbox? | |||
How do I use this? • Last hour • Other CB clients | |||
Other Users? | |||
Others browsing the Monastery: (8) As of 2024-10-12 15:51 GMT | |||
Sections? | |||
Information? | |||
Find Nodes? | |||
Leftovers? | |||
| |||
Voting Booth? | |||
No recent polls found | |||
Notices? | |||
|