[21712] in Perl-Users-Digest
Perl-Users Digest, Issue: 3916 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 4 18:07:18 2002
Date: Fri, 4 Oct 2002 15:05:11 -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 Fri, 4 Oct 2002 Volume: 10 Number: 3916
Today's topics:
Re: Dynamically defining subroutines in another package (Gupit)
Eliminating right-end whitespace <amittai@amittai.com>
Re: Eliminating right-end whitespace <Tassilo.Parseval@post.rwth-aachen.de>
Re: Eliminating right-end whitespace <amittai@amittai.com>
Re: Eliminating right-end whitespace <me@dwall.fastmail.fm>
Re: Eliminating right-end whitespace <wblock@wonkity.com>
Re: Eliminating right-end whitespace (Tad McClellan)
help w chained "maps" <penny1482@attbi.com>
Re: One line to Segfault Perl <Tassilo.Parseval@post.rwth-aachen.de>
Re: One line to Segfault Perl <uri@stemsystems.com>
Re: One line to Segfault Perl <darin@naboo.to.org.no.spam.for.me>
Re: One line to Segfault Perl <wsegrave@mindspring.com>
Open a Session inside Session <zia.beheshti@hotmail.com>
Re: Script to Change Filename <wsegrave@mindspring.com>
Re: Security-Hole in module Safe.pm <rgarciasuarez@free.fr>
Re: Splice function with arrays <bart.lateur@pandora.be>
Re: Splitting Up A String ctcgag@hotmail.com
Re: unzip/zip an array <Tassilo.Parseval@post.rwth-aachen.de>
Re: unzip/zip an array <usenet@tinita.de>
Re: unzip/zip an array <Tassilo.Parseval@post.rwth-aachen.de>
Re: unzip/zip an array <joe+usenet@sunstarsys.com>
What can I do if I have not got chmop <nigel@bannockfarm.freeserve.co.uk>
Re: What can I do if I have not got chmop <Tassilo.Parseval@post.rwth-aachen.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 4 Oct 2002 13:36:06 -0700
From: gupit@yahoo.com (Gupit)
Subject: Re: Dynamically defining subroutines in another package
Message-Id: <1ea0ec40.0210041236.6d90d529@posting.google.com>
None of the solutions worked.
Defining it using qq and escaping the variable gives segmentation
fault
at runtime.
Using the first solution suggested below and trying to take a
reference to it
doesn't compile:
Unable to create sub named "" at /home/me/MyShell.pm line 451
I am trying to enhance Term::Shell to allow it to evaluate perl
expression on the fly.
Term::Shell allows me to add a CLI frontend to a script. However
Term::Shell was lacking in that it didnt evaluate perl expressions.
So if I add a command say DoThis, I want to be able to say
shell> foreach (0..5) {DoThis arg1, arg2}
I wanted to evaluate the perl expressions in the context of the
Derived class so that I could access package globals defined there.
Your second suggestion (defining execute in Base and then calling it
in Derived)
will not work in this case since the rest of the shell processing is
happening in the Base class. There is a catch_run subroutine in Base
which gets called when a perl expression is detected. The subroutine
checks if $o->{evalHandler} is defined and if it is, passes the
epxression to it to evaluate.
Having the user explicityly specify the eval Function in the Derived
class also worked, but I wanted to provide this ability by default to
the user.
I want to have a shell CLI (like Tcl) to which I can add to my
scripts, register commands and run interactive sessions. I am almost
there, but having this capability would be awesome.
Thanks,
G.
Martien Verbruggen <mgjv@tradingpost.com.au> wrote in message news:<slrnapq3r3.1qr.mgjv@verbruggen.comdyn.com.au>...
> On 3 Oct 2002 19:41:23 -0700,
> Gupit <gupit@yahoo.com> wrote:
> > Hi,
> > Can I declare a subroutine in another package at run time?
>
> Yes.
>
> > Something like:
> >
> > package Base;
> > sub new {
> > my ($o) = @_;
> > my $class = ref($o) || $o;
> >
> > my $self = bless {}, $class;
> >
> > $self->{evalHandler} = eval {
> > package $class;
> > return sub {
> > my ($o, $cmd) = @_;
> > {
> > no strict;
> > eval $cmd;
> > die $@ if $@;
> > }
> > };
> > };
>
> I don't think you want to create an anonymous subroutine or use block
> eval.
>
> Try something like (and see further changes below):
>
> eval 'package ' . $class . ';
> sub callback {
> my ($o, $cmd) = @_;
> eval $cmd;
> die $@ if $@;
> }';
>
> Although I am not sure that this is the correct solution to what your
> problem really is, it will allow you to do what you think you need to
> do (see later for suggestions).
>
> > return $self;
> > }
> >
> > ------------------------
> >
> > package Derived;
>
> Derived should inherit from Base, otherwise nothing will work:
>
> @Derived::ISA = qw/ Base /;
>
> (or use base if they're in different module files).
>
> > use vars qw($foo);
> > $foo = 123;
> >
> >
> > package main;
> >
> > my $obj = new Derived();
> > &$obj->{evalHandler}($obj, 'print $foo');
>
> Don't use ampersands unless you know why you want one.
>
> $obj is already the first argument, no need to repeat it.
>
> $obj->callback('print "$foo\n"');
>
> An alternative, since the Derived package inherits from class, is to
> do something like (untested):
>
> package Base;
>
> sub execute
> {
> my ($o, $cmd) = @_;
> my $package = ref($o);
> eval "package $package; $cmd";
> die $@ if $@;
> }
>
> sub new
> {
> my $o = shift;
> my $class = ref($o) || $o;
> my $self = bless {}, $class;
> }
>
> package Derived;
> @Derived::ISA = qw/ Base /;
> use vars '$foo';
> $foo = 123;
>
> package main;
>
> my $obj = new Derived();
> $obj->execute('print "$foo\n"');
>
> which only switches to the package when needed.
>
>
> I still thinks this sucks quite considerably, though. String evals are
> not a great way to do things in general. Why do you think you need to
> do this anyway?
>
> Martien
------------------------------
Date: Fri, 4 Oct 2002 16:40:45 -0400
From: "Amittai Aviram" <amittai@amittai.com>
Subject: Eliminating right-end whitespace
Message-Id: <ankucg$fhou4$1@ID-124651.news.dfncis.de>
Is there a function in core Perl that gets rid of all (any number of)
whitespace characters from the right or left end of a string? (This would
be equivalent to PHP's ltrim() and rtrim().) I know about chop() and
chomp(), but chop only chops one character off and chomp only gets rid of
the newline or record separator, if I'm not mistaken. Would I have to use a
regular expression? Thanks!
Amittai Aviram
amittai@amittai.com
------------------------------
Date: 4 Oct 2002 20:44:44 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Eliminating right-end whitespace
Message-Id: <ankujs$a8k$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Amittai Aviram:
> Is there a function in core Perl that gets rid of all (any number of)
> whitespace characters from the right or left end of a string? (This would
> be equivalent to PHP's ltrim() and rtrim().) I know about chop() and
> chomp(), but chop only chops one character off and chomp only gets rid of
> the newline or record separator, if I'm not mistaken. Would I have to use a
> regular expression? Thanks!
It's not a Perl-builtin, but it's trivial with a regex and substitution:
$string =~ s/ +$//;
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Fri, 4 Oct 2002 16:59:22 -0400
From: "Amittai Aviram" <amittai@amittai.com>
Subject: Re: Eliminating right-end whitespace
Message-Id: <ankvfc$f88ct$1@ID-124651.news.dfncis.de>
"Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de> wrote in
message news:ankujs$a8k$1@nets3.rz.RWTH-Aachen.DE...
> Also sprach Amittai Aviram:
>
> > Is there a function in core Perl that gets rid of all (any number of)
> > whitespace characters from the right or left end of a string? (This
would
> > be equivalent to PHP's ltrim() and rtrim().) I know about chop() and
> > chomp(), but chop only chops one character off and chomp only gets rid
of
> > the newline or record separator, if I'm not mistaken. Would I have to
use a
> > regular expression? Thanks!
>
> It's not a Perl-builtin, but it's trivial with a regex and substitution:
>
> $string =~ s/ +$//;
Yeah, gotcha. Easy enough. Thanks!
Und herzlichen Gruß an Aachen :-) .
Amittai
------------------------------
Date: Fri, 04 Oct 2002 21:00:16 -0000
From: "David K. Wall" <me@dwall.fastmail.fm>
Subject: Re: Eliminating right-end whitespace
Message-Id: <Xns929DACFA6A049dkwwashere@216.168.3.30>
Tassilo v. Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote on 04 Oct
2002:
> Also sprach Amittai Aviram:
>
>> Is there a function in core Perl that gets rid of all (any number of)
>> whitespace characters from the right or left end of a string?
>
> It's not a Perl-builtin, but it's trivial with a regex and substitution:
>
> $string =~ s/ +$//;
and it's in the FAQ as well...
perldoc -q strip
--
David K. Wall - me@dwall.fastmail.fm
"Oook."
------------------------------
Date: Fri, 04 Oct 2002 21:12:33 -0000
From: Warren Block <wblock@wonkity.com>
Subject: Re: Eliminating right-end whitespace
Message-Id: <slrnaps16v.bq.wblock@w0nkity.wonkity.com>
Tassilo v. Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote:
> It's not a Perl-builtin, but it's trivial with a regex and substitution:
>
> $string =~ s/ +$//;
That just gets rid of spaces, though, not all whitespace characters,
which would be
$string =~ s/\s+$//;
--
Warren Block * Rapid City, South Dakota * USA
------------------------------
Date: Fri, 4 Oct 2002 15:52:05 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Eliminating right-end whitespace
Message-Id: <slrnaprvrl.2ot.tadmc@magna.augustmail.com>
Amittai Aviram <amittai@amittai.com> wrote:
> Is there a function in core Perl
No.
> that gets rid of all (any number of)
> whitespace characters from the right or left end of a string?
perldoc -q space
"How do I strip blank space from the beginning/end of a string?"
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 04 Oct 2002 18:31:31 GMT
From: "Dick Penny" <penny1482@attbi.com>
Subject: help w chained "maps"
Message-Id: <78ln9.38794$xI5.7526@sccrnsc02>
A day or two ago, I asked for and rec'd help re multiple map transforms of
data. Now, I am trying to break apart a long line into separate "maps" one
per line so its easier to read, and easier to continue to add functionality.
This has been advocated several places in AS and clpm.
#1 below works fine - of course, you guys provided it.
My #2 attempt to break #1 into two lines fails - I get all the data and
digits OK, BUT w/o the period insertations.
Uggh, what have I missed? I've seen examples where they just chained maps,
sorts, greps together - isn't that what I'm doing in #2?
#1my @numbrs = map { [ map { s/(\d{4})(\d\d)$/$1.$2/; $_ } /\d+/g ] }
@lines;
#2my @numbrs = map { s/(\d{4})(\d\d)$/$1.$2/; $_ }
map{[/\d+/g]} @lines;
--
Dick Penny
------------------------------
Date: 4 Oct 2002 18:24:55 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: One line to Segfault Perl
Message-Id: <ankmdn$4du$1@nets3.rz.RWTH-Aachen.DE>
Also sprach AndyW:
> On Fri, 04 Oct 2002 15:58:19 +0100, Mark Jason Dominus wrote:
>
><snip>
>
>>
>> plover% perl -v
>> This is perl, v5.6.1 built for i586-linux
>> ...
>> plover% perl -le 'undef tcp'
>> Segmentation fault (core dumped)
>>
>> Now how about that?
>>
>
> I get on Red Hat Linux 7.3:
>
> [andy@pavilion andy]$ perl -v
>
> This is perl, v5.6.1 built for i386-linux
> [andy@pavilion andy]$ perl -le 'undef tcp'
> Segmentation fault
>
> And on Red Hat 7.3.94 (beta of Red Hat 8.0):
>
> [andyw@beta andyw]$ perl -v
>
> This is perl, v5.8.0 built for i386-linux-thread-multi
> [andyw@beta andyw]$ perl -le 'undef tcp'
> Can't modify constant item in undef operator at -e line 1, at EOF
> Execution of -e aborted due to compilation errors
>
> So perhaps it's a bug in (Red Hat's build of?) Perl 5.6.1,
> now fixed in 5.8.0.
Nope, also happens on my Debian perl-binary (5.6.1), so probably no Red
Hat specififics here.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Fri, 04 Oct 2002 19:06:16 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: One line to Segfault Perl
Message-Id: <x7adlut460.fsf@mail.sysarch.com>
>>>>> "TvP" == Tassilo v Parseval <Tassilo.Parseval@post.rwth-aachen.de> writes:
TvP> Nope, also happens on my Debian perl-binary (5.6.1), so probably no Red
TvP> Hat specififics here.
and i built 5.6.1 for linux and it happens there. but not on
sparc/solaris 5.6.1 and not on linux 5.005_03.
but you have to ask the question wtf execute 'undef tcp'?
and it cores for any bare string, not just tcp.
since 5.6.1 has been superceded by 5.8 it may be moot. but it should be
reported to perlbug anyhow.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Fri, 04 Oct 2002 20:33:58 GMT
From: Darin McBride <darin@naboo.to.org.no.spam.for.me>
Subject: Re: One line to Segfault Perl
Message-Id: <WWmn9.470706$Ag2.19390396@news2.calgary.shaw.ca>
Paul Gillingwater wrote:
> Here's a Perl script which segfaults Perl:
>
> #!/usr/bin/perl
> undef tcp;
>
> -------
> Sure, it's a nasty thing to do, but should this be a bug? Segfaults
> are never the Right Thing To Do.
Look at it as an advanced form of "die". :-)
--
To reply, please remove the obvious spam filter
------------------------------
Date: Fri, 4 Oct 2002 16:25:14 -0500
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: One line to Segfault Perl
Message-Id: <anl0vv$lu0$1@slb4.atl.mindspring.net>
"Helgi Briem" <helgi@decode.is> wrote in message
news:3d9d9fbc.2180320565@news.cis.dfn.de...
Hi, Helgi! Here's another for your side. I haven't tested the OP's script on
my Linux systems, as it would likely add nothing new to the thread.
> On 4 Oct 2002 06:33:06 -0700, paul@lanifex.com (Paul
> Gillingwater) wrote:
>
> >Here's a Perl script which segfaults Perl:
> >
> >#!/usr/bin/perl
> >undef tcp;
>
> No it doesn't. All I get is:
>
> Can't modify constant item in undef operator at
> undef_tcp.pl line 1, near "tcp;"
>
> Both under Win2000 and RH Linux 7.2.
> Activeperl 5.6.1 on both platforms.
<snip>
On this workstation with Win95(32-bit) and IndigoPerl, version info of which
is:
This is perl, v5.6.1 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)
Copyright 1987-2001, Larry Wall
Binary build 626 provided by IndigoSTAR Software. http://www.indigostar.com
Built 21:37:25 May 6 2001
I get (essentially) the same behaviour seen by Helgi Briem, i.e.,
Can't modify constant item in undef operator at undef_tcp.pl line 3, near
"tcp;"
Bareword "tcp" not allowed while "strict subs" in use at undef_tcp.pl line
3.
Execution of undef_tcp.pl aborted due to compilation errors.
In addition,
perl -c undef_tcp
gives the additional message
Unquoted string "tcp" may clash with future reserved word at undef_tcp.pl
line 3
when I comment out the 'use strict;' statement (See script).
#!perl -w
use strict;
undef tcp;
IMO, had the OP used warnings and strictures, he would have known in advance
the script was faulty.
So, I land on the side of "No it doesn't"-at least not here. ;-)
There appear to be two camps here, one of which might consider moving the
discussion to subgroup
alt.let's_beat_up_helgi_for_not_making_it_clear_that_his_statement_applied_t
o_his_own_computers_and_not_those_used_by_the_OP.
I'm a bit surprised at the consistency of Win32 and Perl 5.6.1across various
versions, as I am persuaded that each version (of WinXX) after Win95 is
better than the next.
;-)
BTW, thanks to the other Linux users for their results. I'll keep that info
in mind if I ever have a need to deliberately segfault Perl on one of my
Linux systems.
Cheers.
Bill Segraves
------------------------------
Date: Fri, 04 Oct 2002 20:05:40 GMT
From: "john b" <zia.beheshti@hotmail.com>
Subject: Open a Session inside Session
Message-Id: <owmn9.16107$ws6.335723@news2.nokia.com>
I have an Oracle database running on a server. If I want to run my script
from a different machine, I'll need to first open a telnet session (for
example, Tsession) to the machine running oracle and then open another SQL
session (Dsession) on that machine. I'm confused how I can talk to the SQL
session using my telnet session.
Can I do something like
Tsession->("Dsession-> ....");
Thanks,
------------------------------
Date: Fri, 4 Oct 2002 13:46:27 -0500
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Script to Change Filename
Message-Id: <anknqb$tkj$1@slb6.atl.mindspring.net>
"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:3d9dce8a$1@news.microsoft.com...
> William Alexander Segraves wrote:
<snip>
Thanks, Jue.
None of what I wrote was in your reponse; so I hope the OP will see that
your comments apply to his post.
ATB.
Bill Segraves
------------------------------
Date: 04 Oct 2002 21:36:40 GMT
From: Rafael Garcia-Suarez <rgarciasuarez@free.fr>
Subject: Re: Security-Hole in module Safe.pm
Message-Id: <slrnaps2oe.9o6.rgarciasuarez@rafael.example.com>
Andreas Jurenda wrote in comp.lang.perl.misc :
> Safe::reval() execute a given code in a safe compartment.
>
> But this routine has a one-time safeness.
> If you call reval() a second (or more) time with the same compartment, you
> are potential unsafe.
>
> These depends on the values of @_ at the entrypoint of the safe compartment.
While we're at it, and in a full-disclosure mood, a similar bug affects
Safe::rdo(). It's fixed in the development version of Perl.
I'd like to stress the fact that the only way to be absolutely sure that
no particular opcode will be executed by perl is to compile a separate
perl without this opcode. I think this is easy : deleting the
appropriate lines from opcode.pl and running "make regen_headers" before
"make" should be enough.
Of course this doesn't prevent the eval'd code to use an XS module that
performs system calls, and to exploit a security hole in it. (if you've
not disabled the require, dofile (do "") and entereval (eval "") ops,
along all other ops that may be used to execute another program ;-)
--
There's always something that's known to be painfully broken, for some
definitions of pain and broken. -- Jarkko Hietaniemi
------------------------------
Date: Fri, 04 Oct 2002 21:36:25 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Splice function with arrays
Message-Id: <uc2spu04h2p5a3plaj18iv4jvov2u806id@4ax.com>
John W. Krahn wrote:
># use redo
>for ( my $i = 0; $i <= $#array; $i++ ) {
> if ( $array[$i] == 5 ) {
> splice @array, $i, 1;
> redo;
> }
>}
Have you tried it with warnings enabled and a 5 at the end of the array?
@array = (1, 2, 5);
--
Bart.
------------------------------
Date: 04 Oct 2002 22:00:24 GMT
From: ctcgag@hotmail.com
Subject: Re: Splitting Up A String
Message-Id: <20021004180024.837$C8@newsreader.com>
vgtek@yahoo.com (Vivek) wrote:
> I've just started learning perl, and i was working on a problem which
> deals with cutting up a protein sequence. I'm supposed to create a
> 'cut' subroutine which cuts up a protein sequence according to a
> specified regular expression and location.
> For example if my protein sequence was:
> 'QWGCSDLPFGERTYWGGP'
> And the regular expression I gave was FGER and position was 1
> I should get the two subsequences:
> 'QWGCSDLPF' and 'GERTYWGGP'
>
> I guess I would have to match, but then I don't know how to split it.
> My Question is, how would I use split to split up the string, into the
> smaller strings?
This is my favorite way to do it:
sub fragment {
my ($protein, $pattern)=@_;
(my $real_pattern= $pattern) =~ tr!/!!d;
# allows only non-overlapping recognition sites
$protein =~ s/$real_pattern/$pattern/g;
return split '/', $protein;
};
my @frags= fragment('QWGCSDLPFGERTYWGGP' , 'F/GER') ;
__END__
It allows you specify the recognition sequence and scissile bond in a
easy and natural way. This is important, as coding
(sequence,offset) pairs by hand gets old really fast.
How it works is pretty simple: turn ...FGER... into ...F/GER...,
then split on /.
It won't accomodate non-trivial reg-ex, like degenerate or unspecified
residues. As long as there can be only one scissile bond in the
recognition sequence, this should accomodate simple degeneracy:
warn "Inadequately tested code follows";
warn "Doing regex on regex is hazardous";
sub fragment {
my ($protein, $pattern)=@_;
# Decapture (). If you already decapture your (), this hoses.
$pattern =~ s/\(/(?:/g;
my ($head,$tail) = split '/', $pattern;
$protein =~ s!($head)($tail)!$1/$2!g;
return split '/', $protein;
};
my @frags= fragment('QWGCSDLPFGERTYWGGP' , '(F|P)/GER') ;
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service
------------------------------
Date: 4 Oct 2002 18:24:55 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: unzip/zip an array
Message-Id: <ankmdn$4du$2@nets3.rz.RWTH-Aachen.DE>
Also sprach Benjamin Goldberg:
> Tassilo v. Parseval wrote:
>>
>> Also sprach John W. Krahn:
>>
>> > $ perl -e'
>> > @T = qw/a b c d e f g h/;
>> > print "@T\n";
>> > push @{ --$| ? \@T1 : \@T2 }, $_ for @T;
>> > print "@T1\n@T2\n";
>> > '
>>
>> Heh, that must be the weirdest use of $| I have ever seen.
>
> I used to have this JAPH as my signature:
>
> tr/`/ /, s/.//, print "@{[map --$| ? ucfirst lc : lc, split]}\n"
> for pack u, pack 'H*', ab5cf4021bafd28972030972b00a218eb9720000;
JAPH's are probably in a different compartement. But it's good that it
came up in this thread. I only had semi-conscious knowledge about this
flip-flop behaviour of $|.
Yet, one thing is odd: Why does it just work with decrement? This seems
to be a pattern in some of the Perl's special vars:
print $^W--, " " for 1 .. 10;
__END__
0 1 0 1 0 1 0 1 0 1
But:
print $^W++, " " for 1 .. 10;
__END__
0 1 1 1 1 1 1 1 1 1
The answer must lie somewhere in the Perl source. But I'd be interested
in the reasoning behind that.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: 4 Oct 2002 19:02:33 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: unzip/zip an array
Message-Id: <ankok9$fa5v6$1@fu-berlin.de>
Tassilo v. Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote:
> JAPH's are probably in a different compartement. But it's good that it
> came up in this thread. I only had semi-conscious knowledge about this
> flip-flop behaviour of $|.
> Yet, one thing is odd: Why does it just work with decrement?
i'd explain it like this: setting $| to 0 sets it
to 0. setting it to anything non-zero [1] sets it to 1.
so once you have $|==0 and decrement it, it'd
be -1, and so it's set to 1. then to 0 again, and
so forth.
if you only increment, you have 1, then increment, that'd
be 2, which is set to 1, and so on.
regards, tina
[1] trying to set it to a string evaluates the string in
numeric context, as far as i can see, so $|="a1" will result
in 0, but $|="1a" will result in 1.
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://PerlQuotes.tinita.de/ \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: 4 Oct 2002 19:48:59 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: unzip/zip an array
Message-Id: <ankrbb$7vj$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Tina Mueller:
> Tassilo v. Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote:
>
>> JAPH's are probably in a different compartement. But it's good that it
>> came up in this thread. I only had semi-conscious knowledge about this
>> flip-flop behaviour of $|.
>
>> Yet, one thing is odd: Why does it just work with decrement?
>
> i'd explain it like this: setting $| to 0 sets it
> to 0. setting it to anything non-zero [1] sets it to 1.
> so once you have $|==0 and decrement it, it'd
> be -1, and so it's set to 1. then to 0 again, and
> so forth.
> if you only increment, you have 1, then increment, that'd
> be 2, which is set to 1, and so on.
Ah, ok, that's clear. There is obviously some magic attached to these
vars deep down in the core. This just sets $| = 0:
sv_setpv_mg(get_sv("|", 0), "hello");
While this sets $| = "hello":
sv_setpv(get_sv("|", 0), "hello");
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: 04 Oct 2002 15:59:14 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: unzip/zip an array
Message-Id: <m3k7kyx9f1.fsf@mumonkan.sunstarsys.com>
"Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de> writes:
[...]
> Ah, ok, that's clear. There is obviously some magic attached to these
> vars deep down in the core.
Right- and thet get/set magic for '|' is in mg.c.
--
Joe Schaefer "Imagination is more important than knowledge."
--Albert Einstein
------------------------------
Date: Tue, 1 Oct 2002 17:56:13 +0100
From: "Nigel Goldsmith" <nigel@bannockfarm.freeserve.co.uk>
Subject: What can I do if I have not got chmop
Message-Id: <anl1e3$4b0$1@newsg4.svr.pol.co.uk>
Wrote a little bit of code on perl 5 then took it on to an old Sun box and
it did not like chomp, are there any alternatives? I am sure there are let
the code flow!!!
Nije
------------------------------
Date: 4 Oct 2002 21:41:04 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: What can I do if I have not got chmop
Message-Id: <anl1tg$c68$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Nigel Goldsmith:
> Wrote a little bit of code on perl 5 then took it on to an old Sun box and
> it did not like chomp, are there any alternatives? I am sure there are let
> the code flow!!!
No chomp()? I guess this box must have an antique Perl distribution back
from the Perl4 branch. Can you upgrade? This would be the preferred way.
Other than that, I can't contribute much here since I never worked with
Perl4.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
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 3916
***************************************