Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Perl One-liner de-compile?
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

Report this thread to moderator Post Follow-up to this message
Old Post
Errin M HMMA/IT Larsen
04-26-05 01:55 AM


Re: Perl One-liner de-compile?
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

Report this thread to moderator Post Follow-up to this message
Old Post
Paul Johnson
04-26-05 01:55 AM


RE: Perl One-liner de-compile?
> -----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


Report this thread to moderator Post Follow-up to this message
Old Post
Errin M HMMA/IT Larsen
04-26-05 01:55 AM


RE: Perl One-liner de-compile?
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.



Report this thread to moderator Post Follow-up to this message
Old Post
Charles K. Clarkson
04-26-05 01:55 AM


RE: Perl One-liner de-compile?
On Apr 25, Larsen, Errin M HMMA/IT said:
 

Note the @F, it's capital-F.

>  # 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

Report this thread to moderator Post Follow-up to this message
Old Post
Jeff 'japhy' Pinyan
04-26-05 01:55 AM


RE: Perl One-liner de-compile?

> -----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

Report this thread to moderator Post Follow-up to this message
Old Post
Errin M HMMA/IT Larsen
04-26-05 01:55 AM


Re: Perl One-liner de-compile?
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

Report this thread to moderator Post Follow-up to this message
Old Post
John W. Krahn
04-26-05 01:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:33 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.