[31902] in Perl-Users-Digest
Perl-Users Digest, Issue: 3165 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 9 00:09:20 2010
Date: Fri, 8 Oct 2010 21:09:05 -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, 8 Oct 2010 Volume: 11 Number: 3165
Today's topics:
Re: becoming superuser <john@example.invalid>
Re: becoming superuser <jurgenex@hotmail.com>
Re: becoming superuser <john@example.invalid>
Re: becoming superuser <uri@StemSystems.com>
Re: becoming superuser <john@example.invalid>
Looping on "if" statement? <zihav@yahoo.com>
Re: Looping on "if" statement? <ben@morrow.me.uk>
Re: toy list processing problem: collect similar terms sln@netherlands.com
Re: toy list processing problem: collect similar terms <e9427749@stud4.tuwien.ac.at>
Re: toy list processing problem: collect similar terms <es@ertes.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 08 Oct 2010 01:24:24 -0600
From: John Smith <john@example.invalid>
Subject: Re: becoming superuser
Message-Id: <xMmdnTOJFc-0WjPRnZ2dnUVZ5tqdnZ2d@giganews.com>
Ben Morrow wrote:
> See '<<EOF' under 'Quote and Quote-like Operators' in perldoc perlop.
> That explains what you can achieve by quoting the identifier in various
> ways.
Thanks for the tip.
http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators
ron@dan-desktop:~/source$ perl l3.pl
The price is 7.42.
The price is 7.42.
hi there
I said foo.
I said bar.
Undefined subroutine &main::myfunc called at l3.pl line 25.
ron@dan-desktop:~/source$ catl3.pl
bash: catl3.pl: command not found
ron@dan-desktop:~/source$ cat l3.pl
#!/usr/bin/perl
use strict;
use warnings;
my $Price = 7.42;
print <<EOF;
The price is $Price.
EOF
print << "EOF"; # same as above
The price is $Price.
EOF
print << `EOC`; # execute command and get results
echo hi there
EOC
print <<"foo", <<"bar"; # you can stack them
I said foo.
foo
I said bar.
bar
myfunc(<< "THIS", 23, <<'THAT');
Here's a line
or two.
THIS
and here's another.
THAT
# perl l3.pl
ron@dan-desktop:~/source$
It doesn't really make sense until you see how perl interprets it. What
do I have to do to make that function work? I tried several things may
have worked for C or fortran, but got nothing.
> This is not at the start of the line: there is whitespace before the
> 'PERL'. This means 'PERL' is not alone on the line, so it is not
> recognized as the end of the heredoc.
ron@dan-desktop:~/source$ perl template2.pl
ron@dan-desktop:~/source$ cat l3.pl
#!/usr/bin/perl
use strict;
use warnings;
# perl l3.pl
ron@dan-desktop:~/source$ cat template2.pl
#!/usr/bin/perl
use strict;
use warnings;
my $filename = 'l3.pl';
open my $fh, ">", $filename or die "cannot open $filename: $!";
print $fh <<PERL;
#!/usr/bin/perl
use strict;
use warnings;
# perl $filename
PERL
close($fh);
chmod 0755 , $filename or die "chmod could not open $filename $!\n";
# perl template2.pl
ron@dan-desktop:~/source$
I think this is definitely the cleanest template, most legible.
> Yup. Unlike the other command-line switches, there's no way to turn on
> -T from within Perl, since in order for it to be any use it must be
> turned on very early, before any Perl code has been executed.
Ok, that's good to know for a day when I'm taking down heavier tasks,
but that day isn't today. :-)
Cheers
--
John Smith
------------------------------
Date: Fri, 08 Oct 2010 00:52:40 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: becoming superuser
Message-Id: <a6jta6prp2vdhd5duf7ndufa44h94oo6pv@4ax.com>
John Smith <john@example.invalid> wrote:
[...]
>Undefined subroutine &main::myfunc called at l3.pl line 25.
>ron@dan-desktop:~/source$ catl3.pl
>bash: catl3.pl: command not found
>ron@dan-desktop:~/source$ cat l3.pl
>#!/usr/bin/perl
>use strict;
>use warnings;
>my $Price = 7.42;
>
>
>print <<EOF;
>The price is $Price.
>EOF
>
>print << "EOF"; # same as above
>The price is $Price.
>EOF
>
>print << `EOC`; # execute command and get results
>echo hi there
>EOC
>
>print <<"foo", <<"bar"; # you can stack them
>I said foo.
>foo
>I said bar.
>bar
>
>myfunc(<< "THIS", 23, <<'THAT');
>Here's a line
>or two.
>THIS
>and here's another.
>THAT
>
># perl l3.pl
>ron@dan-desktop:~/source$
>
>It doesn't really make sense until you see how perl interprets it. What
>do I have to do to make that function work? I tried several things may
>have worked for C or fortran, but got nothing.
What function? You didn't define any function in that code above.
You were trying to call a function that doesn't exit, but the error
message told you so already.
jue
------------------------------
Date: Fri, 08 Oct 2010 13:14:23 -0600
From: John Smith <john@example.invalid>
Subject: Re: becoming superuser
Message-Id: <KcmdnX_Sa4oN8DLRnZ2dnUVZ5hmdnZ2d@giganews.com>
Jürgen Exner wrote:
> What function? You didn't define any function in that code above.
>
> You were trying to call a function that doesn't exi[s]t, but the error
> message told you so already.
sub myfunc{};
myfunc(<< "THIS", 23, <<'THAT');
Here's a line
or two.
THIS
and here's another.
THAT
# perl l3.pl
ron@dan-desktop:~/source$ perl l3.pl
Can't find string terminator "THAT" anywhere before EOF at l3.pl line 55.
I've been trying different ideas on how to declare it and see some
output that has to do with this operator, but this one eludes me. (As
did a couple of the other harder examples.)
--
John Smith
------------------------------
Date: Fri, 08 Oct 2010 15:19:57 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: becoming superuser
Message-Id: <87eic0lcf6.fsf@quad.sysarch.com>
>>>>> "JS" == John Smith <john@example.invalid> writes:
JS> Jürgen Exner wrote:
>> What function? You didn't define any function in that code above.
>>
>> You were trying to call a function that doesn't exi[s]t, but the error
>> message told you so already.
JS> sub myfunc{};
JS> myfunc(<< "THIS", 23, <<'THAT');
JS> Here's a line
JS> or two.
JS> THIS
JS> and here's another.
JS> THAT
does that line end with a newline? the error you got is usually caused
by a missing newline. winblows users seem to get this more often with
their editors. it helps to not end a perl source file with a heredoc
terminator. it is bad style and it will prevent this error.
JS> # perl l3.pl
JS> ron@dan-desktop:~/source$ perl l3.pl
JS> Can't find string terminator "THAT" anywhere before EOF at l3.pl line 55.
JS> I've been trying different ideas on how to declare it and see some
JS> output that has to do with this operator, but this one eludes me. (As
JS> did a couple of the other harder examples.)
huh??
you seem to have some odd views on here docs. they are just another way
to create a string vs quotes and qq variants. nothing more and nothing
less. they are not declared, have nothing to do with print or subs or
anything else. they can be interpolated, single quoted and even run as a
subprocess with backticks. here docs are strings.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Fri, 08 Oct 2010 21:08:53 -0600
From: John Smith <john@example.invalid>
Subject: Re: becoming superuser
Message-Id: <NYOdncGrbM5bQTLRnZ2dnUVZ5hadnZ2d@giganews.com>
Uri Guttman wrote:
> does that line end with a newline? the error you got is usually caused
> by a missing newline. winblows users seem to get this more often with
> their editors. it helps to not end a perl source file with a heredoc
> terminator. it is bad style and it will prevent this error.
Thx, uri, it was that I had a space after the THAT before the newline.
> you seem to have some odd views on here docs. they are just another way
> to create a string vs quotes and qq variants. nothing more and nothing
> less. they are not declared, have nothing to do with print or subs or
> anything else. they can be interpolated, single quoted and even run as a
> subprocess with backticks. here docs are strings.
I wouldn't say I have any views on something that I've only known about
for 72 hours; I'm just trying to wrap my head around as many of the
notions that I can latch on to right now. Some of the examples are
harder, like the one with the backtick, which I don't think I got to run
at all.
What I have now is this:
ron@dan-desktop:~/source$ perl l3.pl
The price is 7.42.
The price is 7.42.
hi there
I said foo.
I said bar.
179251
This is a string.This is a string.
The Road goes ever on and on,
down from the door where it began.
Use of uninitialized value $_ in substitution (s///) at l3.pl line 45.
ron@dan-desktop:~/source$ cat l3.pl
#!/usr/bin/perl
use strict;
use warnings;
my $Price = 7.42;
print <<EOF;
The price is $Price.
EOF
print << "EOF"; # same as above
The price is $Price.
EOF
print << `EOC`; # execute command and get results
echo hi there
EOC
print <<"foo", <<"bar"; # you can stack them
I said foo.
foo
I said bar.
bar
print <<ABC
179231
ABC
+ 20;
print "\n";
chomp(my $string = <<'END');
This is a string.
END
print "$string$string \n";
(my $quote = <<'FINIS') =~ s/^\s+//gm;
The Road goes ever on and on,
down from the door where it began.
FINIS
print "$quote";
s/this/<<E . 'that'
. 'more '/eg;
the other
E
sub myfunc{};
myfunc(<< "THIS", 23, <<THAT);
Here's a line
or two.
THIS
and here's another.
THAT
#comment
# perl l3.pl
ron@dan-desktop:~/source$
When I was saying that I couldn't get anything rolling with a
declaration is that I can't judge the author's intent and fill in the
gaps on the last couple. I can see by their complexity that they are
not ways that I'll be using a here doc anytime soon. They definitely
are ordered from the most elementary going forward.
--
John Smith
------------------------------
Date: Fri, 8 Oct 2010 14:39:38 -0700 (PDT)
From: T <zihav@yahoo.com>
Subject: Looping on "if" statement?
Message-Id: <ef818d0e-58f2-404d-ada6-a746d6db8ed8@d17g2000yqm.googlegroups.com>
Greetings,
I have been ask to support some old perl code that's been around and
running for sometime. We upgrade our Linux Redhat OS from 3 to 5.5 and
have bumped into a problem with the following if statement:
# parse stdout to xml when:
#
# using xml mode 2 or xml mode 1 and command succeeds
# we have xml obj
# output contains xml formatted data
#
if (($mode == 2 || ($mode == 1 && !$res)) && ref $xml && grep{ m/
[<>]/ }@out)
I was hoping to make a small testcase but have not been able to
reproduce the problem. What happens is perl just loops on this if
statement forever. Just wondering if anything looks obvious to someone
with great Perl skills than myself. This is three layers down in Perl
modules. We have tried 5.8.8, 5.8.0 and version 5.12 of Perl with the
same result. I believe it's an OS issue, but just can't imagine what?
Thanks for any help in advance.
Tom
------------------------------
Date: Fri, 8 Oct 2010 23:05:34 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Looping on "if" statement?
Message-Id: <e6h4o7-fgk2.ln1@osiris.mauzo.dyndns.org>
Quoth T <zihav@yahoo.com>:
> Greetings,
>
> I have been ask to support some old perl code that's been around and
> running for sometime. We upgrade our Linux Redhat OS from 3 to 5.5 and
You probably upgraded your perl at the same time. Can you try with a new
perl on the old OS, to get some idea of where the problem is coming
from? (You could also try an old perl on the new OS, but you're more
likely to run into problems that way round.)
> have bumped into a problem with the following if statement:
>
> # parse stdout to xml when:
> #
> # using xml mode 2 or xml mode 1 and command succeeds
> # we have xml obj
> # output contains xml formatted data
> #
> if (($mode == 2 || ($mode == 1 && !$res)) && ref $xml && grep{ m/
> [<>]/ }@out)
What do you see if you print out all these variables just before the
'if'? Does that help you make a small testcase?
Have you also upgraded whatever module you used to create $xml? Might
that (or some other upgrade) be having some effect?
> I was hoping to make a small testcase but have not been able to
> reproduce the problem. What happens is perl just loops on this if
> statement forever.
What makes you think it's looping on the 'if'? That doesn't seem very
likely. Have you run the code under the Perl debugger, or under strace,
or even under the C debugger, to get some idea of what's actually going
on? Have you tried splitting the 'if' up into bits to get some idea of
which bit's failing?
> Just wondering if anything looks obvious to someone
> with great Perl skills than myself. This is three layers down in Perl
> modules. We have tried 5.8.8, 5.8.0 and version 5.12 of Perl with the
> same result. I believe it's an OS issue, but just can't imagine what?
Sorry, nothing obvious. You will need a complete test case before I can
go much further.
------------------------------
Date: Fri, 08 Oct 2010 01:14:07 -0700
From: sln@netherlands.com
Subject: Re: toy list processing problem: collect similar terms
Message-Id: <8hkta6l4k1npbvijh7efjk3efom06lr54t@4ax.com>
On Thu, 07 Oct 2010 17:44:31 -0700, sln@netherlands.com wrote:
>If not preprocessor, then ...
>The too simple, order independent, id independent, Perl approach.
>
>-sln
>-----------------
>
>use strict;
>use warnings;
>use Data::Dump 'dump';
>
>my @inp = ([0,'a','b'],[1,'c','d'],[2,'e','f'],[3,'g','h'],
> [1,'i','j'],[2,'k','l'],[4,'m','n'],[2,'o','p'],
> [4,'q','r'],[5,'s','t']);
>
>my ($cnt, @outp, %hs) = (0);
>
>for my $ref (@inp) {
> $hs{ $$ref[0] } or $hs{ $$ref[0] } = $cnt++;
^ exists ...
Was left out in a paste
> push @{$outp[ $hs{ $$ref[0] } ] }, @{$ref}[ 1 .. $#{$ref} ];
>}
>
>dump @outp;
>
------------------------------
Date: Fri, 08 Oct 2010 19:20:10 +0200
From: Josef <e9427749@stud4.tuwien.ac.at>
Subject: Re: toy list processing problem: collect similar terms
Message-Id: <4caf52e5$0$10578$3b214f66@tunews.univie.ac.at>
Am 08.10.2010 04:38, schrieb Ertugrul Söylemez:
> Josef<e9427749@stud4.tuwien.ac.at> wrote:
>
>> I don't know the reason of the silence,
>> but if anybody of the c.l.f people indeed fall sick.
>> This time the code example is attempt for resuscitation, or
>> at least to sedate your hearts. ;-)
>
> Functional programmers write obfuscated code, too. But unlike Perl, it
> still looks beautiful.
Ok, what i learned now, is that perception of beautifulness could be
very different.
If you would say that sub goiter { [ map @$_,@_ ] }
is better than my previous version, you are of course right.
Hey i say this only, so the perliatic pitbulls don't snarl to you
"that has nothing to do with perl" and tear you afterwards.
Ey. Oh, maybe i shouldn't have written this.
Brave dog. brave. search this nice ball. be a nice dog. no no no ...
But yet to something completely different:
Maybe you like the following version more.
...
# charpter 1
sub fun
{@{+ reduce { my ($o,$map)=@$a; my ($k)=$b->[0];
my @k=exists $map->{$k} ? () : $k;
[[@$o,@k],
{ %$map,$k =>
[!@k?@{$map->{$k}}:(),@{$b}[1..$#$b]] }]
} @_
}}
my ($order,$map)=fun [[],{}],@inp;
dump @{$map}{@$order};
whatever^H^H^H^H^H^H^H^H* and have fun, josef
PS: Ok, i have tried to write functional code in a imperative language.
How does look your imperative code written in a functional language?
;-)
------------------------------
Date: Sat, 9 Oct 2010 00:22:03 +0200
From: Ertugrul =?UTF-8?B?U8O2eWxlbWV6?= <es@ertes.de>
Subject: Re: toy list processing problem: collect similar terms
Message-Id: <20101009002203.6f90094a@tritium.streitmacht.eu>
Josef <e9427749@stud4.tuwien.ac.at> wrote:
> Am 08.10.2010 04:38, schrieb Ertugrul S=C3=B6ylemez:
> > Josef<e9427749@stud4.tuwien.ac.at> wrote:
> >
> >> I don't know the reason of the silence,
> >> but if anybody of the c.l.f people indeed fall sick.
> >> This time the code example is attempt for resuscitation, or
> >> at least to sedate your hearts. ;-)
> >
> > Functional programmers write obfuscated code, too. But unlike Perl,
> > it still looks beautiful.
>
> Ok, what i learned now, is that perception of beautifulness could be
> very different.
Well, in fact the code I posted is beautiful in a number of ways. It's
easy to read, very fast and also elegant. However, it is not beautiful
in that you need to understand the concept of both Church lists and
continuation passing style (of which I've become a great fan in the last
few weeks).
In other words: It's beautiful, if you understand the concept it
implements. =3D)
> If you would say that sub goiter { [ map @$_,@_ ] }
> is better than my previous version, you are of course right.
The problem is that you need to understand those Perl symbols to
understand this. In contrast to understand my code you just need to
understand language syntax and the lambda abstraction (as well as the
concept the code implements).
> Hey i say this only, so the perliatic pitbulls don't snarl to you
> "that has nothing to do with perl" and tear you afterwards.
It does have something to do with Perl, it's just like Perl people don't
like to have their favorite language compared to others. =3D)
That's also the reason I'm still crossposting to c.l.p.m. Of course,
readers are free to put me on their killfile, if they prefer to, but I
see no reason.
> But yet to something completely different:
> Maybe you like the following version more.
>
> ...
> # charpter 1
> sub fun
> {@{+ reduce { my ($o,$map)=3D@$a; my ($k)=3D$b->[0];
> my @k=3Dexists $map->{$k} ? () : $k;
> [[@$o,@k],
> { %$map,$k =3D>
> [!@k?@{$map->{$k}}:(),@{$b}[1..$#$b]] }]
> } @_
> }}
> my ($order,$map)=3Dfun [[],{}],@inp;
> dump @{$map}{@$order};
More functional, but I still don't understand all those Perl symbols,
but I'm not a Perl programmer anyway.
> PS: Ok, i have tried to write functional code in a imperative language.
> How does look your imperative code written in a functional language?
An extended hello world:
main :: IO ()
main =3D do
putStr "Your name: "
hFlush stdout
name <- getLine
printf "Hello %s!\n" name
Or an implementation of 'cat':
main :: IO ()
main =3D do
args <- getArgs
case args of
[] -> getContents >>=3D putStr
_ -> mapM_ (readFile >=3D> putStr) args
And yes, it uses constant memory space. =3D)
Greets,
Ertugrul
--=20
nightmare =3D unsafePerformIO (getWrongWife >>=3D sex)
http://ertes.de/
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 V11 Issue 3165
***************************************