[27474] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 9085 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 24 14:05:48 2006

Date: Fri, 24 Mar 2006 11:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 24 Mar 2006     Volume: 10 Number: 9085

Today's topics:
        Accesing lexical vars from XSUB <bol@adv.magwien.gv.at>
    Re: Calculations with ',' as decimal delimiter <news@chaos-net.de>
    Re: Code review request. <a24061@yahoo.com>
    Re: Debugging with Speech: Issues and Work-arounds? <vtatila@mail.student.oulu.fi>
        Equivalent of ls -d <bxb7668@somewhere.nocom>
    Re: Equivalent of ls -d <1usa@llenroc.ude.invalid>
    Re: Equivalent of ls -d xhoster@gmail.com
    Re: Equivalent of ls -d <Juha.Laiho@iki.fi>
    Re: Equivalent of ls -d <bxb7668@somewhere.nocom>
    Re: More help requested on permutation code. (Anno Siegel)
    Re: Parallel LWP callback doesn't terminate. xhoster@gmail.com
    Re: Security implications of taking a stylesheet URL fr <seppi@seppig.de>
    Re: Security implications of taking a stylesheet URL fr <gifford@umich.edu>
    Re: XML::Simple and utf8 woes <corff@zedat.fu-berlin.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 24 Mar 2006 19:19:32 +0100
From: "Ferry Bolhar" <bol@adv.magwien.gv.at>
Subject: Accesing lexical vars from XSUB
Message-Id: <1143224377.91276@proxy.dienste.wien.at>

Hi,

still playing around with XSUBs, I use get_sv() to obtain the content of a
global variable:

In test.pl

$a = "Test";

In test.xs (partially):

SV* my_sv;
my_sv = get_sv("a",FALSE);
if (!my_sv) croak("'a' does not exist!");
printf(form("a = %_\n",my_sv));

Works as expected.

However, when inserting a "my" before the $a in test.pl, the XSUB croaks.
Seems that get_sv can't acces lexical variables.
So just for couriosity: is there a way to access the lexical variable $a?
Or, generally
spoken, how to access the contents of a scatch pad from a XSUB?

Thanks for your answer, and kind greetings from Vienna,

Ferry

-- 
Ing. Ferry Bolhar
Municipality of Vienna, Department 14
A-1010 Vienna / AUSTRIA
E-mail: bol@adv.magwien.gv.at




------------------------------

Date: Fri, 24 Mar 2006 15:06:33 +0100
From: Martin Kissner <news@chaos-net.de>
Subject: Re: Calculations with ',' as decimal delimiter
Message-Id: <slrne27v79.2ol.news@maki.homeunix.net>

Anno Siegel wrote :
> Martin Kissner  <news@chaos-net.de> wrote in comp.lang.perl.misc:

>> One more question:
>> I changed 
>> 	$value =~ s/,/./
>> 	# calculation 
>> 	$value =~ s/\./,/ 
>> top
>> 	$value =~ tr/,/./ 
>> 	# calculation 
>> 	$value =~ tr/./,/ 
>> 
>> Am I right that the second is more efficient?
>
> In theory, yes.  It won't make a difference in practice.  I'd still
> use tr/// because it's the simplest tool that does the job.

Okay, Thank you.

Best regards
Martin 

-- 
perl -e '$S=[[73,116,114,115,31,96],[108,109,114,102,99,112],
[29,77,98,111,105,29],[100,93,95,103,97,110]];
for(0..3){for$s(0..5){print(chr($S->[$_]->[$s]+$_+1))}}'


------------------------------

Date: Fri, 24 Mar 2006 17:31:59 +0000
From: Adam Funk <a24061@yahoo.com>
Subject: Re: Code review request.
Message-Id: <f1ndf3-4j4.ln1@news.ducksburg.com>

