[25995] in Perl-Users-Digest
Perl-Users Digest, Issue: 8214 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 29 18:05:31 2005
Date: Wed, 29 Jun 2005 15:05:08 -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 Wed, 29 Jun 2005 Volume: 10 Number: 8214
Today's topics:
extract a value from a field in a file <nufin>
Re: extract a value from a field in a file <mark.clementsREMOVETHIS@wanadoo.fr>
Re: extract a value from a field in a file <nufin>
Re: extract a value from a field in a file <noreply@gunnar.cc>
Re: problem in passing parameters in function defined i <sherm@dot-app.org>
re:UTF-8 to named character entities (Crap)
re:UTF-8 to named character entities <john@castleamber.com>
Re: Simple Structure Question <newsAT@screenlightDOT.com>
Re: Simple Structure Question <jgibson@mail.arc.nasa.gov>
Re: Simple Structure Question <noreply@gunnar.cc>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 29 Jun 2005 18:27:42 +0200
From: nufin <nufin>
Subject: extract a value from a field in a file
Message-Id: <1120062477.17451.0@lotis.uk.clara.net>
Hello,
I need to extract from a file values of the "QRKPageBegin" field.
Into the file, the fields appear like following:
%%QRKPageBegin: 2
%%QRKPageBegin: 4
%%QRKPageBegin: 5
I would like to extract each of the values of this field, to set a list.
Actually, (I am a perl newbie), I wrote the following code
open (PS,$PSFile) or die "Could not open the file $PSFile: $! \n";
$/ = "\r";
while (<PS>) {
while (/([%%QRKPageBegin\s]{14,})/g) {
print $1, "\n";
}
}
close PS;
However it display/get the field but not the value, so any help would be
greatly appreciated !
Best Regards,
Tof
------------------------------
Date: Wed, 29 Jun 2005 18:43:08 +0200
From: Mark <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: extract a value from a field in a file
Message-Id: <42c2cf9e$0$1223$8fcfb975@news.wanadoo.fr>
nufin wrote:
> Hello,
>
> I need to extract from a file values of the "QRKPageBegin" field.
> Into the file, the fields appear like following:
> %%QRKPageBegin: 2
> %%QRKPageBegin: 4
> %%QRKPageBegin: 5
>
> I would like to extract each of the values of this field, to set a list.
>
> Actually, (I am a perl newbie), I wrote the following code
>
> open (PS,$PSFile) or die "Could not open the file $PSFile: $! \n";
> $/ = "\r";
>
> while (<PS>) {
> while (/([%%QRKPageBegin\s]{14,})/g) {
> print $1, "\n";
> }
> }
> close PS;
>
> However it display/get the field but not the value, so any help would be
> greatly appreciated !
>
For a start, make sure that you have
use warnings;
use strict;
at the top of every Perl script. This will catch a lot of otherwise
hard-to-find errors.
You've misunderstood regular expressions (or at least partly
misunderstood). [] defines a character class - you have no need for this
here. You need a regex like
/^%%QRKPageBegin:\s*(\d+)$/
assuming that this is all that will appear on one line. Putting
use re 'debug';
at the start of your script will help you to debug regexs. See
perldoc re
for more details on this and
perldoc perlre
for general information about regexs.
regards,
Mark
------------------------------
Date: Wed, 29 Jun 2005 20:18:27 +0200
From: nufin <nufin>
Subject: Re: extract a value from a field in a file
Message-Id: <1120069122.21025.0@lotis.uk.clara.net>
Hi Mark,
Many thanks for your help !
I will test it and follow your recommandations.
Best Regards,
Christophe
Mark wrote:
> nufin wrote:
>
>> Hello,
>>
>> I need to extract from a file values of the "QRKPageBegin" field.
>> Into the file, the fields appear like following:
>> %%QRKPageBegin: 2
>> %%QRKPageBegin: 4
>> %%QRKPageBegin: 5
>>
>> I would like to extract each of the values of this field, to set a list.
>>
>> Actually, (I am a perl newbie), I wrote the following code
>>
>> open (PS,$PSFile) or die "Could not open the file $PSFile: $! \n";
>> $/ = "\r";
>>
>> while (<PS>) {
>> while (/([%%QRKPageBegin\s]{14,})/g) {
>> print $1, "\n";
>> }
>> }
>> close PS;
>>
>> However it display/get the field but not the value, so any help would
>> be greatly appreciated !
>>
>
> For a start, make sure that you have
>
> use warnings;
> use strict;
>
> at the top of every Perl script. This will catch a lot of otherwise
> hard-to-find errors.
>
> You've misunderstood regular expressions (or at least partly
> misunderstood). [] defines a character class - you have no need for this
> here. You need a regex like
>
> /^%%QRKPageBegin:\s*(\d+)$/
>
> assuming that this is all that will appear on one line. Putting
>
> use re 'debug';
>
> at the start of your script will help you to debug regexs. See
>
> perldoc re
>
> for more details on this and
>
> perldoc perlre
>
> for general information about regexs.
>
> regards,
>
> Mark
>
>
------------------------------
Date: Wed, 29 Jun 2005 21:03:41 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: extract a value from a field in a file
Message-Id: <3ig9khFl4j4aU1@individual.net>
nufin wrote:
> I need to extract from a file values of the "QRKPageBegin" field.
> Into the file, the fields appear like following:
> %%QRKPageBegin: 2
> %%QRKPageBegin: 4
> %%QRKPageBegin: 5
<snip>
> open (PS,$PSFile) or die "Could not open the file $PSFile: $! \n";
> $/ = "\r";
In addition to Mark's comments, why do you think that line makes a
difference? Without knowing which platform you are on, I would suspect
it doesn't. Please read about newlines in "perldoc perlport".
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 29 Jun 2005 10:17:40 -0400
From: Sherm Pendley <sherm@dot-app.org>
Subject: Re: problem in passing parameters in function defined in perl module
Message-Id: <87r7ell01n.fsf@dot-app.org>
Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
> Vikrant wrote:
>> sub Configure($ddd)
>> {
>> print"$ddd";
>> }
>
> Sorry, but I don't understand how you are thinking now.
He's probably accustomed to C, Java, Pascal, or some other language where
arguments are named and their names declared with the function prototype. For
instance, in C:
void Configure(int ddd) {
...
}
sherm--
--
Due to the amount of unreadable gibberish being posted from Google Groups,
I seldom read messages posted from there.
Cocoa/Perl: http://camelbones.sf.net Hire Me: http://www.dot-app.org
------------------------------
Date: Wed, 29 Jun 2005 21:30:40 +0000 (UTC)
From: crappi@hetnet-dot-nl.no-spam.invalid (Crap)
Subject: re:UTF-8 to named character entities
Message-Id: <d9v3tv$57q$1@domitilla.aioe.org>
Thanks for the reply, however I am still lost.
What I want is a conversion from UTF-8 to the corresponding named
character entities (ë --> ë). But I get really funny
characters. Below is my script, test.xml, and output.xml
command line: perl utf.pl test.xml
--utf.pl--
#!/usr/bin/perl -w
use HTML::Entities;
open OUT, ">output.xml";
while(<>){
$string=(encode_entities($_));
print OUT $string;
}
close OUT;
---test.xml---
<a>patiënten reguleert.’<vn>
<al>
<a>EN 1130b31-1131a.</a>
</al>
</vn>
---output.xml---
<a>patiënten
reguleert.’<vn>
<al>
<a>EN 1130b31-1131a.</a>
</al>
</vn>
---expected.xml---
<a>patiënten reguleert.’<vn>
<al>
<a>EN 1130b31-1131a.</a>
</al>
</vn>
Thanks,
Chris
------------------------------
Date: 29 Jun 2005 22:01:39 GMT
From: John Bokma <john@castleamber.com>
Subject: re:UTF-8 to named character entities
Message-Id: <Xns9684AD0089032castleamber@130.133.1.4>
crappi@hetnet-dot-nl.no-spam.invalid (Crap) wrote:
> Thanks for the reply, however I am still lost.
> What I want is a conversion from UTF-8 to the corresponding named
> character entities (ë --> ë). But I get really funny
> characters. Below is my script, test.xml, and output.xml
Question: why do you want this? Just give your output.xml a proper
character encoding, and you can use ë.
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Wed, 29 Jun 2005 16:49:05 GMT
From: one man army <newsAT@screenlightDOT.com>
Subject: Re: Simple Structure Question
Message-Id: <newsAT-E9DBC9.09480929062005@newssvr13-ext.news.prodigy.com>
ok, after stumbling badly on the syntax and usage, as well as time and
patience, I have written the first script..
thanks for (most of) the replies, sometimes it is useful to have more
sets of eyeballs.
I really don't think some of the posters remember their first Hundred
Hours of Perl programming, it was so long ago, and past by some many
more..
There are a few idioms I am working on, but basically, I have a script
that parses, finds links, get()s and so on for three nested dereferences
in about 900 DB generated links. It kinda clunks along, and works!!
I am going to rewrite it in a cleaner fashion.
--
Lessons Learned:
Perl programmers use Dump() to determine struct and hash contents -
program off of what is in front of you
References, like C pointers, come up a lot and matter
print() is your friend
the documentation is deficient in many places. Most notably
perldoc -q struct
There is a lot of terse idiom everywhere you look
Perl has a lot of modules on CPAN to do very useful stuff
all for now
------------------------------
Date: Wed, 29 Jun 2005 10:26:05 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Simple Structure Question
Message-Id: <290620051026053970%jgibson@mail.arc.nasa.gov>
In article
<newsAT-E9DBC9.09480929062005@newssvr13-ext.news.prodigy.com>, one man
army <newsAT@screenlightDOT.com> wrote:
>
> ok, after stumbling badly on the syntax and usage, as well as time and
> patience, I have written the first script..
Congratulations.
>
> thanks for (most of) the replies, sometimes it is useful to have more
> sets of eyeballs.
>
> I really don't think some of the posters remember their first Hundred
> Hours of Perl programming, it was so long ago, and past by some many
> more..
>
> There are a few idioms I am working on, but basically, I have a script
> that parses, finds links, get()s and so on for three nested dereferences
> in about 900 DB generated links. It kinda clunks along, and works!!
Sounds like a non-trivial task!
>
> I am going to rewrite it in a cleaner fashion.
>
> --
Putting the above line in your message makes the following look (to my
news reader at least) a signature.
> Lessons Learned:
>
> Perl programmers use Dump() to determine struct and hash contents -
> program off of what is in front of you
Please keep in mind that "struct" is not a Perl term. Perl does not
have "structs". There is a struct emulator (Class::Struct) that is part
of the core Perl distribution, but I have never used it in many years
of Perl programming and haven't heard it discussed here much. Think of
it as training wheels for C programmers trying to use Perl. You are
better off losing the training wheels and defining your own data
structures using primitive Perl idioms.
>
> References, like C pointers, come up a lot and matter
>
> print() is your friend
>
> the documentation is deficient in many places. Most notably
> perldoc -q struct
But that documentation refers you to perlref, perlreftut, perldsc, and
perllol. Is there something wrong with those references?
>
> There is a lot of terse idiom everywhere you look
>
> Perl has a lot of modules on CPAN to do very useful stuff
>
>
> all for now
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
------------------------------
Date: Wed, 29 Jun 2005 20:55:31 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Simple Structure Question
Message-Id: <3ig956Fkmrf6U1@individual.net>
one man army wrote:
> ok, after stumbling badly on the syntax and usage, as well as time and
> patience,
We all apologize for the inconvenience you experienced. ;-)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
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 V10 Issue 8214
***************************************