For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > April 2005 > Perl One-liner de-compile?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Perl One-liner de-compile?
Errin M HMMA/IT Larsen

2005-04-25, 8:55 pm

Hi everyone,

Here is an example from the perlrun perldoc page:

perl -ane 'print pop(@F), "\n";'

is equivalent to
=20
while(<> ) {
@F =3D split(' ');
print pop(@F), "\n";
}


My question is, can I get Perl to evaluate a command line (like above)
and print out the equivalent code that command line will produce?

I hope that makes sense. I thought I saw something similar to this on
this list before.

--Errin
Paul Johnson

2005-04-25, 8:55 pm

On Mon, Apr 25, 2005 at 01:45:15PM -0500, Larsen, Errin M HMMA/IT wrote:

> Hi everyone,
>
> Here is an example from the perlrun perldoc page:
>
> perl -ane 'print pop(@F), "\n";'
>
> is equivalent to
>
> while(<> ) {
> @F = split(' ');
> print pop(@F), "\n";
> }
>
>
> My question is, can I get Perl to evaluate a command line (like above)
> and print out the equivalent code that command line will produce?
>
> I hope that makes sense. I thought I saw something similar to this on
> this list before.


$ perl -MO=Deparse -ane 'print pop(@F), "\n";'

--
Paul Johnson - paul@pjcj.net
http://www.pjcj.net
Errin M HMMA/IT Larsen

2005-04-25, 8:55 pm

> -----Original Message-----
> From: Paul Johnson [mailto:paul@pjcj.net]=20
> Sent: Monday, April 25, 2005 1:53 PM
> To: Larsen, Errin M HMMA/IT
> Cc: beginners@perl.org
> Subject: Re: Perl One-liner de-compile?
>=20
>=20
> On Mon, Apr 25, 2005 at 01:45:15PM -0500, Larsen, Errin M=20
> HMMA/IT wrote:
>=20
> similar to this=20
>=20
> $ perl -MO=3DDeparse -ane 'print pop(@F), "\n";'
>=20
> --=20
> Paul Johnson - paul@pjcj.net
> http://www.pjcj.net
>=20



Ok ... So I tried this:

# perl -MO=3DDeparse -nae 'print $f[4]' /some/directory/somefile
LINE: while (defined($_ =3D <ARGV> )) {
our(@F) =3D split(" ", $_, 0);
print $f[4];
}
-e syntax OK

My question now is, where did the @f array come from? I searched
through the perlvar perldoc page, but I only found an explanation for
the @F array. Is this an example of Perl making a typo? Or is the @f
array a secret array I'm not cleared to know about?

--Errin

Charles K. Clarkson

2005-04-25, 8:55 pm

Larsen, Errin M HMMA/IT <mailto:errinlarsen@hmmausa.com> wrote:

: Or is the @f array a secret array I'm not cleared to know about?


We could tell 'ya, but then we'd have to kill 'ya.


Jeff 'japhy' Pinyan

2005-04-25, 8:55 pm

On Apr 25, Larsen, Errin M HMMA/IT said:


Note the @F, it's capital-F.
[color=darkred]
> # perl -MO=Deparse -nae 'print $f[4]' /some/directory/somefile


You're using a lowercase @f here.

> LINE: while (defined($_ = <ARGV> )) {
> our(@F) = split(" ", $_, 0);
> print $f[4];
> }
> -e syntax OK


Perl will magically produce the @F array for you, as shown. It's up to
YOU not to make the typo.

--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http://japhy.perlmonk.org/ % have long ago been overpaid?
http://www.perlmonks.org/ % -- Meister Eckhart
Errin M HMMA/IT Larsen

2005-04-25, 8:55 pm



> -----Original Message-----
> From: Jeff 'japhy' Pinyan [mailto:japhy@perlmonk.org]=20
> Sent: Monday, April 25, 2005 2:42 PM
> To: Larsen, Errin M HMMA/IT
> Cc: beginners@perl.org
> Subject: RE: Perl One-liner de-compile?
>=20

<<SNIP>>
>=20
> You're using a lowercase @f here.
>=20

<<SNIP>>
>=20
> Perl will magically produce the @F array for you, as shown. =20
> It's up to=20
> YOU not to make the typo.
>=20



Ooops. Hehe.

Thx for the 2nd set of eyes, Jeff.

--Errin
John W. Krahn

2005-04-25, 8:55 pm

Larsen, Errin M HMMA/IT wrote:
>
> Ok ... So I tried this:
>
> # perl -MO=Deparse -nae 'print $f[4]' /some/directory/somefile

^^^^^

> LINE: while (defined($_ = <ARGV> )) {
> our(@F) = split(" ", $_, 0);
> print $f[4];

^^^^^

> }
> -e syntax OK
>
> My question now is, where did the @f array come from? I searched
> through the perlvar perldoc page, but I only found an explanation for
> the @F array. Is this an example of Perl making a typo? Or is the @f
> array a secret array I'm not cleared to know about?


The @f array is there because YOU put it there. Of course in this case it
will not contain anything.


John
--
use Perl;
program
fulfillment
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com