On 2006-03-24, Tad McClellan <tadmc@augustmail.com> wrote:
> Adam Funk <a24061@yahoo.com> wrote:
>> On 2006-03-23, Tad McClellan <tadmc@augustmail.com> wrote:
>>> Adam Funk <a24061@yahoo.com> wrote:
>>>> On 2006-03-23, Dave Weaver <zen13097@zen.co.uk> wrote:
>>>> 
>>>>> With modern perls "use warnings" is better than -w
>>>> 
>>>> I didn't know that -- what's the difference?
>>>
>>> The first sentence of the description in:
>>>    perldoc warnings
>>> tells the difference.
>> 
>> --> The "warnings" pragma is a replacement for the command line
>> --> flag "-w", but the pragma is limited to the enclosing block,
>> --> while the flag is global. See perllexwarn for more
>> --> information.
>> 
>> At first, I thought that meant that putting "use warnings" at the
>> beginning (more or less right after "#!/usr/bin/perl") of a
>> free-standing Perl program would have the same effect as putting "-w"
>> on the first line, but on reflection I think that "use warnings"
>> wouldn't percolate down into module code used by the main program --
>> is that correct?
>
>
> Yes, that is correct.

Thanks.  You've sold me on the idea and I'll switch to "use warnings".


------------------------------

Date: Fri, 24 Mar 2006 20:34:49 +0200
From: "Veli-Pekka Tätilä" <vtatila@mail.student.oulu.fi>
Subject: Re: Debugging with Speech: Issues and Work-arounds?
Message-Id: <e01e4j$gm2$1@news.oulu.fi>

Ilya Zakharevich wrote:
>> main::(taskman.plx:4):  focusToRunning();
>>   DB<1>
> ...
>> So the above prompt would be read in its entirety with the package,
>> script and line number pre-pended before the code , which I usually
>> consider the most important. While the file and package info is great
>> initially, it is mostly redundant after the first reading,
> ... unless it changes.
That is true, that's why I said mostly redundant. I guess I should write a 
filter which only shows such things when the previous output is not equal to 
the current one.

> The debugger prompt DB is slightly redundant, too
> ... unless you debug a program which shows its own prompt...
Umm yes, silly me. Well at least I'd still like to kill the command number 
and angle brackets in it as I don't need them and they are read unless one 
stops the speech.

>> However, the code must be cursored through in textual units like lines or
>> words. Without the find command or good markers, you would also have to
>> find the right line by listening to the beginning of the numbers until
>> they match the one you are looking for.
> Not clear: who is "without the find command or good markers"?
A big lot of screen reader users. Most primitive console readers lack these 
features I think. MAny GUi readers include the find command but it is a bit 
impractical to use and doesn't support regular expressions or even 
meta-characters for line breaks. I think some of the more advanced readers 
such as Jaws for WIndows do have the markers for quikc and direct focus 
changes. AS far as I know, my reader and magnifier of choice, Dolphin 
Supernova, however, does not have this feature.

> What is the problem with using DB's "/"?
That command works fine. My point was that it is stil not very straight 
forward to browse through lines of code with the debugger if you happen to 
be using a GUI reader. But as I said the code listing is not really any of 
the big issues, as I can browse the code in my text editor. Totally without 
the line numbers and more freely than using screen reader specific virtual 
focus.

>> This is true of simple console readers or the
>> kind of GUI readers in which the console is just another app. Even when
>> you do find the line,
>> you cannot easily skip the numbers in the
>> beginning of lines or move the focus between the debugger output and the
>> code listing, without some heavy marker trickery. Here I can see two
>> underlying design considerations. Firstly, the screen reader sees only a
>> single very small bit of the screen at a time which is commonly called
>> the straw analogy (you can also think of it as a tiny viewport). The
>> second is that unless you know hotkeys or the app in advance, most
>> keyboard navigation is essentially sequential and text can only be
>> navigated mechanically in simple
>> units.
> I do not understand what is your point here...
Well this is more to do with GUI apps, I think, but there are some lessons 
that are relevant here. FIrst off, as I said you cannot train screen readers 
in detail to read the information out of order so the problem  must be fixed 
in the debugger end. Secondly, the sighted can randomly access any part of 
the screen or browse through code quickly and selectively. This is next to 
impossible with a screen reader. Most movement when using the virtual focus 
or a text editor is essentially sequential and apart from matching text, 
you'll have to repetitively use commands like next line, word or char to 
control the reading process. THough the reader tracks the cursor, its 
reading is linear, left to right and you cannot easily skip anything in the 
stream. Lastly, my account might be even too detailed for the scope of the 
post, simply because I'm naturally interested in accessibility. My bad I 
guess, <grin>.

