[24466] in Perl-Users-Digest
Perl-Users Digest, Issue: 6649 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 3 21:05:53 2004
Date: Thu, 3 Jun 2004 18:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 3 Jun 2004 Volume: 10 Number: 6649
Today's topics:
Deciphering a very cryptic perl "one-liner" <see.post.for.real.address@pacbell.net>
Re: Deciphering a very cryptic perl "one-liner" <usenet@morrow.me.uk>
Re: Escaping single quotes with sql <dwall@fastmail.fm>
Re: Escaping single quotes with sql <tadmc@augustmail.com>
Re: Escaping single quotes with sql <dwall@fastmail.fm>
Re: how can a Perl script for Win32 tell if it's runnin (Bennett Haselton)
Re: how can a Perl script for Win32 tell if it's runnin <dwall@fastmail.fm>
Re: HTML::Summary problem (Lee)
Re: Images on fly using IIS (laszlo)
Re: Images on fly using IIS <usenet@morrow.me.uk>
Re: Invisible Array Loop Counter? (Kevin Collins)
Kill a system process within the script (Mav)
Re: Kill a system process within the script <nospam@bigpond.com>
Re: my @hash{ @array } = syntax? (was Re: Joining 2 arr (Anno Siegel)
Re: my @hash{ @array } = syntax? (was Re: Joining 2 arr <bmb@ginger.libs.uga.edu>
Re: my @hash{ @array } = syntax? (was Re: Joining 2 arr <usenet@morrow.me.uk>
Re: regexp <postmaster@castleamber.com>
Re: regexp ctcgag@hotmail.com
Re: regexp <dwall@fastmail.fm>
Re: regexp <dwall@fastmail.fm>
Re: Setuid problems with perl 5.8.4? (David Efflandt)
Re: Setuid problems with perl 5.8.4? <usenet@morrow.me.uk>
Re: Why is this upload script not working <noreply@gunnar.cc>
Re: Win32::OLE, WMI and executing methods (Daniel Berger)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 03 Jun 2004 23:42:05 GMT
From: "Robert Miller" <see.post.for.real.address@pacbell.net>
Subject: Deciphering a very cryptic perl "one-liner"
Message-Id: <hHOvc.78683$rP2.9172@newssvr25.news.prodigy.com>
Hello All,
Below is 8-lines of pure perl gibberish (a "one-liner") that computes the
SHA1 hash of its stdin. It's not mine, it's the work of John Allen. Just
Google his name and SHA1 if you want to know more about author.
It seems to work fine. My question is *how* it works. Most of the script is
fairly easy to follow: beginning on line 2 there are some arrays defined and
some procedures declared. There's a big DO loop from line 4-8 that reads all
the data from STDIN and processes it. The resulting hash is printed on line
8.
What I can't make heads or tails of is line 1 (the shebang). It seems to be
invoking the perl interpreter with the -i flag (edit in place). This makes
no sense though because the script isn't operating on a named file nor is
the flag followed by an file extension to be used for a backup. The flag
appears to be followed by random characters instead. It suprises me that
line 1 doesn't cause a syntax error, but apparently it's valid perl code.
What gives??? Can anyone explain or parse the first line of this script?
Thanks to any and all, -RM.
=================
#!/usr/bin/perl -iD9T4C`>_-JXF8NMS^$#)4=L/2X?!:@GF9;MGKH8\;O-S*8L'6
@A=unpack"N*",unpack u,$^I;@K=splice@A,5,4;sub
M{($x=pop)-($m=1+~0)*int$x/$m};
sub
L{$n=pop;($x=pop)<<$n|2**$n-1&$x>>32-$n}@F=(sub{$b&($c^$d)^$d},$S=sub{$b^$c
^$d},sub{($b|$c)&$d|$b&$c},$S);do{$l+=$r=read
STDIN,$_,64;$r++,$_.="\x80"if$r<
64&&!$p++;@W=unpack N16,$_."\0"x7;$W[15]=$l*8
if$r<57;for(16..79){push@W,L$W[$_
-3]^$W[$_-8]^$W[$_-14]^$W[$_-16],1}($a,$b,$c,$d,$e)=@A;for(0..79){$t=M&{$F[$
_/
20]}+$e+$W[$_]+$K[$_/20]+L$a,5;$e=$d;$d=$c;$c=L$b,30;$b=$a;$a=$t}$v='a';@A=m
ap{
M$_+${$v++}}@A}while$r>56;printf'%.8x'x5 ."\n",@A
===================
--
Robert Miller
San Jose, CA, USA
rwm415/pacbell/net
------------------------------
Date: Fri, 4 Jun 2004 00:09:20 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Deciphering a very cryptic perl "one-liner"
Message-Id: <c9oejg$fa4$1@wisteria.csv.warwick.ac.uk>
Quoth "Robert Miller" <see.post.for.real.address@pacbell.net>:
>
> Below is 8-lines of pure perl gibberish (a "one-liner") that computes the
> SHA1 hash of its stdin. It's not mine, it's the work of John Allen. Just
> Google his name and SHA1 if you want to know more about author.
>
> It seems to work fine. My question is *how* it works.
>
> What I can't make heads or tails of is line 1 (the shebang). It seems to be
> invoking the perl interpreter with the -i flag (edit in place). This makes
> no sense though ...
<snip>
>
> #!/usr/bin/perl -iD9T4C`>_-JXF8NMS^$#)4=L/2X?!:@GF9;MGKH8\;O-S*8L'6
> @A=unpack"N*",unpack u,$^I;@K=splice@A,5,4;sub
> M{($x=pop)-($m=1+~0)*int$x/$m};
> sub
> L{$n=pop;($x=pop)<<$n|2**$n-1&$x>>32-$n}@F=(sub{$b&($c^$d)^$d},$S=sub{$b^$c
> ^$d},sub{($b|$c)&$d|$b&$c},$S);do{$l+=$r=read
> STDIN,$_,64;$r++,$_.="\x80"if$r<
> 64&&!$p++;@W=unpack N16,$_."\0"x7;$W[15]=$l*8
> if$r<57;for(16..79){push@W,L$W[$_
> -3]^$W[$_-8]^$W[$_-14]^$W[$_-16],1}($a,$b,$c,$d,$e)=@A;for(0..79){$t=M&{$F[$
> _/
^^ linewrap
> 20]}+$e+$W[$_]+$K[$_/20]+L$a,5;$e=$d;$d=$c;$c=L$b,30;$b=$a;$a=$t}$v='a';@A=m
> ap{
^^ linewrap
> M$_+${$v++}}@A}while$r>56;printf'%.8x'x5 ."\n",@A
The tool for this job is B::Deparse, which for this script gives:
BEGIN { $^I = "D9T4C`>_-JXF8NMS^\$#)4=L/2X?!:\@GF9;MGKH8\\;O-S*8L'6"; }
@A = unpack('N*', unpack('u', $^I));
@K = splice(@A, 5, 4);
sub M {
($x = pop @_) - ($m = 4294967296) * int($x / $m);
}
sub L {
$n = pop @_;
($x = pop @_) << $n | 2 ** $n - 1 & $x >> 32 - $n;
}
@F = (sub {
$b & ($c ^ $d) ^ $d;
}
, $S = sub {
$b ^ $c ^ $d;
}
, sub {
($b | $c) & $d | $b & $c;
}
, $S);
do {
$l += $r = read(STDIN, $_, 64);
++$r, $_ .= "\200" if $r < 64 and not $p++;
@W = unpack('N16', $_ . "\000" x 7);
$W[15] = $l * 8 if $r < 57;
foreach $_ (16 .. 79) {
push @W, L($W[$_ - 3] ^ $W[$_ - 8] ^ $W[$_ - 14] ^ $W[$_ - 16], 1);
}
($a, $b, $c, $d, $e) = @A;
foreach $_ (0 .. 79) {
$t = M(&{$F[$_ / 20];} + $e + $W[$_] + $K[$_ / 20] + L($a, 5));
$e = $d;
$d = $c;
$c = L($b, 30);
$b = $a;
$a = $t;
}
$v = 'a';
@A = map({M $_ + ${$v++;};} @A)
} while $r > 56;
printf '%.8x' x 5 . "\n", @A;
So the -i switch has the effect of setting the $^I variable, which is
then used on the second line of the script. A slightly nasty piece of
obfustication, IMHO :).
Ben
--
And if you wanna make sense / Whatcha looking at me for? (Fiona Apple)
* ben@morrow.me.uk *
------------------------------
Date: Thu, 03 Jun 2004 18:27:27 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: Escaping single quotes with sql
Message-Id: <Xns94FD931212327dkwwashere@216.168.3.30>
Ben Morrow <usenet@morrow.me.uk> wrote:
> Quoth "David K. Wall" <dwall@fastmail.fm>:
>> > my $dbh =
>> > DBI->connect("DBI:PgPP:database=honnepon;host=$hostname",
>> > "$user", "$pass", {'RaiseError' => 1});
>>
>> You don't need quotes around $user and $pass. See
>> perldoc -q quoting
>
> Nor around 'RaiseError'.=> autoquotes its left argument if it
> matches /^\w+$/.
Thanks. Somehow I missed seeing that one.
------------------------------
Date: Thu, 3 Jun 2004 17:11:57 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Escaping single quotes with sql
Message-Id: <slrncbv8hd.b9e.tadmc@magna.augustmail.com>
David K. Wall <dwall@fastmail.fm> wrote:
> Wilco van der Veer <ghostie2000@hotmail.com> wrote:
>> use DBI();
>
> DBI doesn't export anything, so the parentheses are unnecessary.
But if the parenthesis are not there, then you have to go find
out if DBI exports anything or not.
With parens you know right away that nothing is being imported
without having to go do any research.
I'd call using those parens the "good kind" of Lazy. :-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 04 Jun 2004 00:45:19 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: Escaping single quotes with sql
Message-Id: <Xns94FDD322CAC01dkwwashere@216.168.3.30>
Tad McClellan <tadmc@augustmail.com> wrote:
> David K. Wall <dwall@fastmail.fm> wrote:
>> Wilco van der Veer <ghostie2000@hotmail.com> wrote:
>>> use DBI();
>> DBI doesn't export anything, so the parentheses are unnecessary.
> But if the parenthesis are not there, then you have to go find
> out if DBI exports anything or not.
>
> With parens you know right away that nothing is being imported
> without having to go do any research.
>
>
> I'd call using those parens the "good kind" of Lazy. :-)
I hadn't looked at it that way. I'll have to keep that in mind for my own
use.
------------------------------
Date: 3 Jun 2004 12:45:04 -0700
From: bennett@peacefire.org (Bennett Haselton)
Subject: Re: how can a Perl script for Win32 tell if it's running as an admin?
Message-Id: <e614455c.0406031145.1f3a2566@posting.google.com>
Jack Challen <jack_challen@ocsl.co.uk> wrote in message news:<tmCvc.1$OG.321@psinet-eu-nl>...
> Bennett Haselton wrote:
> > Is there a way for a Win32 Perl script running under Windows 2K/XP to
> > determine if it's running as an administrator? (Not necessarily *the*
> > administrator account, but any account with local admin privileges.)
>
> Try searching the docs for the Win32 module on CPAN for the string "admin"
>
> cheers
>
> jack
Great minds think alike :) Before posting this mesasge I had already
searched all the local HTML docs for the Win32 module for the string
"admin", but I couldn't find anything, so that's when I asked here.
I went to
http://cpan.uwinnipeg.ca/dist/Win32/
to do a search to see if anything had been created more recently, but
the search bar wouldn't let me search just within that module.
Are you aware of some function in that module that does what I need,
and you were trying to lead me there without spoonfeeding me :) or
were you just giving me a suggestion as the first place to look?
Anybody have ideas for a second place?...
-Bennett
------------------------------
Date: Thu, 03 Jun 2004 20:11:52 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: how can a Perl script for Win32 tell if it's running as an admin?
Message-Id: <Xns94FDA4C5B3FCDdkwwashere@216.168.3.30>
Bennett Haselton <bennett@peacefire.org> wrote:
> Jack Challen <jack_challen@ocsl.co.uk> wrote in message
> news:<tmCvc.1$OG.321@psinet-eu-nl>...
>> Bennett Haselton wrote:
>> > Is there a way for a Win32 Perl script running under Windows
>> > 2K/XP to determine if it's running as an administrator? (Not
>> > necessarily *the* administrator account, but any account with
>> > local admin privileges.)
>>
>> Try searching the docs for the Win32 module on CPAN for the
>> string "admin"
>
> Great minds think alike :) Before posting this mesasge I had
> already searched all the local HTML docs for the Win32 module for
> the string "admin", but I couldn't find anything, so that's when I
> asked here.
Hmm. I searched my local copy of the Win32 docs and found
Win32::IsAdminUser().
I'm using Activestate Perl 5.8.3, build 809.
C:\> perl -MWin32 -e "print $Win32::VERSION"
0.22
> Are you aware of some function in that module that does what I
> need
[snip rest of sentence]
I suspect he was. :-)
------------------------------
Date: 3 Jun 2004 11:46:45 -0700
From: lee@mailinator.com (Lee)
Subject: Re: HTML::Summary problem
Message-Id: <b95662b9.0406031046.263aeb45@posting.google.com>
Well, to answer my own question, changing one line of the demo program
seemed to make it work:
change:
$tree->parse( $filename );
to:
$tree->parse_file($file_name);
and it works.
Lee
------------------------------
Date: 3 Jun 2004 14:07:56 -0700
From: GlgAs@Netscape.net (laszlo)
Subject: Re: Images on fly using IIS
Message-Id: <945e4584.0406031307.43f8b68@posting.google.com>
Ben Morrow <usenet@morrow.me.uk> wrote in message news:<c9lnfk$ceh$2@wisteria.csv.warwick.ac.uk>...
> Quoth GlgAs@Netscape.net (laszlo):
> > A have the following html file:
> >
> > <HTML><HEAD><TITLE=test</HEAD>
> > <BODY><CENTER>
> > <IMG SRC=http://localhost/cgi-bin/wpm/wimaker.pl/test.png>
>
> This needs quoting, as it contains slashes which are special to SGML.
>
The resolution is:
<IMG SRC=http://localhost/cgi-bin/wpm/wimaker.pl>
the program reference may not be followed by additional string. I dont
know why but in this way works neither the quoting nor binmode in the
called program is necessary
One more note for possibile future readers: the $| (autoflush) is
necessary, otherwise the header will follow the image)
thanks for the replay
------------------------------
Date: Thu, 3 Jun 2004 23:44:45 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Images on fly using IIS
Message-Id: <c9od5d$e74$2@wisteria.csv.warwick.ac.uk>
Quoth GlgAs@Netscape.net (laszlo):
> Ben Morrow <usenet@morrow.me.uk> wrote in message news:<c9lnfk$ceh$2@wisteria.csv.warwick.ac.uk>...
> > Quoth GlgAs@Netscape.net (laszlo):
> > > A have the following html file:
> > >
> > > <HTML><HEAD><TITLE=test</HEAD>
> > > <BODY><CENTER>
> > > <IMG SRC=http://localhost/cgi-bin/wpm/wimaker.pl/test.png>
> >
> > This needs quoting, as it contains slashes which are special to SGML.
>
> The resolution is:
>
> <IMG SRC=http://localhost/cgi-bin/wpm/wimaker.pl>
>
> the program reference may not be followed by additional string.
This is then a question of server configuration. It is certainly
possible to configure the server to cause a request for
/cgi-bin/wpm/wimaker.pl/test.png to invoke wimaker.pl passing
'/test.png' as a parameter; your server may not be so configured.
> I dont know why but in this way works neither the quoting nor binmode
> in the called program is necessary
They are *both* necessary. The quoting of the URI has nothing to do with
Perl: it is a question of valid HTML. binmode is *always* necessary on
filehandles that will be fed binary data: if it happens not to have been
what bit you in this case, it will at some point.
Ben
--
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/' # ben@morrow.me.uk
------------------------------
Date: Thu, 03 Jun 2004 23:29:56 GMT
From: spamtotrash@toomuchfiction.com (Kevin Collins)
Subject: Re: Invisible Array Loop Counter?
Message-Id: <slrncbvd3k.hm9.spamtotrash@doom.unix-guy.com>
In article <20040601201845.A18263@dishwasher.cs.rpi.edu>, Paul Lalli wrote:
> On Tue, 2 Jun 2004 ctcgag@hotmail.com wrote:
>
>> It seems that Perl has a special "undef" structure which is shared by all
>> empty array slots (rather than giving each one it's own "real" undef sv*).
>> Of course, the guts of perl must know about this, so that if something is
>> assigned to something pointing to this special structure it knows to break
>> the link, rather than sharing the new value with all other empty array
>> slots. Apparently this confuses Data::Dumper. I would consider it a bug
>> in Data::Dumper.
>
> This would seem to support that analysis:
>
> use strict;
> use warnings;
> use Data::Dumper;
>
> my @arr;
> $#arr = 4;
> print Dumper(\@arr);
> $arr[2] = 'foo';
> print Dumper(\@arr);
>
> __END__
> $VAR1 = [
> undef,
> ${\$VAR1->[0]},
> ${\$VAR1->[0]},
> ${\$VAR1->[0]},
> ${\$VAR1->[0]}
> ];
> $VAR1 = [
> undef,
> ${\$VAR1->[0]},
> 'foo',
> ${\$VAR1->[0]},
> ${\$VAR1->[0]}
> ];
I don't see how that proves it - you simply changed a reference, not what the
reference points to.
However, if you do change it (the undef element), something interesting does
happen:
use strict;
use warnings;
use Data::Dumper;
my @arr;
$#arr = 4;
print Dumper(\@arr);
$arr[0] = 'foo';
print Dumper(\@arr);
$VAR1 = [
undef,
${\$VAR1->[0]},
${\$VAR1->[0]},
${\$VAR1->[0]},
${\$VAR1->[0]}
];
$VAR1 = [
'foo',
undef,
${\$VAR1->[1]},
${\$VAR1->[1]},
${\$VAR1->[1]}
];
Notice that the 1st element ($VAR[1]) that was referencing the undef ($VAR[0])
now becomes undef and the remaining elements shift their references to $VAR[1].
Kevin
------------------------------
Date: 3 Jun 2004 14:57:00 -0700
From: mluvw47@yahoo.com (Mav)
Subject: Kill a system process within the script
Message-Id: <dfaafecd.0406031357.34df09c5@posting.google.com>
Hi, all
I am trying to lanuch a command on my perl script using system call,
I wonder is that a way when someone hit Ctrl-Y, it will kill my
script,and also kill that system call process as well.
My script:
...
@args = ("doing something take a long time");
if (system(@args)==0) {
print "ok";
} else
print "something wrong";
Please help,
Thanks,
M
------------------------------
Date: Fri, 04 Jun 2004 08:33:58 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Kill a system process within the script
Message-Id: <1301375.PJ7eh0oTik@GMT-hosting-and-pickle-farming>
Mav wrote:
> Hi, all
> I am trying to lanuch a command on my perl script using system call,
> I wonder is that a way when someone hit Ctrl-Y, it will kill my
> script,and also kill that system call process as well.
Huh? killing a process takes microseconds.
> My script:
>
> ...
> @args = ("doing something take a long time");
>
> if (system(@args)==0) {
> print "ok";
> } else
> print "something wrong";
>
> Please help,
> Thanks,
> M
Assuming linux/unix:
Try system("kill -SIGTERM $process") ; then
Try system("kill -SIGKILL $process")
where you set $process top the pid you want tokill.
gtoomey
------------------------------
Date: 3 Jun 2004 18:39:48 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: my @hash{ @array } = syntax? (was Re: Joining 2 arrays into hashes)
Message-Id: <c9nr9k$55a$1@mamenchi.zrz.TU-Berlin.DE>
<ctcgag@hotmail.com> wrote in comp.lang.perl.misc:
> Kevin Collins <spamtotrash@toomuchfiction.com> wrote:
> > >
> > > Uhm, I think the {} clearly shows what the intentions are? I mean, I
> > > can do my %array = @array; (And I am happy with that)
> >
> > Yes, but think of it this way: you are defining a *slice* of a hash, not
> > (necessarily) the whole hash. Its the same reason you can't do:
> >
> > my $var[2] = 'val';
> >
> > You can't lexically scope only part of an array or a hash, you have to do
> > the whole thing.
>
> But we aren't asking to lexically scope part of an array or hash, just to
> be able to lexically scope an entire array or hash in the same statement
> that initializes a portion of it. I don't see any fundamental reason it
> wouldn't work, as far as I can tell it doesn't introduce any syntactic
> ambiguity. It would just be a matter of adding a little more DWIM to the
> language.
my() already does some extra gymnastics to get the scope right in
"while ( my $x ... )" and similar. Perl has never suffered from much
concern for the lexer and its difficulties, but the additional stress
could (to coin a phrase) be the straw that breaks the camel's back.
It would also break the parallelism between local() and my() (in addition
to ways it is already broken). "local( @hash{ @list})" already has a
meaning, and it's not to localize %hash as a whole, the way my() would
have to work.
Anno
------------------------------
Date: Thu, 3 Jun 2004 15:34:51 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: my @hash{ @array } = syntax? (was Re: Joining 2 arrays into hashes)
Message-Id: <Pine.A41.4.58.0406031525590.10762@ginger.libs.uga.edu>
On Thu, 3 Jun 2004, Anno Siegel wrote:
> <ctcgag@hotmail.com> wrote in comp.lang.perl.misc:
> > Kevin Collins <spamtotrash@toomuchfiction.com> wrote:
> > > >
> > > > Uhm, I think the {} clearly shows what the intentions are? I mean, I
> > > > can do my %array = @array; (And I am happy with that)
> > >
> > > Yes, but think of it this way: you are defining a *slice* of a hash, not
> > > (necessarily) the whole hash. Its the same reason you can't do:
> > >
> > > my $var[2] = 'val';
> > >
> > > You can't lexically scope only part of an array or a hash, you have to do
> > > the whole thing.
> >
> > But we aren't asking to lexically scope part of an array or hash, just to
> > be able to lexically scope an entire array or hash in the same statement
> > that initializes a portion of it. I don't see any fundamental reason it
> > wouldn't work, as far as I can tell it doesn't introduce any syntactic
> > ambiguity. It would just be a matter of adding a little more DWIM to the
> > language.
>
> my() already does some extra gymnastics to get the scope right in
> "while ( my $x ... )" and similar. Perl has never suffered from much
> concern for the lexer and its difficulties, but the additional stress
> could (to coin a phrase) be the straw that breaks the camel's back.
>
> It would also break the parallelism between local() and my() (in addition
> to ways it is already broken). "local( @hash{ @list})" already has a
> meaning, and it's not to localize %hash as a whole, the way my() would
> have to work.
>
> Anno
>
I think the following thread in P5P is related to this topic, in that it
allows for this:
my $var->[2] = 'val';
which admittedly is slightly different. Whether or not it also allows for
my $var[2] = 'val';
I'm not sure, but it doesn't appear so.
http://groups.google.com/groups?selm=200405211244.31291.tetryl%40tokyoprogrammer.com
Regards,
Brad
------------------------------
Date: Thu, 3 Jun 2004 23:39:22 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: my @hash{ @array } = syntax? (was Re: Joining 2 arrays into hashes)
Message-Id: <c9ocra$e74$1@wisteria.csv.warwick.ac.uk>
Quoth Brad Baxter <bmb@ginger.libs.uga.edu>:
>
> I think the following thread in P5P is related to this topic, in that it
> allows for this:
>
> my $var->[2] = 'val';
>
> which admittedly is slightly different.
Yes... I at least would conceptualize that statement as
(my $var)->[2] = 'val';
which doesn't have the same problem of needing two different values for
the subject of the my.
Ben
--
$.=1;*g=sub{print@_};sub r($$\$){my($w,$x,$y)=@_;for(keys%$x){/main/&&next;*p=$
$x{$_};/(\w)::$/&&(r($w.$1,$x.$_,$y),next);$y eq\$p&&&g("$w$_")}};sub t{for(@_)
{$f&&($_||&g(" "));$f=1;r"","::",$_;$_&&&g(chr(0012))}};t # ben@morrow.me.uk
$J::u::s::t, $a::n::o::t::h::e::r, $P::e::r::l, $h::a::c::k::e::r, $.
------------------------------
Date: Thu, 03 Jun 2004 13:10:12 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: regexp
Message-Id: <40bf6985$0$209$58c7af7e@news.kabelfoon.nl>
Wojtek Michalik wrote:
> On Thu, 03 Jun 2004 17:22:33 +0000, Walter Roberson wrote:
>>I would ask, though, why you are using the g modifier?
>
> Because I am a perl newbie. Don't know much about it.
So that means you just try something without actually reading what it
means? You saw somewhere g and though, well, let's try it.
Regexpen are not made on trail and error basis but with careful thinking.
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: 03 Jun 2004 18:25:45 GMT
From: ctcgag@hotmail.com
Subject: Re: regexp
Message-Id: <20040603142545.255$Gv@newsreader.com>
"Wojtek Michalik" <wojmichal@poczta.onet.pl> wrote:
> Can anybody give me en example of working regex
> that will match sample text given below:
> ____________
> banana\n
> \tapple\n
> ____________
When including literal text in a post, quote it the way you would
quote it in Perl. Otherwise it is ambiguous. It appears that there are
two newlines between "banana" and "apple", because "\n" represents one
newline, and the actual newline (which causes them to be on separate lines)
represents another newline. Well, assuming the above is in double-quotish
circumstances, which reading further, I suspect it isn't.
> \t=tab and \n=nweline
Maybe it does, maybe it doesn't. Since it looks like you are using
the the i switch, I'm guessing that in fact \t represents '\t' and \n
represents '\n'.
> I have been trying to match it by:
> perl -pi -e 's#(banana\n\t)(apple)#$1\.\/$2#g' with modifiers like m s ms
Dealing with shell special characters and escaping, as well as perl special
characters and escaping, is a maddening proposition. If you can't make
your -e command-liner work, turn it into a real script before debugging.
Once you get your script to work, then you try turning it back into a
one-liner.
Also, simplify the substitution into a simple match. Once you get that
to work, you can go back to the substitution.
Finally, have you tried simply printing the input without modification so
you can see what it actually looks like?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Thu, 03 Jun 2004 18:35:48 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: regexp
Message-Id: <Xns94FD947BD968Fdkwwashere@216.168.3.30>
Wojtek Michalik <wojmichal@poczta.onet.pl> wrote:
> Can anybody give me en example of working regex
> that will match sample text given below:
> ____________
> banana\n
> \tapple\n
> ____________
> \t=tab and \n=nweline
> I have been trying to match it by:
> perl -pi -e 's#(banana\n\t)(apple)#$1\.\/$2#g' with modifiers like
> m s ms nothing worked.
> I use perl version 5.8 on linux
In addition to the other advice you've been given, a closer look at the
-p option could be beneficial. You're reading one line at a time (I
don't see $/ being redefined anywhere) and trying to match over
multiple lines. Somehow I'm not surprised that success is eluding you.
:-)
------------------------------
Date: Thu, 03 Jun 2004 18:50:49 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: regexp
Message-Id: <Xns94FD9707D1EC8dkwwashere@216.168.3.30>
Wojtek Michalik <wojmichal@poczta.onet.pl> wrote in alt.perl:
[the same thing that was posted in comp.lang.perl.misc]
> Can anybody give me en example of working regex
> that will match sample text given below:
> ____________
> banana\n
> \tapple\n
> -------------------------
> \t=tab and \n=nweline
> I have been trying to match it by:
> perl -pi -e 's#(banana\n\t)(apple)#$1\.\/$2#g' with modifiers like
> m s ms nothing worked.
> I use perl version 5.8 on linux
Please don't multipost. Several people (including me) have already
responded to this in clpm. Crossposting would have been appropriate.
For a discussion of crossposting and multiposting, see
http://www.cs.tut.fi/~jkorpela/usenet/xpost.html
(Note followups)
------------------------------
Date: Thu, 3 Jun 2004 21:34:53 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Setuid problems with perl 5.8.4?
Message-Id: <slrncbv6bt.ni5.efflandt@typhoon.xnet.com>
On Wed, 02 Jun 2004 21:20:14 -0400, Roy Smith <roy@panix.com> wrote:
> I've got a perl script that runs setuid root. It used to run just fine
> under perl 5.00503 (on RedHat 6.1 linux).
>
> I recently upgraded to perl 5.8.4 and now it's behaving as if it were
> not setuid. It doesn't print any errors, but acts as if it were not
> setuid. Has anything changed between those two versions which might
> affect setuid behavior?
Due to security concerns, suidperl for recent Perl versions is not suid by
default, but you could likely make it so if you understand the risks (and
perldoc perlsec). Or you could use an suid binary (like C) wrapper to run
that particular script.
Of course running anything suid will not run directly under apache suexec,
due to its safeguards (but could work indirectly).
--
David Efflandt - All spam ignored http://www.de-srv.com/
------------------------------
Date: Thu, 3 Jun 2004 23:55:35 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Setuid problems with perl 5.8.4?
Message-Id: <c9odpn$en1$1@wisteria.csv.warwick.ac.uk>
Quoth efflandt@xnet.com (David Efflandt):
> On Wed, 02 Jun 2004 21:20:14 -0400, Roy Smith <roy@panix.com> wrote:
> > I've got a perl script that runs setuid root. It used to run just fine
> > under perl 5.00503 (on RedHat 6.1 linux).
> >
> > I recently upgraded to perl 5.8.4 and now it's behaving as if it were
> > not setuid. It doesn't print any errors, but acts as if it were not
> > setuid. Has anything changed between those two versions which might
> > affect setuid behavior?
>
> Due to security concerns, suidperl for recent Perl versions is not suid by
> default, but you could likely make it so if you understand the risks (and
> perldoc perlsec). Or you could use an suid binary (like C) wrapper to run
> that particular script.
>
> Of course running anything suid will not run directly under apache suexec,
> due to its safeguards (but could work indirectly).
Surely under modern systems with safe setid scripts (i.e. with /dev/fd)
suidperl doesn't come into it any more?
$ su
# cat > suid
#!/usr/bin/perl
print $<, ',', $>, "\n";
^D
# chmod 4755 suid
# ^D
$ ./suid
1000,0
$
OTOH, if your script *does* use suidperl, then you can simply change it
to using ordinary perl instead. As I understand (but I am certainly no
expert) this is safer than having a setid suidperl executable.
Ben
--
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ ben@morrow.me.uk ~ Jorge Luis Borges, 'The Babylon Lottery'
------------------------------
Date: Fri, 04 Jun 2004 00:02:49 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Why is this upload script not working
Message-Id: <2i9lv9Fkuk0jU1@uni-berlin.de>
Ben Morrow wrote:
> Quoth constants@mix-net.net (Mark Constant):
>>
>> my $fh = $q->upload('upfile');
>> $q->uploadInfo($fh)->{'Content-Disposition'} =~
>> /filename="([\w\-\. ]+)"/;
>> my $name = ($1 or $starttime);
>
> my $UPLOAD = $q->upload('upfile');
> my $upload = $q->param('upfile');
It didn't occur to me that you can use both the upload() and param()
function in the same upload routine. (That's why I had grabbed the
name through uploadInfo(). Think the docs could be clearer...)
Anyway I tried it, and it seems to work.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 3 Jun 2004 16:06:53 -0700
From: djberg96@hotmail.com (Daniel Berger)
Subject: Re: Win32::OLE, WMI and executing methods
Message-Id: <6e613a32.0406031506.8789b67@posting.google.com>
Petri <Petri_member@newsguy.com> wrote in message news:<c9nief02cnh@drn.newsguy.com>...
> In article <6e613a32.0406030603.23ce958b@posting.google.com>, Daniel Berger
> says...
> > A.S. Perl 5.8.3
> > Windows XP Pro
>
> > I'm familiar with how to get all InstancesOf() a WMI class
> > (the only examples I could find), but I'm confused as to how to
> > call methods on a class. For example, I know how to iterate over
> > a list of Services, but how do I call the StopService() method
> > using Win32::OLE and WMI?
>
> This short example seems to work fine:
> #!/usr/bin/perl
> # How to call a method:
> #
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/calling_a_wmi_method.asp
> # Return values from StopService():
> #
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/stopservice_method_in_class_win32_service.asp
>
> use strict;
> use warnings;
> use Win32::OLE qw(in with);
>
> my $wmi = Win32::OLE->GetObject("winmgmts:");
>
> my $serv_set = $wmi->InstancesOf("Win32_Service");
> my $serv;
> foreach $serv (in($serv_set)) {
> next unless ($serv->{'Name'} eq 'SETI'); # Find SETI service.
> if ($serv->{'State'} eq 'Running') { # If it's running, stop it.
> my $ok = $serv->StopService();
> print $serv->{'Name'} . ' has been succesfully stopped.' if (!$ok);
> } else { # If service is already stopped or in some other mysterious
> # state, quit loop.
> last;
> }
> }
> __END__
>
>
> Just follow the commented URLs for more info.
> I leave error management as an exercise to the reader. :)
>
> Hope this helps!
>
>
> Petri
Ah, thanks. I was trying to call it as a class method based on
earlier docs I had read:
$wmi->ExecMethod("Win32_Service","StopService","SETI"), but it didn't
work, although it seems that ought to be possible.
Thanks again.
Dan
------------------------------
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 6649
***************************************