[30675] in Perl-Users-Digest
Perl-Users Digest, Issue: 1920 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 13 14:09:57 2008
Date: Mon, 13 Oct 2008 11:09:24 -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 Mon, 13 Oct 2008 Volume: 11 Number: 1920
Today's topics:
'extracting' from a string via regular expressions? sseelenluft@gmail.com
Re: 'extracting' from a string via regular expressions? <josef.moellers@fujitsu-siemens.com>
Re: 'extracting' from a string via regular expressions? sseelenluft@gmail.com
Re: 'extracting' from a string via regular expressions? <klaus03@gmail.com>
Re: 'extracting' from a string via regular expressions? <jurgenex@hotmail.com>
Re: 'extracting' from a string via regular expressions? <smallpond@juno.com>
Re: 'extracting' from a string via regular expressions? <tadmc@seesig.invalid>
can't run "devenv" in Perl <slick.users@gmail.com>
Re: can't run "devenv" in Perl <jurgenex@hotmail.com>
Re: FAQ 4.19 How do I validate input? <brian.d.foy@gmail.com>
Re: FAQ 4.24 How do I reverse a string? <brian.d.foy@gmail.com>
Re: FAQ 4.24 How do I reverse a string? <jurgenex@hotmail.com>
Re: FAQ 4.24 How do I reverse a string? <tadmc@seesig.invalid>
Re: finding newest file in a directory and removing the <beefstu350@hotmail.com>
Re: finding newest file in a directory and removing the <tadmc@seesig.invalid>
Re: finding newest file in a directory and removing the <jurgenex@hotmail.com>
Re: finding newest file in a directory and removing the <beefstu350@hotmail.com>
Help: How to process output of a program <openlinuxsource@gmail.com>
Re: Help: How to process output of a program <josef.moellers@fujitsu-siemens.com>
Re: Help: How to process output of a program <openlinuxsource@gmail.com>
Re: Help: How to process output of a program <jurgenex@hotmail.com>
Re: Help: How to process output of a program <tadmc@seesig.invalid>
Re: mod_perl <jcarlock@127.0.0.1>
Re: mod_perl <glex_no-spam@qwest-spam-no.invalid>
Re: Odd behaviour with has key - wide character <jcombe@gmail.com>
Re: Odd behaviour with has key - wide character xhoster@gmail.com
Re: Parsing CSV and " " sln@netherlands.com
Re: Problem with perlsax splitting the calls to charact <RedGrittyBrick@spamweary.invalid>
Re: Problem with perlsax splitting the calls to charact <tadmc@seesig.invalid>
Re: Want true instantiated objects from XML <newsbot@cox.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 13 Oct 2008 07:53:34 -0700 (PDT)
From: sseelenluft@gmail.com
Subject: 'extracting' from a string via regular expressions?
Message-Id: <057b97c0-ce7b-4b72-84a4-9474f98ca7e8@d45g2000hsc.googlegroups.com>
Hi,
I was modifying code written by others when something stopped working.
I was using a construct like:
$string=~ m@PartOne(.*)PartTwo@;
to find and extract everything between 'PartOne' and 'PartTwo', and I
swear it was working. Then I moved to a different string and it
stopped working (and now the first example also stopped working).
Below is a not-working test-case:
#! /usr/bin/perl
use strict;
# Definition of variables
my $line;
my $file;
# Read file
@ARGV = qw# test2.csv #;
while (defined($line = <>)) {
$file .= $line;
}
$file=~ m@TEMPLATES(.*)ONLY@;
print $file . "\n";
The file test2.csv contains just one sentence: 'IMPORTANT: THESE
TEMPLATES MAY ONLY BE USED WITH THE WRITTEN PERMISSION'
Therefore, the code above should print simply 'MAY' (possibly with the
spaces), but it prints the whole sentence.
Finding the word 'TEMPLATES' works fine, a la:
if ($file=~ m@TEMPLATES@) {
print "It matched!" . "\n";
}
works fine.
So, what am I missing here?
Thanks.
------------------------------
Date: Mon, 13 Oct 2008 17:05:22 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: 'extracting' from a string via regular expressions?
Message-Id: <gcvo3c$k04$2@nntp.fujitsu-siemens.com>
sseelenluft@gmail.com wrote:
> Hi,
> I was modifying code written by others when something stopped working.
> I was using a construct like:
> $string=~ m@PartOne(.*)PartTwo@;
> to find and extract everything between 'PartOne' and 'PartTwo', and I
> swear it was working. Then I moved to a different string and it
> stopped working (and now the first example also stopped working).
> Below is a not-working test-case:
>
> #! /usr/bin/perl
>
> use strict;
>
> # Definition of variables
> my $line;
> my $file;
>
> # Read file
> @ARGV = qw# test2.csv #;
> while (defined($line = <>)) {
> $file .= $line;
> }
>
> $file=~ m@TEMPLATES(.*)ONLY@;
This expression matches the contents of $file against the given RE.
It does not modify $file.
>
> print $file . "\n";
print $1, "\n";
Josef
--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
------------------------------
Date: Mon, 13 Oct 2008 08:28:23 -0700 (PDT)
From: sseelenluft@gmail.com
Subject: Re: 'extracting' from a string via regular expressions?
Message-Id: <8270907c-9563-4d6e-8f13-4083d0da5921@79g2000hsk.googlegroups.com>
> > $file=~ m@TEMPLATES(.*)ONLY@;
>
> This expression matches the contents of $file against the given RE.
> It does not modify $file.
Ah, your are right, when I thought it was working (ie, when I thought
this expression really extracts the content), I was inadvertently also
doing a print of another variable which had $1 assigned to itself, and
I had thought I was only printing $file (and because of the really
long output I only looked at the last lines).
Thanks.
(I guess, I should do a commit to a version control system every time
I hit the save button, otherwise I think something was working when it
fact something else was working.)
------------------------------
Date: Mon, 13 Oct 2008 08:28:26 -0700 (PDT)
From: Klaus <klaus03@gmail.com>
Subject: Re: 'extracting' from a string via regular expressions?
Message-Id: <53e0ac25-85a8-4ef5-b8b1-463435b86bac@l76g2000hse.googlegroups.com>
On Oct 13, 4:53=A0pm, sseelenl...@gmail.com wrote:
> $file=3D~ m@TEMPLATES(.*)ONLY@;
> print $file . "\n";
if ($file=3D~ m@TEMPLATES(.*)ONLY@) {
print "found '$1' in file '$file'\n";
}
else {
print "nothing found in file '$file'\n";
}
------------------------------
Date: Mon, 13 Oct 2008 08:53:02 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: 'extracting' from a string via regular expressions?
Message-Id: <cfr6f4pmkdr0qq606tgbve3li5mh09f6n0@4ax.com>
sseelenluft@gmail.com wrote:
>$file=~ m@TEMPLATES(.*)ONLY@;
>print $file . "\n";
>The file test2.csv contains just one sentence: 'IMPORTANT: THESE
>TEMPLATES MAY ONLY BE USED WITH THE WRITTEN PERMISSION'
>Therefore, the code above should print simply 'MAY' (possibly with the
>spaces), but it prints the whole sentence.
You need to tell Perl to print the matched part only instead of the
whole line. And you should use the $-number variables only if the match
was successfull:
if ($file=~ m@TEMPLATES(.*)ONLY@) {
print "$1\n";
}
jue
------------------------------
Date: Mon, 13 Oct 2008 09:04:54 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: 'extracting' from a string via regular expressions?
Message-Id: <3a75a165-9d71-4697-9e6a-ebf4967f93b1@m44g2000hsc.googlegroups.com>
On Oct 13, 10:53 am, sseelenl...@gmail.com wrote:
> @ARGV = qw# test2.csv #;
Wouldn't open be simpler? That way you can actually check
whether it worked.
------------------------------
Date: Mon, 13 Oct 2008 11:08:40 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: 'extracting' from a string via regular expressions?
Message-Id: <slrngf6sk8.lpo.tadmc@tadmc30.sbcglobal.net>
sseelenluft@gmail.com <sseelenluft@gmail.com> wrote:
> # Definition of variables
> my $line;
> my $file;
You are not defining variables there.
You are declaring variables there.
"defining" in not the same thing as "declaring".
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Mon, 13 Oct 2008 10:29:01 -0700 (PDT)
From: Slickuser <slick.users@gmail.com>
Subject: can't run "devenv" in Perl
Message-Id: <df393cbe-1ef3-4449-950f-d49ca6f534b9@i20g2000prf.googlegroups.com>
Hi,
How can I fixed the error below so that I can run "devenv" in Perl?
Thanks.
setVSEnv();
system("devenv /Build Debug \"ProjectABC.sln\" /out \"C:/log_out.txt
\");
Error:
Setting environment for using Microsoft Visual Studio 2005 x86 tools.
'devenv' is not recognized as an internal or external command,
operable program or batch file.
sub setVSEnv
{
## VS 2005
my $VS_Path = $ENV{'VS80COMNTOOLS'};
if (defined($VS_Path))
{
system("call \"%vs80comntools%vsvars32.bat\" ");
}
else
{
## VS 2003
$VS_Path = $ENV{'VS71COMNTOOLS'};
if (!defined($VS_Path))
{
print STDERR "Visual Studio doesn't exist.\n";
exit(0);
}
system("call \"%vs71comntools%vsvars32.bat\" ");
}
}
------------------------------
Date: Mon, 13 Oct 2008 10:57:10 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: can't run "devenv" in Perl
Message-Id: <6s27f451j8515qe3iipdg6dii53abe1r02@4ax.com>
Slickuser <slick.users@gmail.com> wrote:
>How can I fixed the error below so that I can run "devenv" in Perl?
>
>setVSEnv();
>system("devenv /Build Debug \"ProjectABC.sln\" /out \"C:/log_out.txt
>\");
>
>Error:
>Setting environment for using Microsoft Visual Studio 2005 x86 tools.
>'devenv' is not recognized as an internal or external command,
>operable program or batch file.
Two possibilities:
- add the directory that contains devenv.<whatever> to your path
- calll devenv.<whatever> using the absolute path rather then the
relative local path
jue
------------------------------
Date: Mon, 13 Oct 2008 12:02:35 -0400
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 4.19 How do I validate input?
Message-Id: <131020081202352606%brian.d.foy@gmail.com>
In article <fgr4f4p4h96c33pl8vdagdl5quo0cmkfca@4ax.com>,
<sln@netherlands.com> wrote:
> On Sun, 12 Oct 2008 12:03:01 -0700, PerlFAQ Server <brian@stonehenge.com>
> wrote:
> Oh come on. ASSERT and validate? I can just imagine the overhead
> via Perl these would take in an effort to more and more, make it look
> and feel like C/C++. This makes me sick...
It doesn't look or feel like C++ necessarily. People have just chosen
those names for their modules.
So, go off and be sick with some other language.
------------------------------
Date: Mon, 13 Oct 2008 12:00:50 -0400
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 4.24 How do I reverse a string?
Message-Id: <131020081200506298%brian.d.foy@gmail.com>
In article <sbf4f4h3shti71h7jd5l0jdja6pnqa8qav@4ax.com>,
<sln@netherlands.com> wrote:
> On Sun, 12 Oct 2008 09:58:43 -0400, brian d foy <brian.d.foy@gmail.com>
> wrote:
> I still find it disturbing strings can't be manipulated directly.
> I bet there's alot of pressure to make that ability available.
> When you need to do it, you just need to.
Are you just trolling or is there something you really don't know how
to do?
------------------------------
Date: Mon, 13 Oct 2008 09:20:43 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: FAQ 4.24 How do I reverse a string?
Message-Id: <d4t6f41teotho6ll1d95n6io4psnv7t87d@4ax.com>
sln@netherlands.com wrote:
>I still find it disturbing strings can't be manipulated directly.
I don't understand. There are several fuctions that manipulate strings
directly (see perldoc perlfunc), could you elaborate, please?
>I bet there's alot of pressure to make that ability available.
>When you need to do it, you just need to.
To make _WHAT_ available?
>The fact is, this turn's off C programmers instead of attracting them.
>Let me tell you right now, C programers don't use "substr()" in C, they
>just don't. Perl's string manipulation functions are useless.
I find chomp, uc, sprintf, and their cousins very useful.
jue
------------------------------
Date: Mon, 13 Oct 2008 11:09:43 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: FAQ 4.24 How do I reverse a string?
Message-Id: <slrngf6sm7.lpo.tadmc@tadmc30.sbcglobal.net>
brian d foy <brian.d.foy@gmail.com> wrote:
> In article <sbf4f4h3shti71h7jd5l0jdja6pnqa8qav@4ax.com>,
><sln@netherlands.com> wrote:
>
>> On Sun, 12 Oct 2008 09:58:43 -0400, brian d foy <brian.d.foy@gmail.com>
>> wrote:
>
>> I still find it disturbing strings can't be manipulated directly.
>> I bet there's alot of pressure to make that ability available.
>> When you need to do it, you just need to.
>
> Are you just trolling or is there something you really don't know how
> to do?
It is just trolling, as usual.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Mon, 13 Oct 2008 09:12:52 -0700 (PDT)
From: Stu <beefstu350@hotmail.com>
Subject: Re: finding newest file in a directory and removing the rest
Message-Id: <99ac1b8a-6c0d-4ab5-b93e-6126cfe982ce@m3g2000hsc.googlegroups.com>
On Oct 10, 12:14=A0pm, Tad J McClellan <ta...@seesig.invalid> wrote:
> Stu <beefstu...@hotmail.com> wrote:
> > I was wondering if somebody can point me in the right direction?
>
> > I have a requirement to remove all the files in a given directory
> > except for the one that has been
> > created last.
>
> That is only possible on file systems that keep track of
> a file's creation time.
>
> Most *nix filesystems do not record creation time at all.
>
> If you can live with modification time instead of creation time,
> then this should do it:
>
> =A0 =A0 my(undef, @f) =3D sort { -M $a <=3D> -M $b } grep -f, glob '*';
> =A0 =A0 unlink @f;
>
> (but that does not remove all old files, old files that start
> =A0with a dot will be left alone.
> )
>
> --
> Tad McClellan
> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
Thanks for the response but I am not too sure I understand what this
statement is doing.
When I do this:
@f =3D sort { -M $a <=3D> -M $b } grep -f, glob </axsma/pbh/var/proc/pbh40/
*>;
foreach $file (@f)
{
print $file . "\n";
}
I get I only get one file as the output yet there are several files in
the above-mentioned directory. I would have thought I would have
gotten back all the files in the directory in sorted order by modtime
or creation time.
The file I did get back appears to have a time associated with it that
is in the middle of all my files
Oct 1 15:08 newest file
Sep 19 10:40 time associated with the file that was returned
Jul 18 11:21 older file
How come the older or the newer file was not returned?
Once again thanks for the help
------------------------------
Date: Mon, 13 Oct 2008 11:14:31 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: finding newest file in a directory and removing the rest
Message-Id: <slrngf6sv7.lpo.tadmc@tadmc30.sbcglobal.net>
Stu <beefstu350@hotmail.com> wrote:
> On Oct 10, 12:14 pm, Tad J McClellan <ta...@seesig.invalid> wrote:
>> Stu <beefstu...@hotmail.com> wrote:
>> > I was wondering if somebody can point me in the right direction?
>>
>> > I have a requirement to remove all the files in a given directory
>> > except for the one that has been
>> > created last.
>>
>> That is only possible on file systems that keep track of
>> a file's creation time.
>>
>> Most *nix filesystems do not record creation time at all.
>>
>> If you can live with modification time instead of creation time,
>> then this should do it:
>>
>> my(undef, @f) = sort { -M $a <=> -M $b } grep -f, glob '*';
>> unlink @f;
>>
>> (but that does not remove all old files, old files that start
>> with a dot will be left alone.
>> )
>>
>> --
>> Tad McClellan
>> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
It is bad form to quote .sigs. Please do not do that.
You should also trim irrelevant text, and interleave your comments.
If you are going to comment on one line of code, then you should
quote only the one line of code that you are going to comment on.
> Thanks for the response but I am not too sure I understand what this
> statement is doing.
>
> When I do this:
>
> @f = sort { -M $a <=> -M $b } grep -f, glob </axsma/pbh/var/proc/pbh40/
> *>;
You are calling glob() *twice*.
Once with its name, and once with its alternate form.
Call it only once instead:
@f = sort { -M $a <=> -M $b } grep -f, </axsma/pbh/var/proc/pbh40/*>;
or, better
@f = sort { -M $a <=> -M $b } grep -f, glob '/axsma/pbh/var/proc/pbh40/*';
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Mon, 13 Oct 2008 09:36:29 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: finding newest file in a directory and removing the rest
Message-Id: <est6f49109nbab5lk1vtbn9kq70c1hdvg0@4ax.com>
Stu <beefstu350@hotmail.com> wrote:
>@f = sort { -M $a <=> -M $b } grep -f, glob </axsma/pbh/var/proc/pbh40/
>*>;
>
>I get I only get one file as the output yet there are several files in
>the above-mentioned directory. I would have thought I would have
This is a neat one :-))
You are double globbing. Either drop the glob() call or replace the
angle brackets with paranthesis.
jue
------------------------------
Date: Mon, 13 Oct 2008 09:40:59 -0700 (PDT)
From: Stu <beefstu350@hotmail.com>
Subject: Re: finding newest file in a directory and removing the rest
Message-Id: <f51881cb-4a9e-4a8a-b97e-f20779e0a213@g61g2000hsf.googlegroups.com>
On Oct 13, 12:14=A0pm, Tad J McClellan <ta...@seesig.invalid> wrote:
> Stu <beefstu...@hotmail.com> wrote:
> > On Oct 10, 12:14=A0pm, Tad J McClellan <ta...@seesig.invalid> wrote:
> >> Stu <beefstu...@hotmail.com> wrote:
> >> > I was wondering if somebody can point me in the right direction?
>
> >> > I have a requirement to remove all the files in a given directory
> >> > except for the one that has been
> >> > created last.
>
> >> That is only possible on file systems that keep track of
> >> a file's creation time.
>
> >> Most *nix filesystems do not record creation time at all.
>
> >> If you can live with modification time instead of creation time,
> >> then this should do it:
>
> >> =A0 =A0 my(undef, @f) =3D sort { -M $a <=3D> -M $b } grep -f, glob '*'=
;
> >> =A0 =A0 unlink @f;
>
> >> (but that does not remove all old files, old files that start
> >> =A0with a dot will be left alone.
> >> )
>
> >> --
> >> Tad McClellan
> >> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
>
> It is bad form to quote .sigs. Please do not do that.
>
> You should also trim irrelevant text, and interleave your comments.
>
> If you are going to comment on one line of code, then you should
> quote only the one line of code that you are going to comment on.
>
> > Thanks for the response but I am not too sure I understand what this
> > statement is doing.
>
> > When I do this:
>
> > @f =3D sort { -M $a <=3D> -M $b } grep -f, glob </axsma/pbh/var/proc/pb=
h40/
> > *>;
>
> You are calling glob() *twice*.
>
> Once with its name, and once with its alternate form.
>
> Call it only once instead:
>
> =A0 =A0@f =3D sort { -M $a <=3D> -M $b } grep -f, </axsma/pbh/var/proc/pb=
h40/*>;
> or, better
> =A0 =A0@f =3D sort { -M $a <=3D> -M $b } grep -f, glob '/axsma/pbh/var/pr=
oc/pbh40/*';
>
> --
> Tad McClellan
> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"- Hid=
e quoted text -
>
> - Show quoted text -
Thanks for all your help. That was it
------------------------------
Date: Mon, 13 Oct 2008 22:34:35 +0800
From: Amy Lee <openlinuxsource@gmail.com>
Subject: Help: How to process output of a program
Message-Id: <pan.2008.10.13.14.34.35.828734@gmail.com>
Hello,
How to process output of a program? For example, I want to parse the
output of /sbin/lspci program.
Thanks.
Amy
------------------------------
Date: Mon, 13 Oct 2008 17:03:37 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Help: How to process output of a program
Message-Id: <gcvo03$k04$1@nntp.fujitsu-siemens.com>
Amy Lee wrote:
> Hello,
>
> How to process output of a program? For example, I want to parse the
> output of /sbin/lspci program.
if (open(my $lspci, '/sbin/lspci |')) {
while (<$lspci>) {
# process $_
}
close $lspci;
}
--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
------------------------------
Date: Mon, 13 Oct 2008 23:41:48 +0800
From: Amy Lee <openlinuxsource@gmail.com>
Subject: Re: Help: How to process output of a program
Message-Id: <pan.2008.10.13.15.41.48.437959@gmail.com>
On Mon, 13 Oct 2008 17:03:37 +0200, Josef Moellers wrote:
> Amy Lee wrote:
>> Hello,
>>
>> How to process output of a program? For example, I want to parse the
>> output of /sbin/lspci program.
>
> if (open(my $lspci, '/sbin/lspci |')) {
> while (<$lspci>) {
> # process $_
> }
> close $lspci;
> }
Really thanks.
Amy
------------------------------
Date: Mon, 13 Oct 2008 08:47:18 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Help: How to process output of a program
Message-Id: <liq6f4ln929n306m5qk1mm27v3qul9n8rh@4ax.com>
Amy Lee <openlinuxsource@gmail.com> wrote:
>How to process output of a program? For example, I want to parse the
>output of /sbin/lspci program.
You run the program and capture its output, using e.g. qx (aka
backticks) or open() into a pipe.
From the documentation:
qx/STRING/
`STRING`
A string which is [...] executed as a
system command with "/bin/sh" or its equivalent. [...] The
collected standard output of the command is returned;
open(): [...] if MODE is "'-|'", the filename
is interpreted as a command which pipes output to us.
Further details please see there.
On a side note: what kind of Perl tutorial/reference/documentation are
you using? You are asking _A_LOT_ of very beginner style questions,
which are typically covered quite early in any Perl tutorial or
reference book that I have seen. E.g. my copy of "Programming Perl"
explains backticks on page 52 out of over 600 pages, that is this topic
is covered within the first 10% of the book.
jue
------------------------------
Date: Mon, 13 Oct 2008 11:16:09 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Help: How to process output of a program
Message-Id: <slrngf6t29.lpo.tadmc@tadmc30.sbcglobal.net>
Amy Lee <openlinuxsource@gmail.com> wrote:
> On Mon, 13 Oct 2008 17:03:37 +0200, Josef Moellers wrote:
>
>> Amy Lee wrote:
>>> Hello,
>>>
>>> How to process output of a program? For example, I want to parse the
>>> output of /sbin/lspci program.
>>
>> if (open(my $lspci, '/sbin/lspci |')) {
>> while (<$lspci>) {
>> # process $_
>> }
>> close $lspci;
>> }
> Really thanks.
Shown above is one of the three ways of running an external
program from within Perl.
If you would like to know about all three of them, you can
start with:
perldoc -q external
How can I capture STDERR from an external command?
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Mon, 13 Oct 2008 12:58:18 -0400
From: "Jim Carlock" <jcarlock@127.0.0.1>
Subject: Re: mod_perl
Message-Id: <48f37e30$0$5466$9a6e19ea@unlimited.newshosting.com>
Jim Carlock wrote:
: >
: > I need some further help in configuring security for mod_perl and Apache.
: > Any help, assistance or other is greatly appreciated. Thank you much well
: > in advance.
"J. Gleixner" wrote...
:
: There are many sites on the Internet to help you configure your Web
: server, and it's not something discussed in this newsgroup.
:
: http://perl.apache.org/
Well, if I've got the wrong newsgroup let me know. Please point me to
the right newsgroup. comp.lang.perl.misc means installing Perl as far
as I can tell, and mod_perl IS Perl. Installing falls into the "misc"
category, I think. In the manner of not trying to argue, I'll provide
some code too.
The following presents some my initial attempts at writing my first
Perl function and first webpage written in HTML first, then converted
to getting output by Perl with the print() function. It works I hope.
It also displays the first function created. I make no claims to the
quality of the code. Feel free to comment. I look forward to all
comments, criticisms. Nothing to lose and a lot to gain.
http://www.microcosmotalk.com/tech/mod_perl/
Now back to mod_perl. mod_perl is installed as follows in my
httpd.conf file.
<snip file="httpd.conf">
# mod_perl 5.8 build
# LoadFile "C:/Program Files/ActiveState/Perl/bin/perl58.dll"
# mod_perl 5.10 build
LoadFile "C:/Program Files/ActiveState/Perl/bin/perl510.dll"
LoadModule perl_module modules/mod_perl.so
# ...
# ...
# other Apache directives
# ...
# ...
<IfModule alias_module>
<IfModule mime_module>
# ...
# ...
# ...
<Files ~ "\.(pl|plx)$">
# DefaultType text/html # This DOES NOT work/commented out
SetHandler perl-script
Options ExecCGI
PerlHandler ModPerl::Registry
PerlSendHeader On
# PerlTaintCheck On # This does NOT work/commented out
# PerlWarn On # This does NOT work/commented out
</Files>
</IfModule>
</IfModule>
# ...
# ...
# ...
</snip>
--
Jim Carlock
Ralph Nader Only Has A Chance If YOU Vote For Him
http://www.votenader.org/
------------------------------
Date: Mon, 13 Oct 2008 12:32:26 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: mod_perl
Message-Id: <48f3862a$0$87065$815e3792@news.qwest.net>
Jim Carlock wrote:
> Jim Carlock wrote:
> : >
> : > I need some further help in configuring security for mod_perl and Apache.
> : > Any help, assistance or other is greatly appreciated. Thank you much well
> : > in advance.
>
> "J. Gleixner" wrote...
> :
> : There are many sites on the Internet to help you configure your Web
> : server, and it's not something discussed in this newsgroup.
> :
> : http://perl.apache.org/
>
> Well, if I've got the wrong newsgroup let me know.
I've already done that, yet here you are. Your initial post said that
you needed help 'configuring security for mod_perl and Apache.' Since
you don't actually ask any specific questions, I suggested you
start with the URL above, which should cover many different
mod_perl related subjects, including 'Getting Help'. I guess I
should have also pointed you to the documentation for apache:
http://httpd.apache.org/
If you have a specific question about your Perl code, then post
it, if it's about configuring apache, then there are other more
appropriate newsgroups and you should be able to find them on
your own.
> Please point me to
> the right newsgroup. comp.lang.perl.misc means installing Perl as far
> as I can tell, and mod_perl IS Perl.
OK. My ESP hasn't been upgraded in a while. What problems are you
having when installing Perl?
[...]
>
> Now back to mod_perl. mod_perl is installed as follows in my
> httpd.conf file.
Again, it's not 'installed' by your httpd.conf file. It should
already be 'installed' on your machine before you can use it.
What is your question?
------------------------------
Date: Mon, 13 Oct 2008 07:51:57 -0700 (PDT)
From: Jon Combe <jcombe@gmail.com>
Subject: Re: Odd behaviour with has key - wide character
Message-Id: <985b7ac5-76b6-4294-be5b-c229d1a4013b@l62g2000hse.googlegroups.com>
> you're running into version string. Since 5.8, perl handles
> vX.Y.Z... where X Y and Z are numbers specially (this is considered a
> failed experiment by many people).
>
> note that any other letter would have caused an error under "strict":
>
> use strict;
> %h = ( b123, 3);
>
> Global symbol "%h" requires explicit package name at - line 2.
> Bareword "b123" not allowed while "strict subs" in use at - line 2.
> Execution of - aborted due to compilation errors.
>
> you should either manually quote the keys of a hash, or use the
> auto-quoting => operator:
>
> use strict;
> my %h = ( v123 => 3 );
>
> Note that even using => will not work correctly at 5.8.0: you should
> really upgrade your perl if you've got that version, since it has lots
> of bugs.
>
Thank you Joost. I tried with the quoting operator (=>) as you
suggested but it didn't work, but this is because I do have Perl
5.8.0. Sadly I am not the administrator of the system so I don't think
that I will be able to change it. I cannot find any mention of
"Version Strings" in the perldata documentation. Is that the correct
page or was it not documented in 5.8.0?
Jon.
------------------------------
Date: 13 Oct 2008 15:42:48 GMT
From: xhoster@gmail.com
Subject: Re: Odd behaviour with has key - wide character
Message-Id: <20081013114250.065$LP@newsreader.com>
RedGrittyBrick <RedGrittyBrick@spamweary.invalid> wrote:
> Jon Combe wrote:
> > Does the letter "v" have any significance when creating a hash key?
> > The following code snippet does not behave as I expect it to:-
> >
> > #!/usr/bin/perl -w
> >
> > %H = (v365, 3);
> > print keys %H;
> >
> > When run it outputs
> >
> > Wide character in print at wide.pl line 4.
> > Å
> >
> > When the key name is changed to "va365" it prints "va365" as I expect.
> > What is special about just v followed by numbers?
> >
>
> Have you tried it with "use strict;"?
<The original post didn't show up for me>
And more importantly, read the section on Version Strings in perldoc
perldata.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Mon, 13 Oct 2008 16:28:14 GMT
From: sln@netherlands.com
Subject: Re: Parsing CSV and " "
Message-Id: <3pr6f4dsjtu2unt0505mk22tv5ebfjsc6b@4ax.com>
On Sat, 11 Oct 2008 21:47:27 GMT, sln@netherlands.com wrote:
[snip]
Small change's ..
- For performance, the transliteration was changed to count $tmp string.
- Added the span modifier on the regex loop.
Thus the option below to keep newlines, and have the original formatting intact,
ie: bullet point location's etc...
Just (un)comment the block that is needed. Try it both ways.
#############
# Csv3 Regex
#############
# http://www.nasdaq.com//asp/symbols.asp?exchange=Q&start=0
use strict;
use warnings;
my $fname = 'c:\temp\symbols.csv';
open CSV, $fname or die "can't open $fname...";
my ($row, $tmp) = ('','');
my ($parsing, $records, $quotes) = (1,1,0);
while ($parsing)
{
## Buffer until a full row
## -------------------------
if (!($_ = <CSV>)) {
$parsing = 0; # eof, parse what's left
} else {
$tmp = $_;
## this block will trim newlines ---
$tmp =~ s/\s+$//s;
next if (!length($tmp));
$row .= " $tmp";
## ---
## this block will keep newlines ---
# $row .= $tmp;
## ---
$quotes += $tmp =~ tr/"//;
next if (!($quotes % 2 == 0)); # Even number of double quotes?
} # Good to go, parse it ...
print " (".$records++.") ----------\n";
## Parse the row
## -------------------
while ($row =~ /\s*"\s*([^"]*?)\s*"\s*,|\s*"\s*(.*?)\s*"\s*$/gs) # span lines
{
my $val = $1;
if (defined $2) {
# cleanup the description field
# ------------------------------
$val = $2;
$val =~ s/""/"/g;
$val =~ s/\.\.\. More\.\.\.//ig;
$val =~ s/ / /ig;
}
print "val = $val\n";
}
$row = '';
$quotes = 0;
}
close CSV;
__END__
------------------------------
Date: Mon, 13 Oct 2008 14:08:59 +0100
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: Problem with perlsax splitting the calls to characters callback
Message-Id: <48f34870$0$24338$db0fefd9@news.zen.co.uk>
raga wrote:
> On Oct 13, 5:06 pm, RedGrittyBrick <RedGrittyBr...@spamweary.invalid>
> wrote:
>> raga wrote:
>>> From the link given here :
>>> http://search.cpan.org/~kmacleod/libxml-perl-0.08/doc/PerlSAX.pod
>>> Perl sax seems to split the characters call for a single entity.
>>> Though this is wierd.(not sure if there is a genuine reason) it is
>>> fine.. as all belong to same entity, we can simply append all the
>>> characters calls.
>> The URL you provide says this:
>>
>> "The Parser will call this method to report each chunk of character
>> data. SAX parsers may return all contiguous character data in a single
>> chunk, or they may split it into several chunks;"
>>
>>> However ,sadly it just calls the characters api with an unwanted
>>> space.
>>> Eg: i've tag < tag1>mynameisrs</tag>
>> That isn't well formed XML and so cant be parsed.
>> 1. you have a space in front of the firts tag name.
>> 2. you open tag1 but close tag.
>>
>>> it calls characters("myname") characters(" ") characters("isrs") ,
>>> It is not atall predictible why it is doing this way.
>> In my experience it is always sufficiently predictable. Probably your
>> mynameisrs data is split over several lines and you've not written your
>> handler to take this into account.
>> [perl program omitted]
>
> sorry for the wrong input provided earlier.. it was my hurry to type
> quickly
> i intended to type <tag>mynameisrs</tag>
>
> Yes, the perlsax occasionally splits the chars to multiple calls. ur
> snip doesnt seems to handle it!.
My program wasn't intended to handle it, it was intended to show that no
unexpected space characters are inserted.
> My actual query is in addition to the calls made to the charchters api
> with the split chunks, it randomly calls the characters API with a
> unwanted space..
It never does for me!
Create and post a short working program that shows it!
--
RGB
------------------------------
Date: Mon, 13 Oct 2008 09:39:09 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Problem with perlsax splitting the calls to characters callback
Message-Id: <slrngf6ncd.klm.tadmc@tadmc30.sbcglobal.net>
raga <rsasanka@gmail.com> wrote:
> sorry for the wrong input provided earlier.. it was my hurry to type
> quickly
You should not attempt to type code or data at all.
You should instead copy/paste it so that you do not insert
errors that are not in your real code or data.
Please see the Posting Guidelines that are posted here frequently.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Mon, 13 Oct 2008 08:10:46 -0700 (PDT)
From: "/usr/ceo" <newsbot@cox.net>
Subject: Re: Want true instantiated objects from XML
Message-Id: <c18cfbfb-2087-476f-b8a9-c139e409315d@y21g2000hsf.googlegroups.com>
On Oct 13, 1:57=A0am, "/usr/ceo" <news...@cox.net> wrote:
> On Oct 12, 6:46=A0pm, s...@netherlands.com wrote:
>
>
>
> > On Sun, 12 Oct 2008 14:01:14 -0700 (PDT), "/usr/ceo" <news...@cox.net> =
wrote:
> > >I've had a need for this at points in the past, but was always able to
> > >code around it (and still could even now), but I'd really like to be
> > >able to do this, and I can't find anything out there that does this
> > >exactly as I want. =A0(Which tends to make me believe what I want
> > >wouldn't be as immediately useful as maybe I would think it to be,
> > >but...?!)
>
> > >Given an object defined as this:
>
> > >package Person;
>
> > >use strict;
> > >use warnings qw( all );
>
> > >sub new {
> > > =A0 my $proto =3D shift;
> > > =A0 my $class =3D ref $proto || $proto;
> > > =A0 my %attrs =3D @_;
> > > =A0 my $self =3D {};
>
> > > =A0 # Nevermind the error checking for attributes right now.
>
> > > =A0 $self->{__name} =3D $attrs{name};
> > > =A0 $self->{__age} =3D $attrs{age};
>
> > > =A0 bless $class, $self;
>
> > > =A0 return $self;
> > >}
>
> > ># RW attributes.
>
> > >sub name { $s =3D shift; $s->{__name} =3D shift if @_; return $s-
> > >>{__name} }
> > >sub age { $s =3D shift; $s->{__age} =3D shift if @_; return $s->{__age=
} }
>
> > ># Methods.
>
> > >sub sayName { print "My name is: " . shift->{__name} . "\n" }
> > >sub sayAge { print "I am " . shift->{__age} . " years old.\n" }
>
> > >1;
>
> > The above is all very impressive. What do you want to do?
>
> > >I want to be able to read the following XML and create instances of
> > >Person from each instance in the XML:
>
> > ><xml>
> > ><People>
> > > =A0 <Person name=3D"John Doe" age=3D"22" />
> > > =A0 <Person name=3D"Jane Doe" age=3D"23" />
> > > =A0 <Person name=3D"Maxx Doogan" age=3D"10" />
> > ></People>
> > ></xml>
>
> > So XML parsing is holding you up?
>
> No, I can parse most of the XML I need with XML::Simple. =A0The point
> is, I don't really want the hashed structure that XML::Simple
> provides, even though I can munge the parsing with ForceGroup and
> other options. =A0So no, the parsing isn't the issue. =A0I want more of a=
n
> XML "freeze / unfreeze" or serialize / deserialize (marshalling)
> solution. =A0(Marshalling and s/d aren't always the same I realize...)
>
>
>
>
>
> > >So I get an array of Person objects which I can then write:
>
> > >my @people; # Hold the array of Person object created from the XML
> > >above.
>
> > >for my $person (@people) {
> > > =A0 $person->sayName();
> > > =A0 $person->sayAge();
> > >}
>
> > >I've looked through SOAP::Lite (and SOAP::Serialize and
> > >SOAP::Deserialize). =A0I'm a fairly frequent user of XML::Simple, but
> > >Simple doesn't do the above (AFAIK). =A0SURELY *something* like this i=
s
> > >"out there" (read "CPAN") but I can't seem to find it; only things
> > >close to it (like SOAP::SOM objects that require an xpath of sorts and
> > >my methods are still not available through an instantiated method of
> > >just the data [object attributes] in XML.)
>
> > >Thanks!
> > >/usr/ceo
>
> > rxparse version 2
>
> I'll check that out as well, but the solution Zed offered was closer
> to what I was looking for. =A0Close enough.
>
> Thanks!
> /usr/ceo
For those of you following along at home, there were some minor errors
with the code I typed in off the top of my head for my example.
blessing into $class is wrong. Using "strict" the $s variable in my
accessors needed to be "my"'d. I hate it when I read a book or try to
pull something from Usenet and it doesn't work due to unchecked errors
on the part of the author! :-) :-(
Here is the final XML::Twig solution, taking Zed's XML::Twig solution,
adding in the Person package (just inline in this case) and correcting
for a few errors (and making a few ticky-tack "the way I do things"
changes to Zed's example which was fine as it was):
#!/usr/bin/perl
use strict;
use warnings qw( all );
package Person;
use strict;
use warnings qw( all );
sub new {
my $proto =3D shift;
my $class =3D ref $proto || $proto;
my %attrs =3D @_;
my $self =3D {};
# Nevermind the error checking for attributes right now.
$self->{__name} =3D $attrs{name};
$self->{__age} =3D $attrs{age};
bless $self, $class;
return $self;
}
# RW attributes.
sub name { my $s =3D shift; $s->{__name} =3D shift if @_; return $s-
>{__name} }
sub age { my $s =3D shift; $s->{__age} =3D shift if @_; return $s-
>{__age} }
# Methods.
sub sayName { print "My name is: " . shift->{__name} . "\n" }
sub sayAge { print "I am " . shift->{__age} . " years old.\n" }
package main;
use XML::Twig;
my $twig =3D XML::Twig->new();
$twig->parse( \*DATA );
my @people;
my @xmlpersons =3D $twig->root->descendants( 'Person' );
for my $element (@xmlpersons) {
my $name =3D $element->att( 'name' );
my $age =3D $element->att( 'age' );
my $person =3D Person->new( name =3D> $name, age =3D> $age );
push @people, $person;
}
for my $person (@people) {
print "-" x 10 . "\n";
$person->sayName();
$person->sayAge();
}
__DATA__
<xml>
<People>
<Person name=3D"John Doe" age=3D"22" />
<Person name=3D"Jane Doe" age=3D"23" />
<Person name=3D"Maxx Doogan" age=3D"10" />
</People>
</xml>
Gr=FCss!
/usr/ceo
------------------------------
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:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#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 1920
***************************************