> I think a short summary of the problems as you see them would make
> things much more grokable.
It is remarkably difficult unless you've used a screen reader before. A 
concrete demo would be nice, but as I canot do it live, here are the 
relevant screen reader prompts. I only use a handful of the screen reader 
commands, as most of them are hard to recall or slow to lookup, so this 
might not be the most efficient way. This intro is a lean subset of 
Supernova usage relevant to consoel applications alone.

Here's some simple sample code for the debugging:

# Redundant sample code.
use strict; use warnings;
my @nums = 1..100;
my @mapped = map {2 * $_} @nums;
for my $num (@mapped)
{
   print "$num\n";
} # for

Firstly, the screen reader normally tracks the cursor for focus changes and 
only reads new information when you hit enter. So, say I'll start 
single-stepping on line one. I would get the following output automatically 
on hitting enter.

main colon <beep indicating repetition> <pause> left paren demo dot plx 
colon four right paren colon my at mapped equals map left brace two star 
dollar underline right brace at nums semicolon <pause> D B less than one 
greater than.

Notice that case differences are gone, the screen reader cannot structure 
the output meaningfully, you have no idea of white space and the whole 
package prompt is read before the relevant code itself. The only way to 
interact with this output is to mute it.

Say I missed what's exactly inside the map block. I cannot take advantage of 
SUpernova's cursor tracking for reading, simply because the cursor canot 
reach the source code. In stead, I'll have to use a screne reader specific 
navigation mode, called virtual focus, to get the screne reader's focus near 
the code.

So I hit f4 to initiate virtual focus:

[f4] virtual focus c colon back slash windows back slash <snip> maximize 
button close button title bar

Oh, this is the title bar. Now I'd need to move the virtual focus to where I 
was. I don't know how to route it to where the physical cursor is, so the 
two choices I have are finding and cursoring around. The find command isn't 
too practical. Typing in [f4, ctrl+f3, map, <enter>] does get the virtual 
focus in the right line but rather than the current word it reads the whole 
line.  To find out what's going on I'll need to cursor right along the line 
in units of words, which causses the word on the left side of the cursor to 
be read.

The alternative is to just cursor around the screen. To find the line using 
this latter method, is about hitting the down arrow many times:

[down] loading # aha not this one so.
[down] editor # nah
[holding down] bottom
[up] db less than one greater than console # here's the cursor but the code.
[up] main colon # this is it but it is going to read the whole line so.
[ctrl+right] main colon # this is the first word so the next one .
[ctrl+right] my
[ctrl+right] at mapped
[right] equals
[right] map left brace  two # this is it, the expression.

So this is what I ment when I said that only a bit of the screen can be seen 
at a time. The practical effects are quite devastating compared to even a 
dumb terminal. A sighted user could simply glance at the code. I'll have to 
put in some effort to find the line in the first place. Further more, though 
the find looks briefer, I don't use it as much as I should because it is 
limited and lctrl+f3, enter is a lot slower to hit than just f3 in a text 
editor. The text editor is a good tool if the doc is long and besides the 
editor commands are not tied to a particular screen reader.

The cursoring method is not all that slow, as you can hold down the arrows 
and only listen to the very beginning of lines to know that they aren't the 
one you'd like to find. Even if I knew it would be the 20th lien, though, I 
could not directly move to it with a goto or repeated down command like you 
can in a good text editor. Most screen readers don't implement power-user 
commands like this, and the concept of virtual focus is screen reader 
specific. Fortunately virtual focus remembres your previous position in the 
window so you don't always have to cursor around that many lines to find the 
desired one. I guess this example serves to illustrate how prompts can be on 
the way, if you'd just like to get the important bits read automatically on 
an enter press.

Next, suppose I'd liek to examine the 0..9 slice of the @mapped array to see 
what numbers went in there. As I already know the index range, I'd rather 
not be told them at all or would want indeces printed only when ($index % 
$n) == 0.

Here's how the slice is read when you hit enter, though:

zero one two four three six four eight five ten <snip> twenty db less than 
nine greater than.

Here you see the linear left-to-right reading order in action. The column 
mode is a GUI-only thing for Supernova, so it reads all indeces and their 
values interlieved in a very difficult fashion. The last value and the db 
prompt are run together, too.

Again a sighted person could just decide he or she doesn't want to see the 
indeces, only the data, but this is not trivial with a screen reader. 
Entering virtual focus:

