Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messageOn 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
Post Follow-up to this message> -----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
Post Follow-up to this messageLarsen, 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.
Post Follow-up to this messageOn 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
Post Follow-up to this message> -----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
Post Follow-up to this messageLarsen, 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
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.