[32099] in Perl-Users-Digest
Perl-Users Digest, Issue: 3363 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 23 14:09:26 2011
Date: Sat, 23 Apr 2011 11:09:09 -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 Sat, 23 Apr 2011 Volume: 11 Number: 3363
Today's topics:
DBD DB2 <c.joydeep@gmail.com>
Re: DBD DB2 <john@castleamber.com>
Re: DBD DB2 <c.joydeep@gmail.com>
Re: DBD DB2 <john@castleamber.com>
Re: for @{ my $x } on Perl 5.10 (bug?) <tzz@lifelogs.com>
Re: for @{ my $x } on Perl 5.10 (bug?) <john@castleamber.com>
Re: for @{ my $x } on Perl 5.10 (bug?) <derykus@gmail.com>
Re: for @{ my $x } on Perl 5.10 (bug?) <john@castleamber.com>
Re: grabbing a facebook group <tadmc@seesig.invalid>
Re: grabbing a facebook group <tzz@lifelogs.com>
Re: grabbing a facebook group <tzz@lifelogs.com>
Re: grabbing a facebook group <john@castleamber.com>
I can't understand a sentence "Look out for implicit as <gypark@gmail.com>
Re: I can't understand a sentence "Look out for implici <tadmc@seesig.invalid>
Re: parsing a command line, but not the usual problem sln@netherlands.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 23 Apr 2011 20:55:25 +0530
From: Joydeep Chakrabarty <c.joydeep@gmail.com>
Subject: DBD DB2
Message-Id: <4db2ef64$0$316$14726298@news.sunsite.dk>
Hello all,
I am trying to install DBD for DB2. I have downloaded both
DBD-DB2-1.74.tar.gz and DBD-DB2-1.80a.tar.gz as well as DBD-DB2.ppd. I
am using Windows 7 64-bit with Active Perl 5.12.3.
When I try to do nmake on DBD-DB2 it gives me error
"c:\perl64\lib\core\win32.h(61) : fatal error C1083: Cannot open
include file: 'windows.h': No such file or directory
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual
Studio 9.0\VC\bin\cl.EXE"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: 'C:\PROGRA~2\MICROS~2.0\VC\bin\nmake.exe' :
return code '0x2'
Stop."
When I try to ppm install DBD-DB2.ppd, it gives me error "ppm install
failed: The PPD does not provide code to install for this platform".
What am I doing wrong here? Please help.
Thanks,
Joydeep
--
Thanks and regards,
Joydeep
------------------------------
Date: Sat, 23 Apr 2011 11:40:27 -0500
From: John Bokma <john@castleamber.com>
Subject: Re: DBD DB2
Message-Id: <87sjt8j4zo.fsf@castleamber.com>
Joydeep Chakrabarty <c.joydeep@gmail.com> writes:
> Hello all,
>
> I am trying to install DBD for DB2. I have downloaded both
> DBD-DB2-1.74.tar.gz and DBD-DB2-1.80a.tar.gz as well as DBD-DB2.ppd. I
> am using Windows 7 64-bit with Active Perl 5.12.3.
> When I try to do nmake on DBD-DB2 it gives me error
> "c:\perl64\lib\core\win32.h(61) : fatal error C1083: Cannot open
> include file: 'windows.h': No such file or directory
> NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual
> Studio 9.0\VC\bin\cl.EXE"' : return code '0x2'
> Stop.
> NMAKE : fatal error U1077: 'C:\PROGRA~2\MICROS~2.0\VC\bin\nmake.exe' :
> return code '0x2'
> Stop."
>
> When I try to ppm install DBD-DB2.ppd, it gives me error "ppm install
> failed: The PPD does not provide code to install for this platform".
> What am I doing wrong here? Please help.
It looks like you need a C compiler + header files to make this
module.
Have you added the alternative repositories to ppm? The ones at
ActiveState have a limited set of modules.
--
John Bokma j3b
Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma
Freelance Perl & Python Development: http://castleamber.com/
------------------------------
Date: Sat, 23 Apr 2011 22:13:59 +0530
From: Joydeep Chakrabarty <c.joydeep@gmail.com>
Subject: Re: DBD DB2
Message-Id: <4db301cc$0$302$14726298@news.sunsite.dk>
John Bokma wrote on 4/23/2011 :
> Joydeep Chakrabarty <c.joydeep@gmail.com> writes:
>
>> Hello all,
>>
>> I am trying to install DBD for DB2. I have downloaded both
>> DBD-DB2-1.74.tar.gz and DBD-DB2-1.80a.tar.gz as well as DBD-DB2.ppd. I
>> am using Windows 7 64-bit with Active Perl 5.12.3.
>> When I try to do nmake on DBD-DB2 it gives me error
>> "c:\perl64\lib\core\win32.h(61) : fatal error C1083: Cannot open
>> include file: 'windows.h': No such file or directory
>> NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual
>> Studio 9.0\VC\bin\cl.EXE"' : return code '0x2'
>> Stop.
>> NMAKE : fatal error U1077: 'C:\PROGRA~2\MICROS~2.0\VC\bin\nmake.exe' :
>> return code '0x2'
>> Stop."
>>
>> When I try to ppm install DBD-DB2.ppd, it gives me error "ppm install
>> failed: The PPD does not provide code to install for this platform".
>> What am I doing wrong here? Please help.
>
> It looks like you need a C compiler + header files to make this
> module.
>
> Have you added the alternative repositories to ppm? The ones at
> ActiveState have a limited set of modules.
I am using Visual C++ 2008 Express edition. What are the other
repositories?
--
Thanks and regards,
Joydeep
------------------------------
Date: Sat, 23 Apr 2011 12:29:04 -0500
From: John Bokma <john@castleamber.com>
Subject: Re: DBD DB2
Message-Id: <87r58skhb3.fsf@castleamber.com>
Joydeep Chakrabarty <c.joydeep@gmail.com> writes:
> John Bokma wrote on 4/23/2011 :
>> Joydeep Chakrabarty <c.joydeep@gmail.com> writes:
>>
>>> Hello all,
>>>
>>> I am trying to install DBD for DB2. I have downloaded both
>>> DBD-DB2-1.74.tar.gz and DBD-DB2-1.80a.tar.gz as well as DBD-DB2.ppd. I
>>> am using Windows 7 64-bit with Active Perl 5.12.3.
>>> When I try to do nmake on DBD-DB2 it gives me error
>>> "c:\perl64\lib\core\win32.h(61) : fatal error C1083: Cannot open
>>> include file: 'windows.h': No such file or directory
>>> NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual
>>> Studio 9.0\VC\bin\cl.EXE"' : return code '0x2'
>>> Stop.
>>> NMAKE : fatal error U1077: 'C:\PROGRA~2\MICROS~2.0\VC\bin\nmake.exe' :
>>> return code '0x2'
>>> Stop."
>>>
>>> When I try to ppm install DBD-DB2.ppd, it gives me error "ppm install
>>> failed: The PPD does not provide code to install for this platform".
>>> What am I doing wrong here? Please help.
>>
>> It looks like you need a C compiler + header files to make this
>> module.
>>
>> Have you added the alternative repositories to ppm? The ones at
>> ActiveState have a limited set of modules.
>
> I am using Visual C++ 2008 Express edition. What are the other
> repositories?
I would first check if DBD::DB2 is in one of the other repositories you
can enable in ppm. See the documentation of ppm. Or if you use the GUI
version: Click on the gray cog icon (right most icon) and the PPM Preferences
window is opened.
See also the ppm documentation, which in a default install can be
reached via the documentation installed at:
file:///C:/Perl/html/index.html
--
John Bokma j3b
Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma
Freelance Perl & Python Development: http://castleamber.com/
------------------------------
Date: Fri, 22 Apr 2011 17:22:50 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: for @{ my $x } on Perl 5.10 (bug?)
Message-Id: <878vv2ncxx.fsf@lifelogs.com>
On Fri, 22 Apr 2011 09:38:24 -0500 John Bokma <john@castleamber.com> wrote:
JB> It looks like it's a feature. Haven't checked the change logs yet, but I
JB> have the feeling that this was done to make
JB> my $x->{ foo } = 3;
JB> work (which I am OK with)
Ugh. That's some nasty syntactic syrup.
Ted
------------------------------
Date: Fri, 22 Apr 2011 18:05:29 -0500
From: John Bokma <john@castleamber.com>
Subject: Re: for @{ my $x } on Perl 5.10 (bug?)
Message-Id: <87pqodj39i.fsf@castleamber.com>
Ted Zlatanov <tzz@lifelogs.com> writes:
> On Fri, 22 Apr 2011 09:38:24 -0500 John Bokma <john@castleamber.com> wrote:
>
> JB> It looks like it's a feature. Haven't checked the change logs yet, but I
> JB> have the feeling that this was done to make
>
> JB> my $x->{ foo } = 3;
>
> JB> work (which I am OK with)
>
> Ugh. That's some nasty syntactic syrup.
Depends:
my $x = { foo => bar( ... ) };
versus
my $x->{ foo } = bar( ... );
I think the latter is a bit more pleasant to the (well, my) eyes.
--
John Bokma j3b
Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma
Freelance Perl & Python Development: http://castleamber.com/
------------------------------
Date: Sat, 23 Apr 2011 05:29:20 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: for @{ my $x } on Perl 5.10 (bug?)
Message-Id: <0295bc64-4395-41c8-970b-0f11b0c86291@x8g2000prh.googlegroups.com>
On Apr 22, 7:38=A0am, John Bokma <j...@castleamber.com> wrote:
> John Bokma <j...@castleamber.com> writes:
> > "C.DeRykus" <dery...@gmail.com> writes:
>
> >> On Apr 20, 12:53=A0pm, John Bokma <j...@castleamber.com> wrote:
> >>> perl -e 'use strict; use warnings; print for @{ my $x }'
> >>> Can't use an undefined value as an ARRAY reference at -e line 1.
>
> >>> This is perl, v5.8.8 built for x86_64-linux-thread-multi
>
> >>> perl -e 'use strict; use warnings; print for @{ my $x }'
>
> >>> This is perl, v5.10.0 built for x86_64-linux-gnu-thread-multi
>
> >>> Is this a known bug? At least, I assume that the latter working is a =
bug.
>
> >> Same with 5.12.2:
>
> >> perl =A0-Mstrict -wle "print if @{my $x}"
> >> Can't use an undefined value as an ARRAY reference at -e line 1.
>
> >> perl =A0-Mstrict -wle "print for @{my $x}"
>
> >> At the very least it seems quirky that the
> >> former fails and the latter doesn't.
>
> > Thanks Charles, I've reported it using perlbug.
>
> http://rt.perl.org/rt3/Ticket/Display.html?id=3D89024
>
> It looks like it's a feature. Haven't checked the change logs yet, but I
> have the feeling that this was done to make
>
> my $x->{ foo } =3D 3;
>
But the case above is an lvalue so $x autovivifies.
In the other example though:
perl -Mstrict -wle "print if @{my $x}"
'strict' generates a "Can't use an undefined
value as an ARRAY reference" and autoviv will
occur only without 'strict'.
Make the above an lvalue and there's no error:
perl -Mstrict -wle "print if @{my $x}=3D()"
Similarly, 'use strict' should also complain
in the case below since there's no lvalue:
perl -Mstrict -wle "print for @{my $x}"
Yet it doesn't which seems quirky to me.
> work (which I am OK with), and as a side effect (?) makes also:
>
> perl -e 'use strict; use warnings; print for @{ my $x }'
> perl -e 'use strict; use warnings; my $x; sub foo { my @bar =3D @_; };
> =A0 =A0 =A0 =A0 =A0foo( @{ my $x } );'
>
> work (and probably some other things I forgot).
>
> I was leaning towards a bug (when I knew about the for issue), but no
> longer so sure. It does sound logical, the new way, but it makes also
> IMO Perl a little more magic.
>
Magic's needed at times, but this particular
magic seems to trump consistency. It would
seem preferable to me to just loosen 'strict'
to ignore the error that's now thrown for:
perl -Mstrict -wle "print if @{my $x}"
--
Charles DeRykus
------------------------------
Date: Sat, 23 Apr 2011 11:37:00 -0500
From: John Bokma <john@castleamber.com>
Subject: Re: for @{ my $x } on Perl 5.10 (bug?)
Message-Id: <87wrikj55f.fsf@castleamber.com>
"C.DeRykus" <derykus@gmail.com> writes:
> On Apr 22, 7:38 am, John Bokma <j...@castleamber.com> wrote:
>> John Bokma <j...@castleamber.com> writes:
>> > "C.DeRykus" <dery...@gmail.com> writes:
>>
>> >> On Apr 20, 12:53 pm, John Bokma <j...@castleamber.com> wrote:
>> >>> perl -e 'use strict; use warnings; print for @{ my $x }'
>> >>> Can't use an undefined value as an ARRAY reference at -e line 1.
>>
>> >>> This is perl, v5.8.8 built for x86_64-linux-thread-multi
>>
>> >>> perl -e 'use strict; use warnings; print for @{ my $x }'
>>
>> >>> This is perl, v5.10.0 built for x86_64-linux-gnu-thread-multi
>>
>> >>> Is this a known bug? At least, I assume that the latter working is a bug.
>>
>> >> Same with 5.12.2:
>>
>> >> perl -Mstrict -wle "print if @{my $x}"
>> >> Can't use an undefined value as an ARRAY reference at -e line 1.
>>
>> >> perl -Mstrict -wle "print for @{my $x}"
>>
>> >> At the very least it seems quirky that the
>> >> former fails and the latter doesn't.
>>
>> > Thanks Charles, I've reported it using perlbug.
>>
>> http://rt.perl.org/rt3/Ticket/Display.html?id=89024
>>
>> It looks like it's a feature. Haven't checked the change logs yet, but I
>> have the feeling that this was done to make
>>
>> my $x->{ foo } = 3;
>>
>
> But the case above is an lvalue so $x autovivifies.
>
> In the other example though:
>
> perl -Mstrict -wle "print if @{my $x}"
>
> 'strict' generates a "Can't use an undefined
> value as an ARRAY reference" and autoviv will
> occur only without 'strict'.
>
> Make the above an lvalue and there's no error:
>
> perl -Mstrict -wle "print if @{my $x}=()"
>
>
> Similarly, 'use strict' should also complain
> in the case below since there's no lvalue:
>
> perl -Mstrict -wle "print for @{my $x}"
Quote from the reply Eric Brine wrote [1]
Just like the argument list of sub calls, The list over which
foreach iterates is evaluated in lvalue context as required by
foreach's aliasing property.
This also means that since 5.10 (?):
perl -e 'use strict; use warnings; sub foo { my @y=@_ }; foo( @{my $x} )'
Doesn't result in:
Can't use an undefined value as an ARRAY reference at -e line 1.
While I see now somewhat the logic behind it on the other hand I am
afraid that this will result in very subtle bugs. I am not a new to
Perl, yet I now and then manage to make mistakes like:
exists $x->{ foo }{ bar } or ...
and overlooking that I just created a key foo.
[1] http://rt.perl.org/rt3/Ticket/Display.html?id=89024
--
John Bokma j3b
Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma
Freelance Perl & Python Development: http://castleamber.com/
------------------------------
Date: Fri, 22 Apr 2011 16:52:47 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: grabbing a facebook group
Message-Id: <slrnir3tsl.6av.tadmc@tadbox.sbcglobal.net>
Peter J. Holzer <hjp-usenet2@hjp.at> wrote:
> On 2011-04-22 17:10, Tad McClellan <tadmc@seesig.invalid> wrote:
>> John Bokma <john@castleamber.com> wrote:
>>> Then ignore Uno. One doesn't have to post. If Uno is a whiny bitch
>>> there's no need to point it out.
> [...]
>> If you don't like Tad's posts,
>>
>> Then ignore Tad. One doesn't have to post. If Tad responds in-kind
>> to whiny bitches there's no need to point it out.
> [...]
>
> The difference is that I lose nothing if I put Uno in my killfile, but I
> like to read your and Uri's postings - when they are about Perl. But all
> too frequently your postings are not about Perl, but about the personal
> shortcomings of some other poster. I urge you as respected regulars of
> this group to set a good example and keep the last two points of the
> Posting Guidelines (regularly posted by a certain Mr. McClellan - you
> may know him) in mind:
>
>| Count to ten before composing a followup when you are upset
>| This is recommended in all Usenet newsgroups. Here in clpmisc, most
>| flaming sub-threads are not about any feature of Perl at all! They
>| are most often for what was seen as a breach of netiquette. If you
>| have lurked for a bit, then you will know what is expected and won't
>| make such posts in the first place.
>|
>| But if you get upset, wait a while before writing your followup. I
>| recommend waiting at least 30 minutes.
>|
>| Count to ten after composing and before posting when you are upset
>| After you have written your followup, wait *another* 30 minutes
>| before committing yourself by posting it. You cannot take it back
>| once it has been said.
Well said!
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
Date: Fri, 22 Apr 2011 17:14:38 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: grabbing a facebook group
Message-Id: <87hb9qndbl.fsf@lifelogs.com>
On Fri, 22 Apr 2011 17:21:52 +0200 Mart van de Wege <mvdwege@mail.com> wrote:
>> Seconded. Tad is having a bad week or something, but Uri has been
>> handing out the tough love for a while. Let's keep it civil, guys.
MvdW> Uno has had an explanation in friendly words that he totally
MvdW> disregarded, and he started acting like a whiny bitch when called
MvdW> upon it.
We don't have to drop down to Uno's level.
MvdW> You can go all righteous about the people who finally lost their
MvdW> patience, but I suggest you point your anger at the one that
MvdW> *made* them lose their patience.
I'm not angry or righteous. You're superimposing words and emotions on
my original "let's be civil" message. The message is quoted above.
On Fri, 22 Apr 2011 09:48:35 -0500 Tad McClellan <tadmc@seesig.invalid> wrote:
TM> Imply that I an on drugs again, and I will be uncivil again.
Don't let 'em get to you, is all I'm saying. The world is full of,
well, Unos.
Ted
------------------------------
Date: Fri, 22 Apr 2011 17:19:31 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: grabbing a facebook group
Message-Id: <87d3kend3g.fsf@lifelogs.com>
On Fri, 22 Apr 2011 14:45:09 -0500 John Bokma <john@castleamber.com> wrote:
JB> I am /convinced/ that some people have left this group /because/ of
JB> the virtual dick swinging of some regulars here.
I want NAMES, John, NAMES! We must bring every last one of them back!
(obConfuciusSays: Man walking sideways in airport going to Bangkok.)
Ted
------------------------------
Date: Fri, 22 Apr 2011 18:02:11 -0500
From: John Bokma <john@castleamber.com>
Subject: Re: grabbing a facebook group
Message-Id: <87tydpj3f0.fsf@castleamber.com>
Ted Zlatanov <tzz@lifelogs.com> writes:
> On Fri, 22 Apr 2011 14:45:09 -0500 John Bokma <john@castleamber.com> wrote:
>
> JB> I am /convinced/ that some people have left this group /because/ of
> JB> the virtual dick swinging of some regulars here.
>
> I want NAMES, John, NAMES! We must bring every last one of them back!
Well, I am back, sort of.
--
John Bokma j3b
Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma
Freelance Perl & Python Development: http://castleamber.com/
------------------------------
Date: Sat, 23 Apr 2011 06:39:38 -0700 (PDT)
From: Raymundo <gypark@gmail.com>
Subject: I can't understand a sentence "Look out for implicit assignments in while conditionals" in 'perlsub'
Message-Id: <efc6efbc-e15d-4fde-ae33-73d36ac0c922@k3g2000prl.googlegroups.com>
Hello Perl users,
First of all, I'd have to tell you that I'm not so good at English,
not at Perl either. :-)
I am reading 'perlsub' documents:
http://perldoc.perl.org/perlsub.html
In the section "When to still use local()", it says:
---
Despite the existence of my, there are still three places where the
local operator
still shines. In fact, in these three places, you must use local
instead of my.
1.
You need to give a global variable a temporary value, especially $_.
The global variables, like @ARGV or the punctuation variables, must
be localized with local(). This block reads in /etc/motd, and splits
it up
into chunks separated by lines of equal signs, which are placed in
@Fields .
{
local @ARGV = ("/etc/motd");
local $/ = undef;
local $_ = <>;
@Fields = split /^\s*=+\s*$/;
}
It particular, it's important to localize $_ in any routine that
assigns to it.
Look out for implicit assignments in while conditionals.
2.
...(omitted)...
---
("It particular" seems to be a typing error of "In particular")
Okay, I can (maybe) understand the point of this paragraph:
- I can (and I have to) use local() to localize the global variables
Then, what is the exact meaning of the last sentence?
"Look out for implicit assignments in while conditionals."
I guess "implicit assignments in while contitionals" are referrign to
the code like
while ( <STDIN> ) { ... }
because it is, in fact,
while ( defined ( $_ = <STDIN> ) ) { ... }
right?
First, I found that $_ is NOT localized automatically in the
conditional by assigning some value to $_ before the loop and printing
it after the loop.
Then, does the last sentence (with the sentence before it) mean:
1) It is better practice to localize $_ explicitly in the conditional:
while ( defined ( local $_ = <STDIN> ) ) { ... }
or
2) If I am assigning to $_ in the loop for some reason, I have to
localize $_:
while ( <STDIN> ) { ... local $_ = something; ... }
or
3) just "be aware and cautious, $_ isn't be localized automatically"
or
4) I am totally missing the point now :-/ It means something else
??
Any help will be appreciated.
------------------------------
Date: Sat, 23 Apr 2011 11:03:27 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: I can't understand a sentence "Look out for implicit assignments in while conditionals" in 'perlsub'
Message-Id: <slrnir5tpl.8n9.tadmc@tadbox.sbcglobal.net>
Raymundo <gypark@gmail.com> wrote:
> I am reading 'perlsub' documents:
> http://perldoc.perl.org/perlsub.html
> Look out for implicit assignments in while conditionals.
> I guess "implicit assignments in while contitionals" are referrign to
> the code like
> while ( <STDIN> ) { ... }
> because it is, in fact,
> while ( defined ( $_ = <STDIN> ) ) { ... }
> right?
Exactly right.
> Then, does the last sentence (with the sentence before it) mean:
>
> 1) It is better practice to localize $_ explicitly in the conditional:
> while ( defined ( local $_ = <STDIN> ) ) { ... }
It is even better practice to avoid package variables altogether!
while (my $line = <STDIN>) {
I teach this rule:
Always prefer lexical variables (my) over package
variables (local, our), except when you can't.
> 2) If I am assigning to $_ in the loop for some reason, I have to
> localize $_:
> while ( <STDIN> ) { ... local $_ = something; ... }
Yep, that is what you have to "look out" for (unless you use
a lexical variable rather than a package variable).
> Any help will be appreciated.
See also:
http://perl.plover.com/FAQs/Namespaces.html#What_Good_is_C_local_
Note also, that starting with perl 5.10, you can make $_ lexical:
while (my $_ = <STDIN>) {
See the "Lexical $_" heading in perldelta.pod from a recent perl
version.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
Date: Fri, 22 Apr 2011 15:25:10 -0700
From: sln@netherlands.com
Subject: Re: parsing a command line, but not the usual problem
Message-Id: <sjv3r6pkljhtqq2lp4uoh9459d8mkt0vat@4ax.com>
On Tue, 19 Apr 2011 22:11:53 +0000 (UTC), Eli the Bearded <*@eli.users.panix.com> wrote:
>In comp.lang.perl.misc, Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>> >>>>> "EtB" == Eli the Bearded <*@eli.users.panix.com> writes:
>> EtB> Are there any modules that can help me with this breed of command
>> EtB> parsing? Regular command line parsing is dominating my search results.
>> EtB> I would like to be able to do variable expansion in double-quoted
>> EtB> strings and no expansion in single-quoted ones. I am not interested
>> EtB> in file globbing.
>>
>> Looks like Shell::Parser could do it, although it might be overkill.
>
>It's not exactly what I wanted, but it is a good start. I might just
>borrow code from it rather than use it directly.
>
>#!/usr/bin/perl -w
>use Shell::Parser;
>use strict;
>
>my $parser = new Shell::Parser handlers => { default => \&dumpnode };
>sub dumpnode {
> my $self = shift;
> my %args = @_;
>
> print "$args{type}: <$args{token}>\n"
>}
>$parser->parse(q*echo "The $cow \"jumps\" over "'the $moon' && $again*);
>__END__
>
>Gives me:
>
>text: <echo>
>text: < >
>text: <"The $cow \"jumps\" over "'the $moon'>
>text: < >
>text: < >
>metachar: <&>
>metachar: <&>
>text: < >
>text: < >
>variable: <$again>
>
>The flagging of IFS whitespace as text might be right for what this
>was written for, but it isn't right for me. Also I'd have wanted to
>see:
>
>dquoted: <The $cow "jumps" over >
>squoted: <the $moon>
>
It appears you are trying to do more language parsing than shell type.
For example, some of the command line parsing in Windows is just outright bizzarr.
I like your lex/yapp aproach though (in a later post). Below is a bizzar example of
the way you could sucessfully parse string like behavior, amidst whitespace delimeters,
albeit, admittedly far removed from a shell command processor.
Let me know if I can help you out on this.
-sln
-------------------------
use strict;
use warnings;
chomp (my $data = <DATA>);
print "\n$data\n\n";
my (@parsed, $dtype);
1 while ($data =~ /
(?:
( (?: [^'"\s]+
| (?!\s) (?! '[^'\\]*(?:\\.[^'\\]*)*' | "[^"\\]*(?:\\.[^"\\]*)*" )
['"]
)+
) (?{ $dtype = 'text' })
| '([^'\\]*(?:\\.[^'\\]*)*)' (?{ $dtype = 'squoted' })
| "([^"\\]*(?:\\.[^"\\]*)*)" (?{ $dtype = 'dquoted' })
| (\s+) (?{ $dtype = 'ws' })
)
(?{ push @parsed, ($dtype,$^N) })
/xsg);
## done parse, do post processing
## and show results ( I hate c-style for() )
my $filter = "text|squoted|dquoted|ws"; # show these. apparently, nothing is filtered
for (my $i = 0; $i <= $#parsed; $i+=2)
{
next if $parsed[$i] !~ /^(?:$filter)$/;
printf "%-8s <%s>\n", postproc( @parsed[$i, $i+1] );
}
##
sub postproc {
my ($type, $str) = @_;
if ($type eq "dquoted") {
$str =~ s/\\(.)/$1/g;
}
elsif ($type eq "squoted") {
$str =~ s/\\([\\'])/$1/g;
}
elsif ($type eq "text") {
# process text
}
return ($type,$str);
}
__DATA__
\echo "The \$cow \"jumps\" over "'the $moon' && \$again* 'hello wo\'rld
Output:
\echo "The \$cow \"jumps\" over "'the $moon' && \$again* 'hello wo\'rld
text <\echo>
ws < >
dquoted <The $cow "jumps" over >
squoted <the $moon>
ws < >
text <&&>
ws < >
text <\$again*>
ws < >
text <'hello>
ws < >
text <wo\'rld>
------------------------------
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 3363
***************************************