[f4] virtual focus <pause> db less than 8 greater than x at mapped # Aha 
this is the last debugger line.
[down] 0  2 # first row.
1  4 # second row.
etc...

is manigible but it is still difficult to omit the indeces. I reckon a 
sighted person could decide not to pay attention to the left-most column at 
all. You could swap the columns in the debugger output, though, to make the 
index available but optional. However, this format would be suboptimal if 
you do want to find out the indeces right away.

I've just realized that Perl already has nice devices for presenting the 
data in the desired format. I've only used debugger's for statically typed 
languages so the ability to execute any statement on the fly didn't occur to 
me.

A nicer representation of the array could be gotten with:

p join(', ', @mapped[0..9])

If one turns off punctuation, the commas are translated to pauses. Similarly 
if the indeces are desired, the folowing statements could be run

my $i = 0
for(@mapped[0..9]) { print("$i\t$_\n"), $i++ }

Yet another thing that sighted can do but which is hard with a screen reader 
is filtering columns by common characteristics. But again finding say every 
item ending with 0 is pretty easy if you grep a little:

print "$_ " for( grep{ /0$/ } @mapped)

Sadly these kind of power-user reformatting features aren't available in any 
screen reader I've seen. Perl can help only as long as it can print the 
data. As far as filtering goes, it would be real nice to get the same effect 
for the listed source lines. So that you could use a regexp search to home 
in on the map expression, in the example I had earlier. But anyway, as far 
as convenient printing of the data structures goes, seems Perl shines here 
as it is interpreted.

lastly, one situation in which markers to which you can route the virtual 
focus would be highly useful are in comparing distant lines. If there are 
many lines between the two to be compared, you'll always have to re-find the 
line or cursor over the lines in between to be able to do comparisons of any 
kind. As Supernova doesn't support markers for these transitions, the 
easiest option I've discoverd is to copy the bits to be cmpared in different 
buffers in the text editor. Each buffer recalls its cursor position so 
switching between the lines is just a matter of pressing ctrl+tab.

>> The second option that occurred to me was to customize the debugger.
> would hope that most of the functionality you complain about is 
> concentrated in about 3
> lines of Perl - the debugger is not particularly smart...
Yes, I think so, too, and that's why I considered undertaking such a 
challenge. I'd need to implement redundancy filtering but a general solution 
is pretty easy.

> improved" one; the only solution I know is to disregard all the
>  comments, and read the code itself.]
Oh well, I'll try.

Hope this gives you a clearer picture.

--
With kind regards Veli-Pekka Tätilä (vtatila@mail.student.oulu.fi)
Accessibility, game music, synthesizers and programming:
http://www.student.oulu.fi/~vtatila/ 




------------------------------

Date: Fri, 24 Mar 2006 16:42:01 GMT
From: "Another Brian" <bxb7668@somewhere.nocom>
Subject: Equivalent of ls -d
Message-Id: <Iwn521.GKM@news.boeing.com>

I'm trying to get a list of the files and directories. I was using:
my @FILES = `ls -ld $INPUT`;

Where the value being passed into $INPUT includes a wild card that 
identifies lots of files and directories. I am getting this error:
ksh: /acct/v/vobadm/bin/stattest.pl: 0403-027 The parameter list is 
too long.

I do not want to descend into subdirectories. I tried using readdir 
but if $INPUT contains a wild card, it lists the files in the 
subdirectories.

Is there a Perl equivalent of "ls -d $INPUT"?

Thank you,
Brian 




------------------------------

Date: Fri, 24 Mar 2006 17:14:49 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Equivalent of ls -d
Message-Id: <Xns97907CB397C74asu1cornelledu@127.0.0.1>

"Another Brian" <bxb7668@somewhere.nocom> wrote in 
news:Iwn521.GKM@news.boeing.com:

> I'm trying to get a list of the files and directories. I was using:
> my @FILES = `ls -ld $INPUT`;
> 
> Where the value being passed into $INPUT includes a wild card that 
> identifies lots of files and directories. I am getting this error:
> ksh: /acct/v/vobadm/bin/stattest.pl: 0403-027 The parameter list is 
> too long.
> 
> I do not want to descend into subdirectories. I tried using readdir 
> but if $INPUT contains a wild card, it lists the files in the 
> subdirectories.

Huh?

Could you please share with us the code that does that?

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



------------------------------

