[22486] in Perl-Users-Digest
Perl-Users Digest, Issue: 4707 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 14 00:05:58 2003
Date: Thu, 13 Mar 2003 21:05:09 -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 Thu, 13 Mar 2003 Volume: 10 Number: 4707
Today's topics:
AIX 5.1 perl 5.6 perldiag.pod flawed <ekulis@apple.com>
Re: AIX 5.1 perl 5.6 perldiag.pod flawed <mgjv@tradingpost.com.au>
Re: Find and Replace in PERL <abigail@abigail.nl>
Re: HoH vs. more memory efficient way to sum log entrie <krahnj@acm.org>
Re: HoH vs. more memory efficient way to sum log entrie adam-s@vitamamori.com
how to convert special characters to html entities? (Mike Judkins)
Re: how to convert special characters to html entities? <me@verizon.invalid>
Re: how to create own perl module <oxmard.Rules@ab.ab>
Re: Interpolation problem? <goldbb2@earthlink.net>
Re: Interpolation problem? <krahnj@acm.org>
it's true but can I say so ? <ericosman@rcn.com>
Re: it's true but can I say so ? <skuo@mtwhitney.nsc.com>
Re: it's true but can I say so ? <nobody@dev.null>
Re: it's true but can I say so ? <spam@thecouch.homeip.net>
Re: it's true but can I say so ? <mgjv@tradingpost.com.au>
Re: it's true but can I say so ? <REMOVEsdnCAPS@comcast.net>
Re: it's true but can I say so ? <jurgenex@hotmail.com>
Re: Math::Pari, Win32 and gcc <nospam-abuse@ilyaz.org>
Re: new Perl feature request: call into shared libs <nospam-abuse@ilyaz.org>
Re: Parser::RecDescent - dynamic repetition specifier? <abigail@abigail.nl>
pass multiple lines in ? <ericosman@rcn.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 13 Mar 2003 17:13:42 -0800
From: Ed Kulis <ekulis@apple.com>
Subject: AIX 5.1 perl 5.6 perldiag.pod flawed
Message-Id: <BA966CC6.6447%ekulis@apple.com>
Hi,
It seems that perl installs on new AIX servers is flawed. I've run into
this problem on server after server in both AIX 4.3 and 5.1.
$ cat lib_test.pl
#!/usr/bin/perl -w
use diagnostics;
$ ./lib_test.pl
couldn't find diagnostic data in /usr/opt/perl5/lib/5.6.0/pods/perldiag.pod
/usr/opt/perl5/lib/5.6.0/aix /usr/opt/perl5/lib/5.6.0
/usr/opt/perl5/lib/site_perl/5.6.0/aix /usr/opt/perl5/lib/site_perl/5.6.0
/usr/opt/perl5/lib/site_perl . ./lib_test.pl at
/usr/opt/perl5/lib/5.6.0/diagnostics.pm line 241, <POD_DIAG> line 549.
Compilation failed in require at ./lib_test.pl line 3, <POD_DIAG> line 549.
BEGIN failed--compilation aborted at ./lib_test.pl line 3, <POD_DIAG> line
549.
In the AIX 4.3 days we happened to have a good perl 5.003 install on one and
only one server and we just copied the pod from that
But this is the first AIX 5.1 and perl 5.6 install so I don't know where the
lib might be.
I don't install the perl. Another department does.
What can I tell them so that they can fix the perl problem?
Did they miss an option in the install?
What's the right way to do it?
-ed
------------------------------
Date: Fri, 14 Mar 2003 02:22:24 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: AIX 5.1 perl 5.6 perldiag.pod flawed
Message-Id: <slrnb72f71.bkm.mgjv@verbruggen.comdyn.com.au>
On Thu, 13 Mar 2003 17:13:42 -0800,
Ed Kulis <ekulis@apple.com> wrote:
> Hi,
>
> It seems that perl installs on new AIX servers is flawed. I've run into
> this problem on server after server in both AIX 4.3 and 5.1.
>
> $ cat lib_test.pl
> #!/usr/bin/perl -w
>
> use diagnostics;
>
> $ ./lib_test.pl
> couldn't find diagnostic data in /usr/opt/perl5/lib/5.6.0/pods/perldiag.pod
Looks like perldiag.pod isn't installed.
What does
$ perldoc perldiag
do?
> I don't install the perl. Another department does.
>
> What can I tell them so that they can fix the perl problem?
Tell them to just do a standard install, and not to muck about with
the installation tree after that. The documentation is an important
part of Perl, and they shouldn't remove it. If they haven't removed
it, they have screwed up in some other way. Maybe the permissions on
files or directories are broken.
> Did they miss an option in the install?
You will have to ask them how they installed it. Talk to them, and
have them check it. We have no access to your machine.
> What's the right way to do it?
Read the INSTALL file.
Run Configure with the right options (or sit through the whole thing
answering 500 questions).
make
make test
make install
The person installing it should make sure they have a sane umask set.
You sysadmin should already _know_ this.
Martien
--
|
Martien Verbruggen |
Trading Post Australia | What's another word for Thesaurus?
|
------------------------------
Date: 13 Mar 2003 23:22:08 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Find and Replace in PERL
Message-Id: <slrnb724l0.k0s.abigail@alexandra.abigail.nl>
KP (kunal.patel@motorola.com) wrote on MMMCDLXXXI September MCMXCIII in
<URL:news:b4qopq$hnh$1@newshost.mot.com>:
!! I would like to find a string like "xyz abc 234" in my text file and replace
!! it with " mmm nnn 999". How do I do that in PERL ?
perl -i -plwe '$_ = " mmm nnn 999" if $_ eq "xyz abc 234"' text_file
!! Also I would like to display 2 lines before the line that matches my string
!! and 2 lines after the match .....
So, you want to replace the lines in the file, and display the two
lines before the match, and after the match to stdout?
Here's something untested:
#!/usr/bin/perl
use strict;
use warnings;
# Assume file to be modifed as parameter.
die "$0 <file>" unless @ARGV;
my $file = shift;
my @buffer = ("", "");
open my $in => $file or die "Failed to open $file: $!";
open my $out => "> /tmp/f.$$" or die "Failed to open tmp file: $!";
my $after = 0;
while (<$in>) {
print if $after --> 0;
if ($_ eq "xyz abc 234\n") {
$_ = " mmm nnn 999\n";
print @buffer;
@buffer = ("", $_);
$after = 2;
}
shift @buffer;
push @buffer => $after >= 0 ? "" : $_;
print $out $_;
}
close $in;
close $out or die "Failed to close tmp file: $!";
system mv => "/tmp/f.$$", $file and die "mv failed\n";
__END__
This might not give you what you want if there are two lines
consisting of "xyz abc 234\n" following each other, or with
just one line in between. But you don't really specify what
you want in that case anyway.
Abigail
--
$" = "/"; split // => eval join "+" => 1 .. 7;
*{"@_"} = sub {foreach (sort keys %_) {print "$_ $_{$_} "}};
%_ = (Just => another => Perl => Hacker); &{%_};
------------------------------
Date: Fri, 14 Mar 2003 02:28:13 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: HoH vs. more memory efficient way to sum log entries?
Message-Id: <3E713E35.A6C2F0E5@acm.org>
adam@pls.posthere.com wrote:
>
> I use this script or one like it for lots of handy counting jobs. In
> the case below I am creating a Hash of a Hash to sum up the amount of
> data each "page type" has. So expected output would look like this:
> www.somesite.com nonpub.htm = 496343 (that's in bytes)
>
> But since I am running it on the squid logs for the entire month of
> February (and our cache is big/busy), it is running out of memory. Do
> any of you know of a more memory efficient way to do such a count?
> Other suggestions for code improvement always welcome.
>
> thanks,
>
> Adam
> #!/usr/bin/perl -w
use strict;
> $squidlog="./feb_squid_logs";
my $squidlog = './feb_squid_logs';
> open(LOG,"$squidlog") || die "cannot open $squidlog: $!";
^ ^
The quotes are not required.
open( LOG, $squidlog ) || die "cannot open $squidlog: $!";
> foreach $match (<LOG>)
Other have already pointed out that this slurps the entire file into a
list.
while ( my $match = <LOG> ) {
> {
> ( $junk, $junk, $junk, $junk, $junk, $junk, $junk, $junk, $bytes,
> $junk, $url, $junk, $junk, $junk ) = split(/ +/, $match);
You can use undef as a place marker in a lvalue list for values you
don't want to keep.
my ( undef, undef, undef, undef, undef, undef, undef, undef,
$bytes, undef, $url ) = split ' ', $match;
However you could use a list slice to make it more "readable".
my ( $bytes, $url ) = (split ' ', $match)[ 8, 10 ];
> next unless ($bytes > 30000); # only count/sum objects that
> are larger than 30K
> $file_object = $url;
> $front_url = $url;
> $file_object =~ s#^.*/(.*)#$1#g;
> $front_url =~ s#^http://(.*?)/+.*#$1#g;
( my $file_object = $url ) =~ s#^.*/##;
my ($front_url) = $url =~ m#^http://([^/]+)#;
> if ($file_object ne "" ) {
> $HoH{$front_url}{$file_object} += $bytes;
> }
You could use the Perl4 style of multi-key hashes which would use less
memory.
if ( defined $file_object ) {
$hash{$front_url,$file_object} += $bytes;
}
> }
>
> foreach $domain ( keys %HoH ) {
> foreach $file ( keys %{ $HoH{$domain} } ) {
> print "$domain: $file = $HoH{$domain}{$file} \n";
> }
> print "\n";
> }
for my $key ( keys %hash ) {
my ( $domain, $file ) = split /$;/, $key;
print "$domain: $file = $hash{$key}\n";
}
John
--
use Perl;
program
fulfillment
------------------------------
Date: Fri, 14 Mar 2003 03:02:51 GMT
From: adam-s@vitamamori.com
Subject: Re: HoH vs. more memory efficient way to sum log entries?
Message-Id: <urg27v89g8hldpt571fr68ecb4bd0lr3bu@4ax.com>
To John W. Krahn, David K. Wall, Steve Grazzini, Anno Siegel and Ben
Kennedy I owe a huge thank you! Reading all the perl knowledge I
don't (didn't) know makes me feel especially uninformed and yet the
fact you all were kind enough to give me so many useful tips really
makes my day.
Thanks also for suggesting improvements beyond my slurping blunder -
making the code more readable (completely forgot about slices!) and
just better style is a goal I have but don't always manage. At least
the lesson of using while to read files should be burned into me.
thanks a lot guys,
Adam
------------------------------
Date: 13 Mar 2003 15:53:00 -0800
From: mikeyjudkins@yahoo.com (Mike Judkins)
Subject: how to convert special characters to html entities?
Message-Id: <17e1ae4c.0303131553.c14675b@posting.google.com>
Hi All,
Im a relative newbie with Perl and I want to convert a text string
which contains special characters such as á, ™, ë, etc, to the
corresponding html entities which will be output to the page. I have
tried, without success, to install the HTML:Entities module from CPAN.
It seems there are a few dependencies that the module has and I just
do not have the background to go installing all these modules that it
needs to work correctly, nor do I have root access. I chose to go the
route of the kluge, by doing a series of grep find and replacements on
the string, such as:
$title =~ s/™/™/g;
$title =~ s/®/®/g;
$title =~ s/á/á/g;
$title =~ s/à/à/g;
...and so on for each character in $title. I know its ugly, but I just
want something to work for now. BUT it seems that Perl does not like
these special characters in the script anywhere. It breaks if I have
even one of them in there.
ANY advice on how I can troubleshoot this is much appreciated.
Thanks,
Mike
------------------------------
Date: Fri, 14 Mar 2003 00:21:49 GMT
From: "dw" <me@verizon.invalid>
Subject: Re: how to convert special characters to html entities?
Message-Id: <xg9ca.49511$gi1.21943@nwrdny02.gnilink.net>
"Mike Judkins" <mikeyjudkins@yahoo.com> wrote in message
news:17e1ae4c.0303131553.c14675b@posting.google.com...
>
> $title =~ s/T/™/g;
> $title =~ s/®/®/g;
> $title =~ s/á/á/g;
> $title =~ s/à/à/g;
>
> ...and so on for each character in $title. I know its ugly, but I just
> want something to work for now. BUT it seems that Perl does not like
> these special characters in the script anywhere. It breaks if I have
> even one of them in there.
>
> ANY advice on how I can troubleshoot this is much appreciated.
>
why not just use the hex codes for those characters:
$title =~ s/[\xE1]/à/g
------------------------------
Date: Thu, 13 Mar 2003 21:09:38 -0600
From: "Peter Shankey" <oxmard.Rules@ab.ab>
Subject: Re: how to create own perl module
Message-Id: <Z46cnfUi7bWb1eyjXTWcpg@comcast.com>
"Abigail" <abigail@abigail.nl> wrote in message
news:slrnb6vb2h.1ud.abigail@alexandra.abigail.nl...
> ramesh (rpalla@kentlaw.edu) wrote on MMMCDLXXX September MCMXCIII in
> <URL:news:2b0865a8.0303121236.2b938a47@posting.google.com>:
> --
> -- I am trying to create my own module to connect to database and to
> -- query some tables. please help
>
>
> Use vi.
I will be laughing at that one for years to come :)
------------------------------
Date: Thu, 13 Mar 2003 20:23:52 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Interpolation problem?
Message-Id: <3E712F28.38136C8C@earthlink.net>
Paul wrote:
>
> I've tried every combination I could think of in this regex and read
> the perlre and perlop material and search for post on the problem but
> I must be missing the obvious.
>
> I'm traversing an IIS server directory structure comparing file sizes.
> I want to strip my root path off of a fully qualified file name that
> is being compiled as the structure is traversed.
>
> $root = '//server4/k\$/inetpub';
> $entry = '//server4/k\$/inetpub/Wwwroot/sub1/filename.ext';
The proper solution is:
use File::Spec ();
print File::Spec->abs2rel($entry, $root);
[untested]
> $entry =~ s/$root//;
You can't quite do that, but you can do:
$entry =~ s/^\Q$root//;
Or:
substr( $entry, 0, length $root ) = ""
if substr( $entry, 0, length $root ) eq $root;
Or:
for my $foo ( substr( $entry, 0, length $root ) ) {
$foo = "" if $foo eq $root;
}
> print "$entry\n";
>
> I've changed $root to the server name and the results are as expected.
> I've tried double quoting with double backslashes and that didn't
> seem to make any difference. I've changed the delimiter to | and #
> that didn't seem to make any difference. Any help would be
> appreciated.
The reason why it fails is that '$' is special to the regular expression
parser, and is interpreted as (?=\n?\z). The \Q I added quotes the $ to
make it not be treated specially.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Fri, 14 Mar 2003 02:41:17 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Interpolation problem?
Message-Id: <3E714146.87F1408A@acm.org>
Steve May wrote:
>
> You might try to 'quote' the pattern scalar:
>
> my $root = '/some/path/to/foo';
> my $entry = '/some/path/to/foo/foo.txt';
>
> $entry =~ s/\Q$root\E//;
> ^ ^ trailing \E is not mandatory (in this case)
>
> print "$entry\n";
>
> Didn't test this, but it's so brain dead simple that I don't *think* I
> screwed it up. :-)
Yes, and don't forget to anchor it to the beginning of the string. :-)
$entry =~ s/^\Q$root\E//;
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 13 Mar 2003 18:46:28 -0500
From: Eric Osman <ericosman@rcn.com>
Subject: it's true but can I say so ?
Message-Id: <3E711854.1010807@rcn.com>
I'm getting an error when I say
my $found_contents = false;
The error says
[Thu Mar 13 18:37:10 2003] reFormat.pl: Bareword "false" not
allowed while "strict subs" in use at reFormat.pl line 46.
Now, before I merely go through my code and make it a bit less self-
documenting by resorting to thing like
my $found_contents = 0;
I want to ask here : Does Perl provide some builtin way to declare
something to be "true" or "false" ? Or must some representative
expressions such as 0 and 1 be used instead ?
I tried looking it up in Wall's "Programming Perl" book and it's
non-obvious (or I wouldn't have asked in here, as doing so risks
Abigail calling me a bonehead)
Thanks. /Eric
------------------------------
Date: Thu, 13 Mar 2003 16:09:56 -0800
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: it's true but can I say so ?
Message-Id: <Pine.GSO.4.21.0303131608120.19652-100000@mtwhitney.nsc.com>
On Thu, 13 Mar 2003, Eric Osman wrote:
> (snipped) ...
> I want to ask here : Does Perl provide some builtin way to declare
> something to be "true" or "false" ? Or must some representative
> expressions such as 0 and 1 be used instead ?
>
> I tried looking it up in Wall's "Programming Perl" book and it's
> non-obvious (or I wouldn't have asked in here, as doing so risks
> Abigail calling me a bonehead)
>
> Thanks. /Eric
>
% perldoc perldata
and look under the 'Scalar values' section.
...
A scalar value is interpreted as TRUE in the Boolean sense
if it is not the null string or the number 0 (or its string
equivalent, "0"). The Boolean context is just a special
kind of scalar context where no conversion to a string or a
number is ever performed.
There are actually two varieties of null strings (sometimes
referred to as "empty" strings), a defined one and an
undefined one. The defined version is just a string of
length zero, such as `""'. The undefined version is the
value that indicates that there is no real value for
something, such as when there was an error, or at end of
file, or when you refer to an uninitialized variable or
element of an array or hash. Although in early versions of
Perl, an undefined scalar could become defined when first
used in a place expecting a defined value, this no longer
happens except for rare cases of autovivification as
explained in the perlref manpage. You can use the defined()
operator to determine whether a scalar value is defined
(this has no meaning on arrays or hashes), and the undef()
operator to produce an undefined value.
Also see:
perldoc -q defined
...
Why does defined() return true on empty arrays and hashes?
The short story is that you should probably only use defined
on scalars or functions, not on aggregates (arrays and
hashes). See the defined entry in the perlfunc manpage in
the 5.004 release or later of Perl for more detail.
--
Hope this helps,
Steve
------------------------------
Date: Fri, 14 Mar 2003 01:06:18 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: it's true but can I say so ?
Message-Id: <3E712AA6.9060307@dev.null>
Eric Osman wrote:
>
>
> I'm getting an error when I say
>
> my $found_contents = false;
>
> The error says
>
> [Thu Mar 13 18:37:10 2003] reFormat.pl: Bareword "false" not
> allowed while "strict subs" in use at reFormat.pl line 46.
>
>
> Now, before I merely go through my code and make it a bit less self-
> documenting by resorting to thing like
>
> my $found_contents = 0;
>
>
> I want to ask here : Does Perl provide some builtin way to declare
> something to be "true" or "false" ? Or must some representative
> expressions such as 0 and 1 be used instead ?
>
How about something like:
use strict;
sub true{
return (1==1)
};
sub false{
return (1==0)
};
my $found_contents=false;
print "It's a lie" unless ($found_contents);
------------------------------
Date: Thu, 13 Mar 2003 20:15:20 -0500
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: it's true but can I say so ?
Message-Id: <I2aca.6665$a24.50717@weber.videotron.net>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Eric Osman wrote:
>
>
> I'm getting an error when I say
>
> my $found_contents = false;
>
> The error says
>
> [Thu Mar 13 18:37:10 2003] reFormat.pl: Bareword "false" not
> allowed while "strict subs" in use at reFormat.pl line 46.
>
>
> Now, before I merely go through my code and make it a bit less self-
> documenting by resorting to thing like
>
> my $found_contents = 0;
This is perfectly acceptable for a "false" value in perl, so is using
'undef'. Both evaluate to false in a boolean expression.
Almost everything else (1, "hello", "I_Like_Cake") is true.
Alternatively if it makes you feel better, you can declare "true" and
"false" as constants in the beginning of your program and use these 2
words when playing with variables.
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE+cS0oeS99pGMif6wRAp0DAJ4qSMkRcMkTlR6KwGJnNWyFZZXc9wCg2UvC
shAdU63S5wkLkzfenxRpqF0=
=OJxu
-----END PGP SIGNATURE-----
------------------------------
Date: Fri, 14 Mar 2003 02:16:00 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: it's true but can I say so ?
Message-Id: <slrnb72eqv.bkm.mgjv@verbruggen.comdyn.com.au>
On Thu, 13 Mar 2003 20:15:20 -0500,
Mina Naguib <spam@thecouch.homeip.net> wrote:
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> Eric Osman wrote:
>>
>>
>> I'm getting an error when I say
>>
>> my $found_contents = false;
>>
>> The error says
>>
>> [Thu Mar 13 18:37:10 2003] reFormat.pl: Bareword "false" not
>> allowed while "strict subs" in use at reFormat.pl line 46.
>>
>>
>> Now, before I merely go through my code and make it a bit less self-
>> documenting by resorting to thing like
>>
>> my $found_contents = 0;
>
> This is perfectly acceptable for a "false" value in perl, so is using
> 'undef'. Both evaluate to false in a boolean expression.
>
> Almost everything else (1, "hello", "I_Like_Cake") is true.
>
> Alternatively if it makes you feel better, you can declare "true" and
> "false" as constants in the beginning of your program and use these 2
> words when playing with variables.
I know you know this, but as a general note for other people
considering using Perl as if it's Pascal:
Be careful of context. True and False in Perl can be quite subtle, and
do depend on context. For example, what (a bare) return returns in
list or scalar context is different. Both values are "false" but
different. A subroutine that uses
return;
will return a false value for every context ("" for scalar context,
and the empty list for list context).
return undef;
or
return false;
will return a false value in scalar context, and a true value in list
context (a list with one element), unless the false() subroutine knows
how to deal with this context correctly.
Also: Perl does not have strict boolean ideas about false and true. A
language like Pascal (or Java) will only accept an expression of a
boolean type in an if-test. Perl accepts any expression, and will
interpret the return value in its own peculiar way to determine
true-ness (it's much more like C and C++ in that respect).
IOW, don't expect things like
if ($variable == true)
and
if ($variable == false)
to work the same as
if ($variable)
and
if (! $variable)
If, in Perl, you still insist on using some subs or something to
designate for false and true, then you need to be aware to only ever
use them in scalar context (unless your sub deals with the various
contexts correctly), and to only ever use them as assignments.
Anything else is bound to trip you up.
Just use undef for "false" scalars and the empty list for "false"
arrays. They're the most natural false value in Perl (except maybe the
other null string: ""). Also read other posts in this thread quoting
the relevant bit from the documentation.
Using false and true, i.e. trying to force other language paradigms
onto Perl is not a good idea. That way madness lies.
Martien
PS. Even though this is not really that much of a FAQ, should there be
something in the FAQ?
--
|
Martien Verbruggen | I'm just very selective about what I accept
Trading Post Australia | as reality - Calvin
|
------------------------------
Date: Thu, 13 Mar 2003 20:17:13 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: it's true but can I say so ?
Message-Id: <Xns933DD875DFFCAsdn.comcast@216.166.71.239>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Andras Malatinszky <nobody@dev.null> wrote in
news:3E712AA6.9060307@dev.null:
> How about something like:
>
> use strict;
> sub true{
> return (1==1)
> };
> sub false{
> return (1==0)
> };
> my $found_contents=false;
> print "It's a lie" unless ($found_contents);
If you tweak the above just a tad:
sub true () {
return (1==1)
}
sub false () {
return (1=0)
}
you'll take advantage of a feature of the optimizer: If a function
has a null prototype and its return value can be computed at
compile-time, perl simply replaces the function call with the value
it would produce, resulting in a fair speed increase. (This is part
of how "use constant" works).
- --
Eric
print scalar reverse sort qw p ekca lre reh
ts uJ p, $/.r, map $_.$", qw e p h tona e;
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32) - WinPT 0.5.13
iD8DBQE+cTqwY96i4h5M0egRAh8LAJ0ST0Ky7cfSE+v4oQdH87EVX9sH+gCfTvs5
3tTXaVPVT5jDc/T1wxmdJ9k=
=fSHe
-----END PGP SIGNATURE-----
------------------------------
Date: Fri, 14 Mar 2003 04:02:45 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: it's true but can I say so ?
Message-Id: <Fvcca.28397$iq1.12832@nwrddc02.gnilink.net>
Martien Verbruggen wrote:
> IOW, don't expect things like
>
> if ($variable == true)
> and
> if ($variable == false)
> to work the same as
Quite true.
But regardless of the programming language writing such code shows a blatant
ignorance about Boolean algebra to begin with and is a sure way to tell that
the programmer is not up to the task.Writing this in homework won't generate
a fail but it is a sure-fire way to generate some lengthy comment.
But good to point it out, anyway.
jue
------------------------------
Date: Fri, 14 Mar 2003 03:06:01 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Math::Pari, Win32 and gcc
Message-Id: <b4rgup$2ps7$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Sisyphus
<kalinabears@hdc.com.au>], who wrote in article <3e70434c$0$22385@echo-01.iinet.net.au>:
> Hi,
> I have perl5.6.1 built with mingw32 (gcc and dmake) on Windows 2000.
>
> Been trying to build Math::Pari for a couple of days.
>
> I was getting 'unresolved references' to 'geteuid', 'getpwnam' and 4 other
> nixy-type functions - so I amended the makefile.pl's (there are 2) to link
> to libcygwin.a by using the '-L' and '-l' switches.
Instead find where these functions are called, and look for the symbol
to define so that they are not called. Let me know the details.
BTW, are you sure you've read README/INSTALL? I would think that this
problem should be fixed by giving "Configure" option to Makefile.PL...
Again, let me know.
These function calls should not have any relevance to how the library
is used. If anything else fails, find how to #ifdef them out. Again,
let me know. [Now you got the drift, right? ;-]
Hope this helps,
Ilya
------------------------------
Date: Fri, 14 Mar 2003 02:54:40 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: new Perl feature request: call into shared libs
Message-Id: <b4rg9g$2pm6$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Bryan Castillo
<rook_5150@yahoo.com>], who wrote in article <1bff1830.0303121636.5ae73e22@posting.google.com>:
> > > Default convention (__cdecl) is the same. Windows system libraries are
> > > compiled with __stdcall convention which is different. The following code
> > > should suffice for any convention except a register-parameter scheme:
> >
> > Actually, one could also duplicate the last min(3, num_params)
> > arguments in EAX, EDX, ECX. This way the same code could call
> > __regparam__(3) functions too.
> Why not have the calling convention used as a parameter?
What for - if one can avoid it?
> I don't see why you would try to satisfy all schemes with one
> function.
Why not - if this is easy to do? Change 3 to 6 above, and duplicate
the last 6 arguments in 6 standard registers; then providing arguments
to the wrapper function in a "correct" order will satisfy any "input"
calling convention.
Ilya
P.S. BTW, on Sparc it is: the first 6 arguments in the 6 "input"
registers; the rest elsewhere.
------------------------------
Date: 13 Mar 2003 23:41:06 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Parser::RecDescent - dynamic repetition specifier?
Message-Id: <slrnb725oi.k0s.abigail@alexandra.abigail.nl>
user2048 (user2048@yahoo.removethis.com) wrote on MMMCDLXXXI September
MCMXCIII in <URL:news:Xns933D9228E74CFmytokxyzzy@129.250.170.100>:
%% I'm trying to use PRD to parse a file which is divided into sections,
%% where each section contains a line count, followed by that many lines.
%% My approach is to pass the line count as a subrule argument,
%% and then use it in a repetition specifier in the subrule. As in:
%%
%% file: sections /^\z/
%%
%% sections: section(s?)
%%
%% section: line_count lines[$item{line_count}]
%%
%% line_count: /(\d+)/
%%
%% lines: line($arg[0]) # problem here
I don't think PRD allows an expression inside the parens here. It
should be one of: ?, s, s?, N, N..M, ..M, or N.., with N and M
integer literals.
Abigail
--
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'
------------------------------
Date: Thu, 13 Mar 2003 23:35:27 -0500
From: Eric Osman <ericosman@rcn.com>
Subject: pass multiple lines in ?
Message-Id: <3E715C0F.4020302@rcn.com>
Hi,
When testing my CGI script from the windows xp command line, how
can I set an input parameter to be multiple lines ?
The following stupid pet trick doesn't do the expected thing:
perl reFormat.pl digestContents="123\r\n456\r\n567\r\n"
Here's more details:
My script normally expects some HTML code that uses <TEXTAREA> within
<FORM METHOD=POST>.
The script starts like this. notice how it splits the input input
individual lines:
#!/usr/bin/perl
use strict;
use CGI qw(:cgi);
use CGI::Carp qw(fatalsToBrowser);
use Regexp::Common qw /URI/;
print "Content-type: text/html\n\n";
my $cgi = CGI->new();
my $dcWhole = $cgi->param('digestContents') ||
die "I need parameter called digestContents : $!";
my @dcLines = split (/\r\n/ , $dcWhole);
. . .
However, I attempted to pass in three lines for testing like this:
perl reFormat.pl digestContents="123\r\n456\r\n567\r\n"
But it all came in as a single line.
I wanted the script to see it as though it were this:
123
456
567
Is there an easy way to pass in three lines in one command line ?
Thanks. /Eric
------------------------------
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 4707
***************************************