How to get "perl -V"'s output programmatically?

J

J Krugman

Is there a better way to get, within a Perl script, the string
generated by "perl -V" than going through sh:

my $perl_V = do { local $/; `perl -V` };

?

My guess is that the answer is no, because

perl -MO=Deparse -V

produces one big mess (I quote it below). Unfortunately, even this
big mess includes some "hard-coded" strings (such as " Build under
linux\n"), which means that even if I wanted it, I cannot turn this
mess into a general utilities library routine.

TIA,

jill


Output of perl -MO=Deparse -V

sub myconfig {
package Config;
return $summary if $summary_expanded;
$summary =~ s/\$(\w+)/my $c = $Config{$1};
defined $c ? $c : 'undef';/eg;
$summary_expanded = 1;
$summary;
}
sub Config::config_re {
package Config;
my $re = shift @_;
my(@matches) = $config_sh =~ /^$re=.*\n/gm;
@matches ? print(@matches) : print("$re: not found\n");
}
sub config_vars {
package Config;
foreach $_ (@_) {
config_re($_), next if /\W/;
my $v = exists $Config{$_} ? $Config{$_} : 'UNKNOWN';
$v = 'undef' unless defined $v;
print "$_='$v';\n";
}
}
print myconfig();
print "\nCharacteristics of this binary (from libperl): \n", " Compile-time options: USE_LARGE_FILES\n", " Built under linux\n", " Compiled at Apr 4 2004 05:57:53\n";
$" = "\n ";
@env = map({qq[$_="$ENV{$_}"];} sort(grep({/^PERL/;} keys %ENV)));
print " %ENV:\n @env\n" if @env;
print " \@INC:\n @INC\n";
 
D

David K. Wall

J Krugman said:
Is there a better way to get, within a Perl script, the string
generated by "perl -V" than going through sh:

my $perl_V = do { local $/; `perl -V` };

?

Um, how about looking at the docs for Config.pm, one of the core
modules? Or am I misunderstanding you?
 
A

Anno Siegel

J Krugman said:
Is there a better way to get, within a Perl script, the string
generated by "perl -V" than going through sh:

my $perl_V = do { local $/; `perl -V` };

Why the do-block to undef $/? That is necessary for file slurping, but
backticks always return all the output in a multiline string. So

my $perl_V = `perl -V`;

would do the same thing. But there is indeed a better way:

use Config;
my $perl_V = Config::myconfig();

That reproduces most of the text of "perl -V". There are a few insertions
in "perl -V" that are not in myconfig (probably those you are complaining
about in the part I snipped).

Anno
 
A

Anno Siegel

Purl Gurl said:
"...reproduces most of the text...."

"...a few insertions in "perl -V" that are not in myconfig...."

Clearly use of Config falls short on returns compared
to other methods, if what you write is true.

I tend to believe "better" accuracy in wording would be
afforded by describing yours as a "different" way rather
than a "better" way.

It is clearly better in the sense Jill was concerned about (and
every sensible programmer would be) -- that it should be necessary to
start another process to retrieve Perl's configuration information.
It isn't, that's what the Config module is for.

The extra information in "perl -V" can be readily retrieved by other
means, you don't need Config.pm for that.

You should praise my accuracy in even noticing and pointing out the
additions.

Anno
 
A

Anno Siegel

Purl Gurl said:
Clear to me the Config module exhibits selected problems.

I thought all modules did that, by their very nature.
Unfortunately, I am not a practicing internet mind reader
and cannot speak Jill's mind for her, as you do.

It was clearly expressed before you snipped it. No mind-reading involved.

[technical balooney snipped]

I know better than to get involved in technical arguments with you.
Make of that what you will.

Anno
 
J

J Krugman

Why the do-block to undef $/?

Ah, thanks for reminding me. I'd forgotten that `` already does
what I want in scalar context (not to mention my genius for
complexitudinositification).
But there is indeed a better way:
use Config;
my $perl_V = Config::myconfig();
That reproduces most of the text of "perl -V". There are a few insertions
in "perl -V" that are not in myconfig (probably those you are complaining
about in the part I snipped).

Thanks. Not that it's too important, but I wonder how I could find
out where in perl's code those "few insertions" are generated. I
suspect they are nothing more than processed bits from %Config::Config,
but I can't figure out who/what is doing the processing.

Thanks again,

jill
 
S

Sherm Pendley

J said:
Thanks. Not that it's too important, but I wonder how I could find
out where in perl's code those "few insertions" are generated.

It's in perl.c. Look for "case 'V':" - in 5.8.4, it starts on line 1440.
suspect they are nothing more than processed bits from %Config::Config,
but I can't figure out who/what is doing the processing.

Actually, it doesn't look that way. :-(

There are a series of #ifdefs, and in each one a call to sv_catpv() that
appends the appropriate string to a print statement. It's not drawing those
particular bits from Config.pm at all.

That's not to say that the info isn't available via Config.pm - just that
it's not where -V gets it from.

sherm--
 
T

Tassilo v. Parseval

Also sprach Sherm Pendley:
It's in perl.c. Look for "case 'V':" - in 5.8.4, it starts on line 1440.


Actually, it doesn't look that way. :-(

There are a series of #ifdefs, and in each one a call to sv_catpv() that
appends the appropriate string to a print statement. It's not drawing those
particular bits from Config.pm at all.

That's not to say that the info isn't available via Config.pm - just that
it's not where -V gets it from.

It's relatively easy to get those information by mimicking what perl.c
does with Inline::C. Here's a script that gets the locally applied
patches:

use Inline C;

print join "\n", local_patches();

__END__
__C__
void local_patches () {
#include "patchlevel.h"
Inline_Stack_Vars;
int i;
#ifdef LOCAL_PATCH_COUNT
for (i = 0; i <= LOCAL_PATCH_COUNT; i++) {
if (PL_localpatches)
Inline_Stack_Push(sv_2mortal(newSVpv(PL_localpatches[i++], 0)));
}
#endif
Inline_Stack_Done;
}

Some information however are not accessible, such as build-date and
-time as they rely on the __DATE__ and __TIME__ macros.

Tassilo
 
B

Ben Morrow

Quoth J Krugman said:
Thanks. Not that it's too important, but I wonder how I could find
out where in perl's code those "few insertions" are generated.

From perl.c:

case 'V':
if (!PL_preambleav)
PL_preambleav = newAV();
av_push(PL_preambleav,
newSVpv("use Config qw(myconfig config_vars)",0));
if (*++s != ':') {
PL_Sv = newSVpv("print myconfig();",0);
#ifdef VMS
sv_catpv(PL_Sv, "print \"\\nCharacteristics of this "
"PERLSHR image: \\n\",");
#else
sv_catpv(PL_Sv,"print \"\\nCharacteristics of this "
"binary (from libperl): \\n\",");
#endif
sv_catpv(PL_Sv,"\" Compile-time options:");
# ifdef DEBUGGING
sv_catpv(PL_Sv," DEBUGGING");
# endif
# ifdef MULTIPLICITY
sv_catpv(PL_Sv," MULTIPLICITY");

<snip more of the same>

# endif
sv_catpv(PL_Sv,"\\n\",");

#if defined(LOCAL_PATCH_COUNT)
if (LOCAL_PATCH_COUNT > 0) {
int i;
sv_catpv(PL_Sv,"\" Locally applied patches:\\n\",");
for (i = 1; i <= LOCAL_PATCH_COUNT; i++) {
if (PL_localpatches)
Perl_sv_catpvf(aTHX_ PL_Sv,
"q\" \t%s\n\",",PL_localpatches);
}
}
#endif
Perl_sv_catpvf(aTHX_ PL_Sv,"\" Built under %s\\n\"",OSNAME);
#ifdef __DATE__
# ifdef __TIME__
Perl_sv_catpvf(aTHX_ PL_Sv,
",\" Compiled at %s %s\\n\"",__DATE__,__TIME__);
# else
Perl_sv_catpvf(aTHX_ PL_Sv,
",\" Compiled on %s\\n\"",__DATE__);
# endif
#endif
sv_catpv(PL_Sv, "; \
$\"=\"\\n \"; \
@env = map { \"$_=\\\"$ENV{$_}\\\"\" } sort grep {/^PERL/} keys %ENV; ");
#ifdef __CYGWIN__
sv_catpv(PL_Sv,"\
push @env, \"CYGWIN=\\\"$ENV{CYGWIN}\\\"\";");
#endif
sv_catpv(PL_Sv, "\
print \" \\%ENV:\\n @env\\n\" if @env; \
print \" \\@INC:\\n @INC\\n\";");
}
else {
PL_Sv = newSVpv("config_vars(qw(",0);
sv_catpv(PL_Sv, ++s);
sv_catpv(PL_Sv, "))");
s += strlen(s);
}
av_push(PL_preambleav, PL_Sv);
/* don't look for script or read stdin */
scriptname = BIT_BUCKET;
goto reswitch;

So, by the looks of it, -V is pretty much the only way to get the info
that isn't in myconfig.

Ben
 
D

David K. Wall

Purl Gurl said:
Yes, you should know better. Most often, you and the other
boys here, do not fair well. Why you do not fair well is
you boys do not research, do not read, do not investigate,
do not test and certainly do not think as much as you should.

Since you're always flaming people for their use of language, how about using
words correctly yourself? It's "fare well", not "fair well".
 
J

John W. Kennedy

Always flaming? Your wording usage indicates I post here
very frequently and every article I post, is a flame. Clearly
this is untrue just as it is clear you are practicing deceit,
being the troll you are, like most here.
Well gosh, one boy out of one-hundred boys here, is almost
paying attention. Are you sure it is not "farewell?"

"It's hardly fair," muttered Hugh, "to give us such a jumble as this to
work out!"

"Fair?" Clara echoed bitterly. "Well!"

And to all my readers I can but repeat the last words of gentle Clara:

FARE-WELL!

-- Lewis Carroll, "A Tangled Tale"
 
J

John Bokma

Purl said:
John Bokma wrote:
[snip]
purlnoid?

Realistic. I estimate about half of the participants
here are ignorant insulting trolls. Of that half,

That's quite a lot. My best guess is 10% :-D.
about one-forth of those are known to me to be true
psychotic internet stalkers whose best abilities
are that of childish script kiddies who believe use
of proxy servers is a Kevin Mitnik super hack.

There are mentally disturbed internet stalkers here
who have been and are harassing our family, for the
last two to five years.

How are you able to trace back those hack attempts (I assume you mean
that) to this group? The worst thing I ever encountered was someone
calling me (phone) asking me about a Usenet posting (truth!). It ended
in an apology of his side for disturbing me :-D.
Use of proxy servers! Whoa! I am so impressed.

Blithering idiots.

You boys involved in stalking and harassing our family
only serve to significantly increase the popularity
of our home website. At least a third of our hits are
now almost every known search engine indexing our site,
thanks to your childish use of proxy servers and search
engines, to harass our family, for years.
Amazing.

Our search engine popularity index is now right up there
with Microsoft, Amazon and Ebay.

You boys are not just abusing our family, you are abusing
everyone on the net, and you don't even care. Evidence of
this harm caused to all, is a select few of you send email
to others, tricking them into harassing our family. I have
copies of some of those email.

That sounds really weird. The weirdest thing I encountered was some guy
(or girl depending on whom I spoke to after we discovered something was
fishy) sending around pictures of someone else, and claiming it were
pictures of himself. Really weird btw, and a long story. He forgot to
rename a few pics and thanks to Google we were able to track the
originals down.
You boys are victimizing tens of thousands of innocent people
and delight in doing so.

That is why you are blithering idiots, actually, mentally
disturbed stalkers who spend your days thinking only of me.

This is a trollfest newsgroup populated by some who are
truly and actually, mentally disturbed.

That is always a difficult diagnosis, even by people who have made some
sort of attempt to study DSM IV.
Purl Gurl

How come?
 
U

Uri Guttman

you don't know yet but morozilla/idjit gurl is our resident
troll. google for her inane posts over the last 3 years. then you will
understand how loony she is. best not to engage in any logical discourse
as she has major comprehension defects and is highly delusional. she
will of cource jump in and claim all but her are trolls and don't know
perl. some how no one ever believes her but herself (and newbies who
haven't learned yet.

uri
 
U

Uri Guttman

PG> My goodness, Uri! You originate from comcast which is the
PG> number one abusive server in my log records! Not only in
PG> my server logs but in my email logs as well!

you are so delusional it amazes me. i have never used nor would i ever
use any software you have anything to do with. but you know that
already.
PG> In the future, I will resume slapping you around, might
PG> even consider taking your machine down.

go ahead and try. you couldn't break out of a paper bag

PG> Nah, doing a black hat on you would lower me to your level.
PG> That will never happen. I am your superior in all aspects
PG> of life and of goodness.

in your mind that is. too bad you have no connection to reality.

how about your showing up to a perl conference some day? we always have
fun and you would be hysterical. the buzz, you mean moronzilla is here?
hahahahahha!!

but of course, all who go to perl conferences (including damian conway
and larry wall) are just trolls and know nothing compared to you. but
you wouldn't dare show up.

this post is a warning to others who read this.

uri
 
K

Keith Keller

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 2004-06-11 said:
she will of cource jump in and claim all but her are trolls and don't know
perl.

"All your Frank are stalking to us!"

- --keith

- --
(e-mail address removed)-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFAygDThVcNCxZ5ID8RAkaqAJwKXCqGkdynP0Aq5nDHGi3cpwZ9pwCfd4JX
PGTUfcAiRZ7xmYlKQInQowk=
=NpIp
-----END PGP SIGNATURE-----
 
K

Keith Keller

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Lots of childish abuse, in keeping with your childish article, lots
of abuse coming out of San Francisco, pacbell in Frisco, Level 3
through their Frisco WAN, University of California in Frisco.

Only tourists call it Frisco! Residents know better than to stoop to
such foolishness.

Do you see much abuse out of Half Moon Bay? It's a big tech center in
San Mateo County.

- --keith

- --
(e-mail address removed)-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFAyjjBhVcNCxZ5ID8RAhYKAJ9cSpVg465sxp96pVucmovVFef3qQCeNIIG
cDVhZmBI0I0PeUN1UHcIkWc=
=Rgfu
-----END PGP SIGNATURE-----
 
D

Dale Henderson

UG> you don't know yet but morozilla/idjit gurl is our resident
^^^^^^^^^
UG> troll.

You mean mean Purl Gurl and Godzilla are the same?
I was wondering what happened to Godzilla and was beginning to
notice a resemblance.
 
J

John Bokma

Uri said:
you don't know yet but morozilla/idjit gurl is our resident
troll. google for her inane posts over the last 3 years. then you will

:-D. Yeah, sometimes she trolls, and yes, she sounds a bit weird in that
other post (12:52 my time).
understand how loony she is. best not to engage in any logical discourse
as she has major comprehension defects and is highly delusional. she
will of cource jump in and claim all but her are trolls and don't know
perl. some how no one ever believes her but herself (and newbies who
haven't learned yet.

Sometimes I agree with her regexp-less solutions.
 
J

John Bokma

Purl said:
Uri Guttman wrote:




My goodness, Uri! You originate from comcast which is the
number one abusive server in my log records! Not only in
my server logs but in my email logs as well!

Try today. I have removed all blocks so you boys will
refresh our search engine index popularity.

PR 3 ? Thats not really good :-D Try PR6 or 7 ;-)
Hey, we have search engines indexing our site, engines
I did not know exist! Even Microsoft is all over our site.

That's quite normal, I see the same here, googlbot daily, others same.
Use robots.txt if you want to keep some out, or mod_rewrite.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,413
Latest member
KeiraLight

Latest Threads

Top