Date: 24 Mar 2006 17:16:34 GMT
From: xhoster@gmail.com
Subject: Re: Equivalent of ls -d
Message-Id: <20060324122449.376$cU@newsreader.com>

"Another Brian" <bxb7668@somewhere.nocom> wrote:
> I'm trying to get a list of the files and directories. I was using:
> my @FILES = `ls -ld $INPUT`;
>
> Where the value being passed into $INPUT includes a wild card that
> identifies lots of files and directories. I am getting this error:
> ksh: /acct/v/vobadm/bin/stattest.pl: 0403-027 The parameter list is
> too long.

Yep, that is a shell limitation.

> I do not want to descend into subdirectories. I tried using readdir
> but if $INPUT contains a wild card, it lists the files in the
> subdirectories.

I find that hard to believe.  Can you demonstrate this?

>
> Is there a Perl equivalent of "ls -d $INPUT"?

On a modern perl, its standard glob can deal with much larger file lists
than the shell can.  It naturally does the equivalent ls's -d.  To simulate
ls's -l you would need to stat each file coming out of glob.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


------------------------------

Date: Fri, 24 Mar 2006 18:20:10 +0000 (UTC)
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: Equivalent of ls -d
Message-Id: <e01d8q$7ad$1@ichaos2.ichaos-int>

"Another Brian" <bxb7668@somewhere.nocom> said:
>I'm trying to get a list of the files and directories. I was using:
>my @FILES = `ls -ld $INPUT`;
 ...
>I do not want to descend into subdirectories. I tried using readdir 
>but if $INPUT contains a wild card, it lists the files in the 
>subdirectories.

You can check the entries returned from readdir -- see
perldoc -f -X

 ... f.ex.

$ent = readdir( DIR );
if (-f $ent) {
	// do something for plain files
}

-- 
Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
         PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)


------------------------------

Date: Fri, 24 Mar 2006 18:25:17 GMT
From: "Another Brian" <bxb7668@somewhere.nocom>
Subject: Re: Equivalent of ls -d
Message-Id: <Iwn9u2.MnC@news.boeing.com>

<xhoster@gmail.com> wrote in message 
news:20060324122449.376$cU@newsreader.com...
> "Another Brian" <bxb7668@somewhere.nocom> wrote:
>> I'm trying to get a list of the files and directories. I was using:
>> my @FILES = `ls -ld $INPUT`;
>>
>> Where the value being passed into $INPUT includes a wild card that
>> identifies lots of files and directories. I am getting this error:
>> ksh: /acct/v/vobadm/bin/stattest.pl: 0403-027 The parameter list is
>> too long.
>
> Yep, that is a shell limitation.
>
>> I do not want to descend into subdirectories. I tried using readdir
>> but if $INPUT contains a wild card, it lists the files in the
>> subdirectories.
>
> I find that hard to believe.  Can you demonstrate this?
>
Unfortunately I've deleted the test code and haven't been able to 
quickly recreate it.
>>
>> Is there a Perl equivalent of "ls -d $INPUT"?
>
> On a modern perl, its standard glob can deal with much larger file 
> lists
> than the shell can.  It naturally does the equivalent ls's -d.  To 
> simulate
> ls's -l you would need to stat each file coming out of glob.
>
GLOB!  That's the command. I was just too brain dead to remember it. 
Thank you.  It works great!

Brian. 




------------------------------

Date: 24 Mar 2006 15:12:41 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: More help requested on permutation code.
Message-Id: <48igj9Fkdg2tU1@news.dfncis.de>

