[33148] in Perl-Users-Digest
Perl-Users Digest, Issue: 4427 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 5 05:17:18 2015
Date: Tue, 5 May 2015 02:17:04 -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 Tue, 5 May 2015 Volume: 11 Number: 4427
Today's topics:
Re: Cannot pass an argument to expect script from my pe <rweikusat@mobileactivedefense.com>
Doubt about a sample code in "Hashes" chapter, Perl Coo <gypark@gmail.com>
Re: mind.pl showing storage and retrieval from memory <jblack@nospam.com>
Re: mind.pl showing storage and retrieval from memory <news@lawshouse.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 04 May 2015 16:10:13 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Cannot pass an argument to expect script from my perl script
Message-Id: <87fv7c4bvu.fsf@doppelsaurus.mobileactivedefense.com>
soorajspadmanabhan@gmail.com writes:
> On Monday, May 4, 2015 at 7:31:13 PM UTC+8, G.B. wrote:
>> On 04.05.15 12:21, emagnun wrote:
>> > system($script $cmd);
>>
>> Try a comma after `$script'.
>
> Thanks G.B for the reply. I will give a try tomorrow as my access is closed for the day.
>
> By the way, command is an argument to the script. So I did not quite
> understand the idea of putting a comma there.
system (and exec) are special-cased in the Perl tokenizer (AFAICT, it's
impossible to create a Perl subroutine which parses in this way) in
order to enable executing a certain program while passing an arbitrary
string as first argument (aka 'the program name').
Example illustrating this: Assuming the following, small C program
--------
#include <stdio.h>
int main(int argc, char **argv)
{
puts(*argv);
return 0;
}
--------
has been translated to an executable a.out in the current directory,
invoking this program as
[rw@doppelsaurus]/tmp#perl -e 'system("./a.out");'
./a.out
print (as shown above) ./a.out. It can also be invoked like this
[rw@doppelsaurus]/tmp#perl -e '$cmd = "./a.out"; $name = "Giant, poisonous lobster-toad"; system($cmd $name)'
Giant, poisonous lobster-toad
In order to pass an actually useful argument to the script, it must be
passed as argv[1] and not argv[0]. One way to accomplish that is to
invoke system with a list of argument by separating them with commas.
Another way is to pass just a single argument (eg "$script $cmd"). Perl
will then scan the string to see if it contains 'shell meta-characters',
passing the complete string to sh -c if it does. Otherwise, it will
split it on whitespace and execute the program without invoking a
shell. This is usually desirable if want doesn't want to make use of
features of the shell, hence, passing a comma-separated list of
arguments to system/ exec should usually be preferred.
------------------------------
Date: Mon, 4 May 2015 10:31:42 -0700 (PDT)
From: Raymundo <gypark@gmail.com>
Subject: Doubt about a sample code in "Hashes" chapter, Perl Cookbook 2nd
Message-Id: <0f856f46-2c6e-476f-bd4a-5f2002f196bf@googlegroups.com>
Hello,
I'm reading Perl Cookbook 2nd edition and I can't understand a sample code and
related paragraphs. I think that the code, the comment, and the paragraphs
are not consistent.
At first, please let me quote the text in page 174:
---- begin quote ----
Hashes can also represent relationships such as the C language #include s.
A includes B if A contains #include B. This code builds the hash
(it doesn't look for files in /usr/include as it should, but that's
a minor change):
foreach $file (@files) {
local *FH;
unless (open(FH, " < $file")) {
warn "Couldn't read $file: $!; skipping.\n";
next;
}
while (<FH>) {
next unless /^\s*#\s*include\s*<([^>]+)>/;
push(@{$includes{$1}}, $file);
}
close FH;
}
This shows which files with include statements are not included in other files:
@include_free = ( ); # list of files that don't include others
@uniq{map { @$_ } values %includes} = undef;
foreach $file (sort keys %uniq) {
push( @include_free , $file ) unless $includes{$file};
}
The values of %includes are anonymous arrays because a single file can (and
often does) include more than one other file. We use map to build up a big
list of the included files and remove duplicates using a hash.
---- end of quote ----
Now I want to describe what I think.
Suppose that a.c includes a.h.
The first code builds hash %includes as follows:
%includes = (
'a.h' => [ 'a.c' ]
)
That is, key is 'included file' and value is (a list of) 'including files'
In the second code, %uniq is built as follows:
%uniq = (
'a.c' => undef
)
Finally, @include_free is constructed as follows:
@include_free = ( 'a.c' );
Okay, the code is not any problem by itself.
The first strange thing is this comment:
# list of files that don't include others
It is not consistent with the sentence above. It should be:
# list of files that aren't included by others
And the last paragraphs, I think, should be:
The values of %includes are anonymous arrays because a single file
**can be (and often is) included by more than one other file.**
We use map to build up a big list of the **including** files and
remove duplicates using a hash.
Then all the codes and text can be consistent.
Or, the line that builds %includes hash could be:
push(@{$includes{**$file**}}, **$1**);
(swap the key and the value)
Then it would be built as:
%includes = (
'a.c' => [ 'a.h' ]
)
In this case, the single sentence between two codes is the only text
that needs to be changed:
This shows which files **do not include any other files**:
Am I missing or misunderstanding something?
I'd like to hear what you think about this.
Thank you.
G.Y. Park from South Korea
------------------------------
Date: Mon, 4 May 2015 11:06:05 -0500
From: John Black <jblack@nospam.com>
Subject: Re: mind.pl showing storage and retrieval from memory
Message-Id: <MPG.2fb154e32d732ad989826@news.eternal-september.org>
In article <bo1fkad9rl1ev0ivp0tjgtcu6dp8g4tnct@4ax.com>, jurgenex@hotmail.com says...
>
> mentificium@gmail.com wrote:
> >#!/usr/bin/perl
> >use strict; # PERL by Example (2015) p. 77
> >use warnings; # PERL by Example (2015) p. 85
> >our $age = 0; # Temporary age for loop-counting and loop-exit.
> >our @aud = " "; # PERL by Example (2015) p. 17: auditory array
> [...]
>
> What is the purpose of this forest of characters? If you are trying to
> hide your code among useless comments, then you are doing a great job.
>
> You are missing to tell the purpose of you posting.
> You are missing the purpose of the code. There is neither a (formal or
> informal) spec nor even a hint of what it is supposed to do.
> There is no input and no expected or actual output.
>
> Just a chunk of impenetrable, very poorly written code.
Its obvious this guy is trolling the group. Why does the group keep feeding the troll?
John Black
------------------------------
Date: Mon, 04 May 2015 18:05:16 +0100
From: Henry Law <news@lawshouse.org>
Subject: Re: mind.pl showing storage and retrieval from memory
Message-Id: <GaSdndFBnp1IO9rInZ2dnUU78SednZ2d@giganews.com>
On 04/05/15 17:06, John Black wrote:
> Why does the group keep feeding the troll?
I suppose it's because he trolls, if that's what he is doing, by posting
Perl, rather than rants about something or someone. Also, trolling
implies posting in a group specifically in order to annoy the people who
use it properly; I don't think this guy is doing that.
He reminds me slightly of the wingnut who posts the
earthquake-forecasting stuff. His Perl is even worse, though.
But your point is well made. I'll keep myself in check in future!
--
Henry Law Manchester, England
------------------------------
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 4427
***************************************