[22005] in Perl-Users-Digest
Perl-Users Digest, Issue: 4227 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 6 18:08:37 2002
Date: Fri, 6 Dec 2002 15:05:15 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 6 Dec 2002 Volume: 10 Number: 4227
Today's topics:
Re: Array problem. <goldbb2@earthlink.net>
backticks and variables (mcsnet)
Re: backticks and variables <pinyaj@rpi.edu>
Re: backticks and variables (Ben Morrow)
Re: backticks and variables (Tad McClellan)
Bad output of arrays with STDIN input (quasar100x)
Re: Bad output of arrays with STDIN input <tassilo.parseval@post.rwth-aachen.de>
Re: Bad output of arrays with STDIN input (Tad McClellan)
barewords unexpectedly give no error <usenet@dwall.fastmail.fm>
Re: barewords unexpectedly give no error <tassilo.parseval@post.rwth-aachen.de>
Re: barewords unexpectedly give no error <pinyaj@rpi.edu>
Re: barewords unexpectedly give no error <usenet@dwall.fastmail.fm>
Re: barewords unexpectedly give no error <usenet@dwall.fastmail.fm>
Re: Building Packages - Override Package Functions - In (Jay Tilton)
Re: Deleting from arrays ctcgag@hotmail.com
Disabling regex paren capturing (Rhys Ulerich)
Re: Disabling regex paren capturing (Ben Morrow)
Re: Disabling regex paren capturing <bkennedy@hmsonline.com>
Re: Disabling regex paren capturing <pinyaj@rpi.edu>
disappearing subject line in sendmail (Ron)
Re: disappearing subject line in sendmail (Walter Roberson)
Re: first element of a hash ctcgag@hotmail.com
Re: Get Bloomberg data with Perl? <goldbb2@earthlink.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 06 Dec 2002 14:50:44 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Array problem.
Message-Id: <3DF0FF94.33925D3D@earthlink.net>
Richard S Beckett wrote:
[snip]
> Now that's sorted out, how would you approach something like this, then?
>
> sub get_values {
> $value1 = $value1_entry -> get;
> $value2 = $value2_entry -> get;
> $value3 = $value3_entry -> get;
> etc...
> }
>
> sub update_values {
> $value1_entry -> delete (0, "end");
> $value2_entry -> delete (0, "end");
> $value3_entry -> delete (0, "end");
> etc...
>
> $value1_entry -> insert ("end", $value1);
> $value2_entry -> insert ("end", $value2) ;
> $value3_entry -> insert ("end", $value3) ;
> etc...
> }
my @entries = ( $value1_entry, $value2_entry, $value3_entry, ... );
my @values;
sub get_values {
@values = map scalar( $_->get ), @entries;
}
sub update_values {
for my $i ( 0 .. $#entries ) {
$entries[$i] -> delete( 0, "end" );
$entries[$i] -> insert( "end", $values[$i] }
}
}
--
$..=q/(?:(?{local$^C=$^C|/.(1<<$_).q/})|)/for.0..4;
$..=q/(?(?{$^C<26.and$*.=substr"\n h!,$^C,1;1}).)/;
$.=~s/!/aktrsreltanPJ,r coeueh"/;BEGIN{$^H|=(1<<21
)}"" =~ $.;print $*;q(Just another Perl hacker,\n);
------------------------------
Date: 6 Dec 2002 13:00:18 -0800
From: mcsnet@yahoo.com (mcsnet)
Subject: backticks and variables
Message-Id: <2c68573.0212061300.49461b28@posting.google.com>
hey all,
i've written a perl script(yes, i'm using cgi) that takes two form
fields and defines them as variables ($form1 and $form2). i then want
to take those two variables and use them as arguments for a command
line app (ping). the problem is that the two variables aren't being
quoted right. here's a snapshot of my code, then comments:
code:
my $form1 = em(param('name')); # put server name here
my $form2 = em(param('port')); # put port to ping on here
print "$form1, $form2"; # just to make sure the vars look good, and
they do
print "<P>";
my $tester = `./ping $form1 $form2`;
print $tester; # lets see what $tester looks like...
comments:
when i print $tester above, i get nothing, so i assume its not handing
it to ping as well. when i change the above to:
my $tester = `./ping "$form1" "$form2"`;
i can see that the first variable is being handed over in what looks
like the correct way, because the print statement prints it out
correctly, but it must be quoting it with some special character or
something, cuz i get an error that says its the wrong server name
which is the error you get if you give it a non existent host. in
other words, print says it looks good but it doesn't i guess. *shrug*
what is the correct way to use backticks AND script variables? they
way i'm doing it is the way that i've most often seen it.
help!
pmccarty at yahoo dot com
------------------------------
Date: Fri, 6 Dec 2002 16:44:32 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: mcsnet <pmccarty@yahoo.com>
Subject: Re: backticks and variables
Message-Id: <Pine.A41.3.96.1021206164141.18708C-100000@vcmr-104.server.rpi.edu>
[posted & mailed]
On 6 Dec 2002, mcsnet wrote:
>my $form1 = em(param('name')); # put server name here
>my $form2 = em(param('port')); # put port to ping on here
>print "$form1, $form2"; # just to make sure the vars look good, and
>they do
No, they DON'T. Do you know what em() does? It puts an <EM></EM> tag
around them. You should do:
my $n = param('name');
my $p = param('port');
print em($n), ", ", em($p);
Then you can do
my $output = qx(ping $n $p);
Beware of people doing evil bad things, though. You'd be better off doing
my $output = qw(ping \Q$n\E \Q$p\E);
or
my $n = quotemeta param('name');
my $p = quotemeta param('port');
my $output = qx(ping $n $p);
--
Jeff "japhy" Pinyan RPI Acacia Brother #734 2002 Acacia Senior Dean
"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: Fri, 6 Dec 2002 21:51:47 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: backticks and variables
Message-Id: <asr65j$58p$1@wisteria.csv.warwick.ac.uk>
mcsnet@yahoo.com (mcsnet) wrote:
>hey all,
>i've written a perl script(yes, i'm using cgi) that takes two form
>fields and defines them as variables ($form1 and $form2). i then want
>to take those two variables and use them as arguments for a command
>line app (ping). the problem is that the two variables aren't being
>quoted right. here's a snapshot of my code, then comments:
>
>code:
>my $form1 = em(param('name')); # put server name here
>my $form2 = em(param('port')); # put port to ping on here
>print "$form1, $form2"; # just to make sure the vars look good, and
>they do
>print "<P>";
>my $tester = `./ping $form1 $form2`;
First, you don't ping a machine on a port. You just ping it. So, removing
$form2 throughout (use decent names for your vars, dammit!) and assuming
wlog that $form1 eq 'localhost', ping will be invoked as
./ping <EM>localhost</EM>
.
>print $tester; # lets see what $tester looks like...
>
>comments:
>when i print $tester above, i get nothing, so i assume its not handing
>it to ping as well. when i change the above to:
>
>my $tester = `./ping "$form1" "$form2"`;
So now ping will be invoked as
./ping "<EM>localhost</EM>"
. See the problem?
A piece of general advice: if you are invoking external commands, and it's not
working, change the system() or `` or whatever for a print so you can see
what's _actually_ being invoked...
Ben
------------------------------
Date: Fri, 6 Dec 2002 16:28:56 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: backticks and variables
Message-Id: <slrnav2958.2dh.tadmc@magna.augustmail.com>
mcsnet <mcsnet@yahoo.com> wrote:
> i've written a perl script(yes, i'm using cgi) that takes two form
> fields and defines them as variables ($form1 and $form2). i then want
> to take those two variables and use them as arguments for a command
> line app (ping).
Danger Will Robinson!
You better have taint checking (-T) turned on...
> the problem
You have much bigger problems than the one you have noticed already,
you have a bus-sized security hole. Better plug that before you
get to production...
> is that the two variables aren't being
> quoted right. here's a snapshot of my code, then comments:
>
> code:
> my $form1 = em(param('name')); # put server name here
Why are you wrapping it in <em> tags?
Do you expect your command shell to understand HTML?
I expect that this is the cause of your problem.
my $form1 = param('name');
> my $form2 = em(param('port')); # put port to ping on here
> print "$form1, $form2"; # just to make sure the vars look good, and
> they do
^^^^^^^
No they don't, they are wrapped in <em> tags.
Are you viewing them in a browser?
> print "<P>";
> my $tester = `./ping $form1 $form2`;
Here is what you are executing:
./ping <em>some.server</em> <em>some.other.server</em>
There sure is a lot of file redirection going on there...
> i can see that the first variable is being handed over in what looks
> like the correct way, because the print statement prints it out
> correctly, but it must be quoting it with some special character or
> something,
It is *you* that has done the quoting in <em> tags. Don't do that.
> what is the correct way to use backticks AND script variables? they
> way i'm doing it is the way that i've most often seen it.
You are using backticks and variables correctly already.
The problem is with the values that are in your variables.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 6 Dec 2002 13:23:08 -0800
From: yakuza465@hotmail.com (quasar100x)
Subject: Bad output of arrays with STDIN input
Message-Id: <38b2d711.0212061323.2f04ffb3@posting.google.com>
I can't for the life of me figure out why my output always skips the
first element in an array of strings that was input using <STDIN>.
Using Active State Perl I use <STDIN> pressing enter after every
string. Then, after the last string I have to press enter twice and
THEN ctrl-z before I can get any output. That output skips the first
element. Is it because of extra \n's in the array???
Very Frustrated and Confused,
Q
p.s. I'm using Active State for Windows (hence the ctrl-z)
------------------------------
Date: 6 Dec 2002 21:53:40 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Bad output of arrays with STDIN input
Message-Id: <asr694$kh9$1@nets3.rz.RWTH-Aachen.DE>
Also sprach quasar100x:
> I can't for the life of me figure out why my output always skips the
> first element in an array of strings that was input using <STDIN>.
> Using Active State Perl I use <STDIN> pressing enter after every
> string. Then, after the last string I have to press enter twice and
> THEN ctrl-z before I can get any output. That output skips the first
> element. Is it because of extra \n's in the array???
> Very Frustrated and Confused,
Probably just a an issue with a buffered output device. Tell Perl to
flush it after each newline. Put this somewhere at the beginning of your
script:
$| = 1;
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, 6 Dec 2002 16:33:33 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Bad output of arrays with STDIN input
Message-Id: <slrnav29dt.2dh.tadmc@magna.augustmail.com>
quasar100x <yakuza465@hotmail.com> wrote:
> I can't for the life of me figure out why my output always skips the
> first element in an array of strings that was input using <STDIN>.
How do you know that it skips them?
You must be outputting them somewhere in order to make that
determination, right?
So maybe your problem is with the output rather than the input...
> Using Active State Perl
> Very Frustrated and Confused,
There is a bug in some Windows command interpreters, maybe
that is what is biting you.
Try redirecting the output to a file, then look in the file.
If there's nothing missing, then you've hit the bug.
Or, output the number of elements in the array, and see if
it is off by one:
print scalar(@array), " elements in \@array\n";
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 06 Dec 2002 21:29:55 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: barewords unexpectedly give no error
Message-Id: <Xns92DCA7D574FE9dkwwashere@216.168.3.30>
I was testing a function I wrote that uses array references, and at
one point in testing I used barewords in a place that I think should
have given me an error, but didn't. After mucking around a bit, I
found a small piece of code that reproduces the puzzling behaviour
(but without the long function I was really writing).
This bit of code executes with no errors or warnings:
use strict;
use warnings;
sub cat {
my ($r1, $r2) = @_;
return @$r1, @$r2;
}
print cat( [1..3], ['a'..'d'] );
print "\nDeref:", @{ [d,e,f] };
print "\nList: ", (k,f,hh);
print "\nList2: ", u,v,b,w;
The output is
123abcd
Deref: def
List1: kfhh
List2: uvbw
I would have expected the last three print() statements to abort the
compilation, but unexpectedly, they work.
If I comment out the subroutine and the print() that calls it, I get
the expected errors.
Is there anything documenting this behaviour? perldata doesn't seem
to cover it, and I'm not sure where else to look.
Maybe I'm just being obtuse -- it *is* Friday, after all.
--
David K. Wall - usenet@dwall.fastmail.fm
"Oook."
------------------------------
Date: 6 Dec 2002 21:53:41 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: barewords unexpectedly give no error
Message-Id: <asr695$kh9$2@nets3.rz.RWTH-Aachen.DE>
Also sprach David K. Wall:
> This bit of code executes with no errors or warnings:
>
> use strict;
> use warnings;
>
> sub cat {
> my ($r1, $r2) = @_;
> return @$r1, @$r2;
> }
>
> print cat( [1..3], ['a'..'d'] );
> print "\nDeref:", @{ [d,e,f] };
> print "\nList: ", (k,f,hh);
> print "\nList2: ", u,v,b,w;
>
>
> The output is
>
> 123abcd
> Deref: def
> List1: kfhh
> List2: uvbw
>
>
> I would have expected the last three print() statements to abort the
> compilation, but unexpectedly, they work.
So would I actually.
> If I comment out the subroutine and the print() that calls it, I get
> the expected errors.
>
> Is there anything documenting this behaviour? perldata doesn't seem
> to cover it, and I'm not sure where else to look.
You must have come across a bug. I get same behaviour as you with 5.6.1,
but the expected compile-time errors with 5.005_03 and 5.8.0. So it
broke in between but was fixed thereafter.
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, 6 Dec 2002 16:56:20 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: barewords unexpectedly give no error
Message-Id: <Pine.A41.3.96.1021206165119.18708D-100000@vcmr-104.server.rpi.edu>
On Fri, 6 Dec 2002, David K. Wall wrote:
>This bit of code executes with no errors or warnings:
>
> use strict;
> use warnings;
>
> sub cat {
> my ($r1, $r2) = @_;
> return @$r1, @$r2;
> }
>
> print cat( [1..3], ['a'..'d'] );
> print "\nDeref:", @{ [d,e,f] };
> print "\nList: ", (k,f,hh);
> print "\nList2: ", u,v,b,w;
Simplified to:
use strict;
print 1..1, bad;
That's so crappy. That's in 5.6.1!!!
It's fixed in bleadperl, at least.
--
Jeff "japhy" Pinyan RPI Acacia Brother #734 2002 Acacia Senior Dean
"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: Fri, 06 Dec 2002 22:08:25 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: barewords unexpectedly give no error
Message-Id: <Xns92DCAE5C9E04dkwwashere@216.168.3.30>
Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de> wrote on
06 Dec 2002:
> Also sprach David K. Wall:
>
>> This bit of code executes with no errors or warnings:
>>
>> use strict;
>> use warnings;
>>
>> sub cat {
>> my ($r1, $r2) = @_;
>> return @$r1, @$r2;
>> }
>>
>> print cat( [1..3], ['a'..'d'] );
>> print "\nDeref:", @{ [d,e,f] };
>> print "\nList: ", (k,f,hh);
>> print "\nList2: ", u,v,b,w;
[snip]
>
> You must have come across a bug. I get same behaviour as you with
> 5.6.1, but the expected compile-time errors with 5.005_03 and
> 5.8.0. So it broke in between but was fixed thereafter.
I forgot to include the OS and Perl version, so here it is:
This is perl, v5.6.1 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)
Binary build 629 provided by ActiveState Tool Corp.
http://www.ActiveState.com
Built 12:27:04 Aug 20 2001
I'm using Windows 2000 5.00.2195, Service Pack 2.
I suppose I should update, eh? I didn't bother because I don't
upgrade just to be upgrading, and I don't know of any features of 5.8
that I'm just dying to use. I suppose I will upgrade now.
--
David K. Wall - usenet@dwall.fastmail.fm
"Oook."
------------------------------
Date: Fri, 06 Dec 2002 22:43:24 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: barewords unexpectedly give no error
Message-Id: <Xns92DCB44A9A902dkwwashere@216.168.3.30>
Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote on 06 Dec 2002:
> Simplified to:
>
> use strict;
> print 1..1, bad;
>
> That's so crappy. That's in 5.6.1!!!
>
> It's fixed in bleadperl, at least.
I feel better now, since you and Tassilo confirm that at least it
wasn't me. First Perl bug I've found that wasn't MY fault. :-)
-- although if I hadn't carelessly typed in barewords without thinking
I would never have noticed it.
--
David K. Wall - usenet@dwall.fastmail.fm
"Oook."
------------------------------
Date: Fri, 06 Dec 2002 22:51:21 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Building Packages - Override Package Functions - Including Inheritance
Message-Id: <3df128a6.168696110@news.erols.com>
"Rod" <palladium@spinn.net> wrote:
: > : I hope this makes sense and any thought or suggestions would be
: appreciated.
: >
: > What happened when you tried it just like you wrote it?
:
: AFAIK this works as designed, I am just concerned about how safe this is?
The very worst thing I can see happening would be a "Subroutine foo
redefined at Bar_1_2.pm line ..." warning. If warnings are enabled, that
is. But redefining a sub is exactly what you want to do.
:I have looked at many of the CPAN modules, but have not seen a good example.
: If I am going about this all wrong I would appreciate any insight on better
: way to contstruct this to be safe.
A solution is not wrong just because it is unorthodox. You stated your
goal clearly, and your solution meets that goal with little effort.
Perl's good at that.
: I have thought about building this where the sub is matched via version of
: application, but this seemed to messy to manage (Possibility of 300 Subs in
: around 20 Packages).
Blecch. That sounds too much like real work.
: Sorry regarding the odd use of word inheritance..Pascal project still stuck
: in my brain.
What you want is somewhat analagous to having a subclass inheriting from a
base class, so the word is not entirely off the mark, but trying to bend
the meaning of established terminology is likely to confuse. That's all.
: #########TestMe_1_2.pm ##############
: package TestMe_1_2;
: our ($VERSION, @ISA, @EXPORT);
: require 5.000;
: require Exporter;
: use strict;
: use TestMe_1_1;
: $VERSION = 1.02;
: @ISA = qw(Exporter);
: @EXPORT= qw(clean);
If you want TestMe_1_2 to export all the symbols that it got from
TestMe_1_1, instead of duplicating the list, swipe the one that already
exists.
our @EXPORT = @TestMe_1_1::EXPORT;
Or put '@EXPORT' into TestMe_1_1 's @EXPORT array.[1]
(Oh wow. Heavy. Far out.)
[1] Kidding. Don't do this.
------------------------------
Date: 06 Dec 2002 21:59:08 GMT
From: ctcgag@hotmail.com
Subject: Re: Deleting from arrays
Message-Id: <20021206165907.852$PG@newsreader.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> According to Bill Smith <wksmith@optonline.net>:
> > It seems that "exists $list[4]" and
> > "defined $list[4]" should always give the same result. If so, I prefer
> > "defined".
> >
> > Could anyone give an example where this is not true?
>
> An array element exists if its index is smaller than the length of the
> array. It still can be undefined, as for index 1 in this example:
>
> my @x = ( 1, undef);
> for my $i ( 0 .. 3) {
> print "$i\n" if not defined $x[ $i] and exists $x[ $i];
> }
It seems there are three forms of undef in an array, the existant undef,
the nonexistant undef, and the out-of-bounds undef. So an internal
element can be either be nonexistant or existant but undefined.
my @x=(1,undef)x5;
$x[15]=undef;
$#x=20;
delete @x[1,4,7];
for my $i ( 0 .. $#x) {
print "$i: ", defined $x[$i], "\t", exists $x[ $i], "\n";
};
__END__
0: 1 1
1:
2: 1 1
3: 1
4:
5: 1
6: 1 1
7:
8: 1 1
9: 1
10:
11:
12:
13:
14:
15: 1
16:
17:
18:
19:
20:
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: 6 Dec 2002 12:44:03 -0800
From: ulerich@psu.edu (Rhys Ulerich)
Subject: Disabling regex paren capturing
Message-Id: <8f709ee4.0212061244.5ce25ed0@posting.google.com>
Say that I've got
$re_a = qr/(a+)/;
Then
$line =~ /$re_b/;
# Now $1 = "aa..."
# Now $2 = "bb..."
But what if I write code which relies on using $2 for its "bb..."
contents. Somewhere down the road, $re_a is changed to:
$re_a = qr/(a+)(c+)/;
And the definition of $re_b is the same:
$re_b = qr/$re_a\s(b+)/;
Then
$line =~ /$re_b/;
# Now $1 = "aa...";
# Now $2 = "cc...";
# Now $3 = "bb...";
And all of my code which was based upon $2 = "bb..." is broken.
I know that there's a way to disable capturing via (?:), but
is there a way to disable all nested clustering?
i.e. define $re_b as follows:
$re_b = qr/(?OPT:$re_a)\s(b+)/; # For whatever option OPT
Run
$line =~ /$re_b/;
# Now $1 = "bb..." regardless of the definition of $re_a, provided
# that $re_a still matches where it is supposed to.
Having such an option would allow people to insulate themselves from
changes in subexpressions when using smaller regexes to build up larger
ones.
Thanks.
Please reply by email to ulerich Atta psu Dotty edu. I don't get the
chance to read the group very often.
------------------------------
Date: Fri, 6 Dec 2002 21:43:30 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: Disabling regex paren capturing
Message-Id: <asr5m2$53i$1@wisteria.csv.warwick.ac.uk>
ulerich@psu.edu (Rhys Ulerich) wrote:
>Say that I've got
> $re_a = qr/(a+)/;
>
>Then
> $line =~ /$re_b/;
> # Now $1 = "aa..."
> # Now $2 = "bb..."
You haven't set $re_b. I shall assume you meant
$re_b = qr/$re_b\s(b+)/;
as below.
>But what if I write code which relies on using $2 for its "bb..."
>contents. Somewhere down the road, $re_a is changed to:
> $re_a = qr/(a+)(c+)/;
>And the definition of $re_b is the same:
> $re_b = qr/$re_a\s(b+)/;
>
>Then
> $line =~ /$re_b/;
> # Now $1 = "aa...";
> # Now $2 = "cc...";
> # Now $3 = "bb...";
>
>And all of my code which was based upon $2 = "bb..." is broken.
>I know that there's a way to disable capturing via (?:), but
>is there a way to disable all nested clustering?
>
>i.e. define $re_b as follows:
> $re_b = qr/(?OPT:$re_a)\s(b+)/; # For whatever option OPT
>Run
> $line =~ /$re_b/;
> # Now $1 = "bb..." regardless of the definition of $re_a, provided
> # that $re_a still matches where it is supposed to.
I don't think so (at least, I can't find any mention in Camel).
You might be able to something clever with (??{ }), but I'm not sure.
The only other thing I can think of is to do
($re_a_nobrack = $re_a) =~ s/<some clever re which matches () but not (?)>//g;
$re_b = qr/$re_a_nobrack\s(b+)/;
but you can't just use s/\(|\)// as a qr// re stringifies with a (?-xism) at
the beginning. You can write a pcre to match nested brackets: see the Camel
Book.
>Having such an option would allow people to insulate themselves from
>changes in subexpressions when using smaller regexes to build up larger
>ones.
You should get into the habit of always assigning $1, $2, etc. to named
variables straight away if you are going to use their values much.
[roll on Perl6, with named assignments inside regexes...]
Talking of which, you may be able to do something similar with
my $a;
$re_a = qr/(a+) (?{$a = $+})/x;
my $b;
$re_b = qr/$re_a \s (b+) (?{$b = $+})/x; [untested]
which (may) assign the 'a's matched to $a and the 'b's matched to $b. You
could the change $re_a to
my ($a, $c);
$re_a = qw/(a+) (?{$a = $+}) (c+) (?{$c = $+})/x;
and still have $b assigned to the 'b's. This is untested.
>Please reply by email to ulerich Atta psu Dotty edu. I don't get the
>chance to read the group very often.
No. Sorry. If you want help, you can read the ng like everyone else.
Ben
------------------------------
Date: Fri, 6 Dec 2002 16:58:16 -0500
From: "Ben Kennedy" <bkennedy@hmsonline.com>
Subject: Re: Disabling regex paren capturing
Message-Id: <MQWdneU2-ohIgGygXTWcrg@giganews.com>
"Rhys Ulerich" <ulerich@psu.edu> wrote in message
news:8f709ee4.0212061244.5ce25ed0@posting.google.com...
> And all of my code which was based upon $2 = "bb..." is broken.
> I know that there's a way to disable capturing via (?:), but
> is there a way to disable all nested clustering?
If you begin a new block, values in $1, $2, etc will be restored at the end
of the block:
my $string = "abcdef";
$string =~ /^(...)/;
print "\$1 is: $1\n";
{
my $string2 = "uvwxyz";
$string2 =~ /(...)$/;
print "In sub-block, \$1 is: $1\n";
}
print "Back outside sub-block, \$1 is: $1\n";
Hope this helps--
--Ben Kennedy
------------------------------
Date: Fri, 6 Dec 2002 17:11:46 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Rhys Ulerich <ulerich@psu.edu>
Subject: Re: Disabling regex paren capturing
Message-Id: <Pine.A41.3.96.1021206170812.18710A-100000@vcmr-104.server.rpi.edu>
[posted & mailed]
On 6 Dec 2002, Rhys Ulerich wrote:
>I know that there's a way to disable capturing via (?:), but
>is there a way to disable all nested clustering?
>
>i.e. define $re_b as follows:
> $re_b = qr/(?OPT:$re_a)\s(b+)/; # For whatever option OPT
>Run
> $line =~ /$re_b/;
> # Now $1 = "bb..." regardless of the definition of $re_a, provided
> # that $re_a still matches where it is supposed to.
Yes, you can! Here's a cool trick:
use re 'eval';
my $r1 = qr/(a+)/;
my $r2 = qr/(b+)/;
if ("aaa bbb" =~ /$r1 $r2/) { print "1=$1, 2=$2\n" }
if ("aaa bbb" =~ /(??{$r1}) $r2/) { print "1=$1\n" }
See perlre.pod for an explanation of what (??{ }) does. I don't know if
it actually explains it in the docs, but all capturing that goes on inside
a (??{ }) is "lost" when you leave the (??{ }).
--
Jeff "japhy" Pinyan RPI Acacia Brother #734 2002 Acacia Senior Dean
"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: Fri, 06 Dec 2002 20:47:36 GMT
From: nor@htmlcompendium.org (Ron)
Subject: disappearing subject line in sendmail
Message-Id: <3df10cbb.2685775@news.synapse.net>
Hi:
I've run a mailing of a short mailing list but on the copies
that I got the subject line had disappeared but showed up in the
header of the message when I opened it. It worked perfectly when I ran
the tests on a reduced mailing to myself - several addresses.
I also notice that there are two From: lines, one with the
servername and the other with the From: line that I set. How do I
eliminate the server From: line and use only mine?
These are being managed by a perl program that I wrote to
manage and track all of this. This is the syntax that I'm using...
==================
open (MAIL, "|/usr/sbin/sendmail -t") or dienice("Can't access the
mail program!\n");
print MAIL "To: $email\n";
print MAIL "From: $myemail\n";
print MAIL "Reply-to: $myemail\n";
print MAIL "Subject: <C> account\n";
print MAIL "other lines for the body of the message\n\n";
print MAIL "signature block\n\n";
close (MAIL);
===================
Ron Woodall
nor@synapse.net
responsible for the Compendium of HTML Elements - available at:
http://htmlcompendium.org
Ron Woodall
nor@synapse.net
responsible for the Compendium of HTML Elements - available at:
http://htmlcompendium.org
------------------------------
Date: 6 Dec 2002 20:55:54 GMT
From: roberson@ibd.nrc.ca (Walter Roberson)
Subject: Re: disappearing subject line in sendmail
Message-Id: <asr2sq$f14$1@canopus.cc.umanitoba.ca>
In article <3df10cbb.2685775@news.synapse.net>,
Ron <nor@htmlcompendium.org> wrote:
:open (MAIL, "|/usr/sbin/sendmail -t") or dienice("Can't access the mail program!\n");
:print MAIL "To: $email\n";
:print MAIL "From: $myemail\n";
:print MAIL "Reply-to: $myemail\n";
:print MAIL "Subject: <C> account\n";
:print MAIL "other lines for the body of the message\n\n";
:print MAIL "signature block\n\n";
:close (MAIL);
You should be putting an empty line between the headers and the body.
If you fail to do so then the headers will extend until the first empty
line of the body.
--
And the wind keeps blowing the angel / Backwards into the future /
And this wind, this wind / Is called / Progress.
-- Laurie Anderson
------------------------------
Date: 06 Dec 2002 22:08:09 GMT
From: ctcgag@hotmail.com
Subject: Re: first element of a hash
Message-Id: <20021206170809.413$3c@newsreader.com>
stig <nospam_stigerikson@yahoo.se> wrote:
> hi
> newbee question.
>
> i have a sorted hash
Cool. Whered you get it from? Is it in Perl?
> how can i get the first element out of the hash not knowing the key?
Look in the documentation that came with your sorted hash.
> something like $array[0] to get the first element out of the array
> $array, only on a hash.
I would suggest that if you don't know how to do that, then you don't
have a sorted hash afterall.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: Fri, 06 Dec 2002 14:32:15 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Get Bloomberg data with Perl?
Message-Id: <3DF0FB3F.22B62C7B@earthlink.net>
BreadWithSpam@fractious.net wrote:
>
> Tzvi Oppenhimer <member@dbforums.com> writes:
> > Originally posted by Michael Robbins
>
> > > Has anyone been able to get Bloomberg data into Perl?
> > > Bloomberg has an API, but only has examples for Java, VB, VBA,
> > > etc.
>
> > Have you succeed in getting Bloomberg data into Perl?
>
> I can't speak for Mr. Robbins, but I've been working
> on it myself for a little while.
>
> There are many ways to do it, though I've not personally
> seen anyone write an XS wrapper around their C libraries
> as was suggested elsewhere.
>
> Frankly getting anything with their C libs to compile
> on my windows box has been a major pain - bad enough
> to get a standalone C app running.
>
> Other ways to go -- Bloomberg offers a sample program
> which compiled without too much trouble. Call it from
> inside perl with either system or backticks.
>
> Or use OLE to talk to Excel which talks to bbcomm via
> DDE. That works very nicely for small datasets and
> as long as you're in Excel, you have access to all of
> Excel's power at the same time.
>
> Finally, there's Win32::DDE itself and, while I've
> gotten it to talk to bloomberg, I've not gotten any
> useful data back out, since the dde calls don't seem
> to have any delays and the bbcomm stuff always takes
> a second or two before any data appears.
As a last possibility, one could find out how the Bloomberg data is
gotten over the internet, and implement that protocol in perl.
I suppose if one could read the source or decompile their API, this
could be done. Or use a packet sniffer, or force the connection to go
through a logging proxy.
--
$..=q/(?:(?{local$^C=$^C|/.(1<<$_).q/})|)/for.0..4;
$..=q/(?(?{$^C<26.and$*.=substr"\n h!,$^C,1;1}).)/;
$.=~s/!/aktrsreltanPJ,r coeueh"/;BEGIN{$^H|=(1<<21
)}"" =~ $.;print $*;q(Just another Perl hacker,\n);
------------------------------
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 4227
***************************************