Michael Press  <jack@abc.net> wrote in comp.lang.perl.misc:
> Thank you all for the help. Would you guys look at 
> the rest of the code? First a disclaimer.
> The sort assumes numerical permutation elements. 
> This is a limitation I can rectify. 
> 
> ________________CUT________________
> #! /usr/bin/perl 
> 
> use warnings;
> use strict;
> 
> # Multiply permutation cycles, into a permutation map;
> # then turn the map into a cycle representation, and print. 
> # Knuth ACP 1.3.3 Algorithm B. 
> 
> sub permutation_multiply 
> {
>     my $t;
>     my $hold;
>     my $prev;
> 
>     #  Read in the cycles, and initialize the permutation array. 
>     my %permutation_map = map { /\w/ ? ( $_ => $_ ) : () } my
> @token_list = $_[0] =~ /\w+|[()]/g;
> 
>     #  Multiply the cycles generating the permutation as a map. 
>     for (my $idx = $#token_list; $idx >= 0; --$idx)
>     {
>         my $it  = $token_list[$idx];
>         if    ($it eq ')' ) { $prev = $it }
>         elsif ($it  eq '(' ) { $permutation_map{$hold} = $prev }
>         else
>         {
>             if ( $prev eq ')' ) { $hold = $it }
>             $t = $prev, $prev = $permutation_map{$it},
> $permutation_map{$it} = $t;
>         }
>     }
> 
>     #  Generate the cycle representation from the permutation in
> %permutation_map
>     my @cycles;
>     for my $key (sort { $a <=> $b } keys %permutation_map)
>     {
>         my @element_list;
>         next if $permutation_map{$key} =~ m/-$/ ;
>         do
>         {
>             push @element_list,  $key;
>             $t = $permutation_map{$key};
>             $permutation_map{$key} .= '-';
>             $key = $t;
>         } while ($permutation_map{$key} !~ m/-$/ );
>         push @cycles, [@element_list];
>     }
>     for my $key (keys %permutation_map) {$permutation_map{$key} =~ tr/-//d }
> 
>     #  Print out the cycles:
>     #   Sort the cycles by length.
>     #   Put spaces between permutation elements.
>     #   Put in cycle delimiter parentheses.
>     #   Put spaces between permutation cycles.
>     #   Print.
>     print join(' ',  map { sprintf "(%s)", join ' ', @{$_}} sort {$#{$a}
> <=> $#{$b}} @cycles ), "\n";
> }
> 
> my $alpha = "(99)(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22)";
> my $beta =  "(99)(0)(3 6 12 1 2 4 8 16 9 18 13)(15 7 14 5 10 20 17 11 22
> 21 19)";
> my $gamma = "(99 0)(1 22)(2 11)(3 15)(4 17)(5 9)(6 19)(7 13)(8 20)(10
> 16)(12 21)(14 18)";
> my $delta = "(99)(0)(3)(15)(1 18 4 2 6)(5 21 20 10 7)(8 16 13 9 12)(11
> 19 22 14 17)";
> my $x;

What are all the single-element cycles for?  They map to the unit
permutation and have no effect.

> print "beta =  alpha^5 gamma alpha^5 gamma alpha^14 gamma alpha^18 \n";
> $x = ($alpha x 5 . $gamma) x 2 . $alpha x 14 . $gamma . $alpha x 18;
> permutation_multiply $x;
> $x = $beta;
> permutation_multiply $x;
> print "\n";
> 
> print "(alpha^13 gamma delta^2)^3 has shape 4^6\n";
> $x = (($alpha x 13) . $gamma . ($delta x 2)) x 3;
> permutation_multiply $x;
> print "\n";
> 
> ________________END________________

One of my projects in the almost-done limbo is a permutation class.  It
overloads permutation objects so that multiplication (x) and exponentiation
(**) can be applied directly.  I had an hour of fun adapting it to the
problem at hand.  The adaption is mainly in the stringification of
permutations and in the addition of a special creator (new_from_cyc_str)
to deal with the given formats.

The code (incompletely tested) is appended below.  The printed results
are equivalent to those of the original code.

Anno


#!/usr/bin/perl
use strict; use warnings; $| = 1;

my $alpha = Permutation->new_from_cyc_str(
    "(99)(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22)"
);

my $beta =  Permutation->new_from_cyc_str(
     "(99)(0)(3 6 12 1 2 4 8 16 9 18 13)(15 7 14 5 10 20 17 11 22 21 19)"
);

my $gamma = Permutation->new_from_cyc_str(
    "(99 0)(1 22)(2 11)(3 15)(4 17)(5 9)(6 19)(7 13)(8 20)" . 
    "(10 16)(12 21)(14 18)"
);

my $delta = Permutation->new_from_cyc_str(
    "(99)(0)(3)(15)(1 18 4 2 6)(5 21 20 10 7)(8 16 13 9 12)(11 19 22 14 17)"
);

my $x = ($alpha**5 x $gamma)**2 x $alpha**14 x $gamma x $alpha ** 18;

print "beta =  alpha^5 gamma alpha^5 gamma alpha^14 gamma alpha^18\n";
print "$x\n";
print "$beta\n";

print "\n";
print "(alpha^13 gamma delta^2)^3 has shape 4^6\n";
$x = ($alpha**13 x $gamma x $delta**2)**3;
print "$x\n";

exit;

######################################################################

package Permutation;
use List::Util qw( max);

use overload(
#   '""' => sub { "(@{ shift() })" },
    '""' => 'to_cyc_str',
    bool => sub { @{ $_[ 0]} > 1 },
    x    => 'multiply',
    '/'  => 'divide',
    '**' => 'power',
);

sub new {
    my $class = shift;
    push @_, 0 unless @_;
    defined $_[ $_] or $_[ $_] = $_ for 0 .. $#_;
    pop while @_ > 1 and $_[ -1] == $#_;
    bless [ @_], $class;
}

sub new_from_cycle {
    my $class = shift;
    my @p;
    my @q = @_;
    push @q, shift @q;
    @p[ @_] = @q;
    $class->new( @p);
}

sub new_from_cyc_str {
    my ( $class, $str) = @_;
    my $p = $class->new();
    for ( $str =~ /\(([\d ]*)\)/g ) {
        $p = $p->multiply( Permutation->new_from_cycle( split));
    }
    $p;
}

sub new_random {
    my ( $class, $n) = @_;
    my @perm = 0 .. $n - 1;
    for ( reverse 0 .. $n - 1 ) {
        my $pick = rand $_;
        @perm[ -1, $pick] = @perm[ $pick, -1];
    }
    $class->new( @perm);
}

sub multiply {
    my ( $p1, $p2) = @_;
    ref( $p1)->new( (@$p2, @$p2 .. max( @$p1))[ @$p1, @$p1 .. $#$p2]);
}

sub invert {
    my $p = shift;
    my @inv;
    @inv[ @$p] = 0 .. $#$p;
    ref( $p)->new( @inv);
}

sub divide { $_[ 0]->multiply( $_[ 1]->invert) }

sub power {
    my ( $p, $n) = @_;
    if ( $n < 0 ) {
        $n = -$n;
        $p = $p->invert;
    }
    my $pow = Permutation->new();
    while ( $n ) {
        $pow = $pow->multiply( $p) if $n & 1;
        $p = $p->multiply( $p);
        $n >>= 1;
    }
    $pow;
}

sub _extract_cycle {
    my $p = shift;
    my ( @seen, @cyc);
    my $i = $#$p;
    until ( defined $seen[ $i] ) {
        $seen[ $i] = 1;
        push @cyc, $i;
        $i = $p->[ $i];
    }
    @cyc;
}

sub to_cycles {
    my $p = shift;
    my @cycles;
    while ( $p ) {
        my @cyc = $p->_extract_cycle;
        $p = $p->multiply( Permutation->new_from_cycle( @cyc)->invert);
        push @cycles, \ @cyc;
    }
    sort { @$a <=> @$b } @cycles;
}

sub to_cyc_str {
    my $p = shift;
    join ' ', map "[@$_]", $p->to_cycles;
}
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


------------------------------

Date: 24 Mar 2006 17:01:56 GMT
From: xhoster@gmail.com
Subject: Re: Parallel LWP callback doesn't terminate.
Message-Id: <20060324121011.116$GW@newsreader.com>

"Peter Hill" <peter.hill@modulus.com.au> wrote:
> <xhoster@gmail.com> wrote in message
> news:<20060323110859.954$zU@newsreader.com>...
> > "Peter Hill" <peter.hill@modulus.com.au> wrote:
> [snip]
> > >   print "We never get here.\n";
> > >   return C_ENDCON;
> > > }
> > >
> >
> > As far as I can tell, the only error you are committing is in your
> > expectations, not in your code.  The only way "We never get here"
> > should be printed is if you either get called with empty content (and
> > why would that happen?  If there is nothing to send to the callback,
> > why call it?), or with an over-sized chunk.  Otherwise, the
> > "return length $content;" will be activated, by-passing the print.
> >

> Yes, thank you, that makes perfect sense. I was basing the callback
> function on an article be Randal Shwartz ("Parallel Bad Links") but I can
> now see that that doesn't work either; something must have changed since
> the article was written.

Yep, I see that it did used to call the callback one final time with
zero content length, but it no longer does.  The changes seems to have
happened in 2.54_19, in LWP/Parallel/Protocol/http.pm, with this line:

if ( $response && &headers($response) && length($buf)) {

The "&& length($buf)" didn't used to be there.  It says is a bug fix, but
now I'm starting to think it was more of a bug-introduction :)

> It appears that I need to do my analysis on each
> chunk as it is returned rather than expecting to deal with a complete
> document.

I believe you would now override the on_return in order to process the
"complete" document, but you could still use the callback to mark the
document as "complete" after maxsize is reached, even if it isn't truly
complete. (There is supposed to be max_size attribute which will
automatically cap the size without needing to use callbacks at all, but
there doesn't seem to be any supported way to set this attribute!)

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


------------------------------

Date: Fri, 24 Mar 2006 16:19:53 +0100
From: Sebastian Gottschalk <seppi@seppig.de>
Subject: Re: Security implications of taking a stylesheet URL from a CGI  parameter
Message-Id: <48ih1aFkc5g7U2@news.dfncis.de>

Scott W Gifford wrote:

> Any other risks I may not have considered?

What about the stylesheets themselves?

a {content-before:@url(somesites.com/mycontent.blah)}

with the content being any html you'd like to see, including JavaScript?


------------------------------

Date: Fri, 24 Mar 2006 11:44:31 -0500
From: Scott W Gifford <gifford@umich.edu>
Subject: Re: Security implications of taking a stylesheet URL from a CGI parameter
Message-Id: <qszd5gbdc7k.fsf@arkanoid.gpcc.itd.umich.edu>

Hi Volker,

Thanks for your thoughts.  A few quick responses...

Volker Birk <bumens@dingens.org> writes:

> In comp.security.misc Scott W Gifford <gifford@umich.edu> wrote:
>> We will escape $stylesheet so it can only contain letters, numbers,
>> underscore, dash, slashes, colons, and dots (to avoid cross-site
>> scripting), ensure it starts with "http://" or "https://" and contains
>> no port specification after the host
>
> The latter is a drawback.

The goal is to limit the possibility of doing something like:

    http://10.0.0.5:445/

to cause the client machine to connect to a fileserver in their
internal network.  It certainly is a limitation, but I suspect it will
be an acceptable one to our users.

>> and
>> require the filename to end with ".css" (to make it more difficult to
>> cause a script to run).
>
> This is unneccessary.

The goal here is to reduce the possibility of doing something like:

    http://www.somesite.com/runsomething.cgi

to cause the client machine to execute a script somewhere.  Requiring
a .css extension is in by no means foolproof, but executable content
with a .css extension is uncommon, so I suspect this will help
mitigate risk.

>
>> Something like this:
>>     /^https?:\/\/[\w.-]+\/[\w\/:.-]+\.css$/
>
> Why not implementing RFC1738, 3.3 exactly?

I explicity don't want to allow some of the reserved characters
mentioned in section 2.2 of that RFC, to make it impossible to send
queries.  Like the above restriction, I expect this to reduce the risk
of running executable content.

>> I only have a rough knowledge of the full power of cascading
>> stylesheets.  Are there any other security concerns I should be
>> thinking about? 
>
> With :before and :after there may be risks by inserting local scripting
> code.

Thanks, that's exactly the sort of risk I was hoping to find out
about!

----Scott.


------------------------------

Date: 24 Mar 2006 16:09:49 GMT
From: <corff@zedat.fu-berlin.de>
Subject: Re: XML::Simple and utf8 woes
Message-Id: <48ijudFjr9i8U1@uni-berlin.de>

Chronos Tachyon <chronos@chronos-tachyon.net> wrote:

: The problem seems to be the absence of a "use utf8;" pragma.  Perl is
: assuming that your code (including the __DATA__ section) is in ISO-8859-1.

No, I don't think so, as inserting the utf8 pragma doesn't change anything.
I tried it, and the output is still not in utf8.

: [Addendum:  FWIW, your newsreader is also making the same assumption.]

That is a different story, on a different machine. My production code
runs in a true utf8 environment, this one here is only used for communi-
cations. Thank you for the hint, nonetheless!

Oliver.

-- 
Dr. Oliver Corff              e-mail:    corff@zedat.fu-berlin.de


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 9085
***************************************


home help back first fref pref prev next nref lref last post