[23648] in Perl-Users-Digest
Perl-Users Digest, Issue: 5855 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 25 06:05:52 2003
Date: Tue, 25 Nov 2003 03:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 25 Nov 2003 Volume: 10 Number: 5855
Today's topics:
Re: Assigning split to a list: undefined values? <kuujinbo@hotmail.com>
Re: Avoiding running a process twice <simon.andrews@bbsrc.ac.uk>
Re: Avoiding running a process twice (Anno Siegel)
Excerpts from search result page (Krishna Srinivasan)
help with find2perl <sunil_franklin@hotmail.com>
Re: help with find2perl (Anno Siegel)
Re: Perl Editor <jwillmore@remove.adelphia.net>
Re: Perl Editor (John M. Gamble)
Posting Guidelines for comp.lang.perl.misc ($Revision: tadmc@augustmail.com
Re: push @arr, slice-of-href <eddhig22@yahool.com>
Re: push @arr, slice-of-href <eddhig22@yahool.com>
Regexp issue . . . <mickyc@NOshaSPAMw.ca>
Re: Regexp issue . . . (Anno Siegel)
Re: undif as if it is 0 <eddhig22@yahool.com>
Re: use strick & hash ref <tom@nosleep.net>
Re: use strick & hash ref <tom@nosleep.net>
Re: use strick & hash ref <tom@nosleep.net>
Re: use strick & hash ref <tom@nosleep.net>
Re: use strick & hash ref <uri@stemsystems.com>
Re: use strick & hash ref <tom@nosleep.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 25 Nov 2003 16:15:26 +0900
From: ko <kuujinbo@hotmail.com>
Subject: Re: Assigning split to a list: undefined values?
Message-Id: <bpuvos$fhh$1@pin3.tky.plala.or.jp>
Malcolm Dew-Jones wrote:
> Dmitry Epstein (mitia.nospam@northwestern.edu.invalid) wrote:
[snip]
> perldoc -f split also states that assigning to a _list_ (which is what you
> have) creates an implicit limit on the number of fields to be extracted.
>
> So I am guessing that "default" is refering to the "limit", but since you
> have implicitly defined a limit then you don't get the default behaviour.
>
Thanks for pointing out my error. Missed the most relevant part of the
docs in relation to this problem :(
keith
------------------------------
Date: Tue, 25 Nov 2003 08:57:20 +0000
From: Simon Andrews <simon.andrews@bbsrc.ac.uk>
Subject: Re: Avoiding running a process twice
Message-Id: <bpv5hg$ffa$1@south.jnrs.ja.net>
Anno Siegel wrote:
> If you can use file locking (not sure about the windows side), that would
> be the way to go. Again you use a file, but it isn't created/deleted
> with program runs, but only locked (exclusively). The advantage is that
> it's easier to get correct (because it's what locking is about), and
> you're not responsible for deleting the file. The system takes care
> of the lock.
A nice little idea someone posted here was to get an exclusive lock on
the script itself to make sure only one instance was running. I never
tried it, but it seemed like a nice way to do this as you don't have to
remember which file you're locking for a particular script, you just
lock the script itself.
Having said this, the flock documentation says that:
[lockf] requires that FILEHANDLE be open with write intent
Would this not mean you'd have to open your script for appending? If so
I'd be less happy about this approach as it would mean each person using
it would have to have write permission to it.
This would presumably mess up the other similar suggestion, which was to
lock the DATA filehandle.
------------------------------
Date: 25 Nov 2003 09:55:17 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Avoiding running a process twice
Message-Id: <bpv8u5$bec$2@mamenchi.zrz.TU-Berlin.DE>
Simon Andrews <simon.andrews@bbsrc.ac.uk> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
>
> > If you can use file locking (not sure about the windows side), that would
> > be the way to go. Again you use a file, but it isn't created/deleted
> > with program runs, but only locked (exclusively). The advantage is that
> > it's easier to get correct (because it's what locking is about), and
> > you're not responsible for deleting the file. The system takes care
> > of the lock.
>
> A nice little idea someone posted here was to get an exclusive lock on
> the script itself to make sure only one instance was running. I never
> tried it, but it seemed like a nice way to do this as you don't have to
> remember which file you're locking for a particular script, you just
> lock the script itself.
>
> Having said this, the flock documentation says that:
>
> [lockf] requires that FILEHANDLE be open with write intent
Right, on some systems require this, including mainstream ones (solaris).
That requirement is short-sighted design, imho. It assumes that a file
lock always protects exactly the file it is locking. Our example shows
that other kinds of locking occur where the requirement makes no sense.
> Would this not mean you'd have to open your script for appending? If so
> I'd be less happy about this approach as it would mean each person using
> it would have to have write permission to it.
To be portable, yes. It also means you have to *find* the binary first
to open it for writing, not something you want to do if you don't have to.
> This would presumably mess up the other similar suggestion, which was to
> lock the DATA filehandle.
Right. Locking DATA exclusively won't work everywhere.
This discussion illustrates a general principle. In programming as in
other crafts, it is often tempting to use something you "happen to have
around" for some other purpose. Like you have a box to mount on the
wall, and you find a bolt sticking out that holds a box on the other
side. "Let's use that!" Think twice before you do it. It *may*
be a good idea, but you create dependencies that wouldn't be there
without it.
Anno
------------------------------
Date: 24 Nov 2003 23:57:13 -0800
From: krishna@multimediastudio.com (Krishna Srinivasan)
Subject: Excerpts from search result page
Message-Id: <361f42ca.0311242357.41e2c205@posting.google.com>
Hi All,
I have written a website search script that returns all the pages that
match 100% with the search terms. I also want to include excerpts from
the returned result page with the search terms bolded (as Google does
below the title of the retuned page). Is there a ready Perl script
that does just this? Or will I have to write one myself. There seems
to be a thousand different cases on how the excerpt will contain the
search term(s).
Thanks in advance.
Krishna Srinivasan.
------------------------------
Date: Tue, 25 Nov 2003 11:33:24 +0530
From: "Sunil" <sunil_franklin@hotmail.com>
Subject: help with find2perl
Message-Id: <NqCwb.23$023.131@news.oracle.com>
All,
The following does not work for me.
find2perl . -name \*.\* | xargs fgrep -i 'begin'
any pointers?
Thanks,
Sunil.
------------------------------
Date: 25 Nov 2003 10:34:11 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: help with find2perl
Message-Id: <bpvb73$cs8$2@mamenchi.zrz.TU-Berlin.DE>
Sunil <sunil_franklin@hotmail.com> wrote in comp.lang.perl.misc:
> All,
> The following does not work for me.
>
> find2perl . -name \*.\* | xargs fgrep -i 'begin'
>
> any pointers?
No. It's your turn first to give us pointers.
What did you expect it to do.
What does it do instead.
Where there any error messages?
It's not like you're not posting here for the first time, is it.
Anno
------------------------------
Date: Tue, 25 Nov 2003 08:07:41 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Perl Editor
Message-Id: <20031125030740.5fc62897.jwillmore@remove.adelphia.net>
On 24 Nov 2003 09:32:29 -0800
carusoa@optonline.net (AnnMarie) wrote:
> What is the best editor for Perl CGI-Scripts?
Google :-)
Seriously .... use Google and search this newsgroup for 'editor'.
This has been asked and answered before.
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
Your lucky number is 3552664958674928. Watch for it everywhere.
------------------------------
Date: Tue, 25 Nov 2003 09:52:23 +0000 (UTC)
From: jgamble@ripco.com (John M. Gamble)
Subject: Re: Perl Editor
Message-Id: <bpv8on$rs1$2@e250.ripco.com>
In article <c659b5f9.0311240932.58c5a21@posting.google.com>,
AnnMarie <carusoa@optonline.net> wrote:
>What is the best editor for Perl CGI-Scripts?
Anything that you're comfortable with. Emacs, and vi, are found
on all sorts of computers and operating systems.
Currently, i'm using Jedit, which will get me some unbelieving
looks, since it is based on Java. But since it customizes nicely,
and can make use of plug-ins written for it, i'm having a blast
with it.
Edit Plus is nice if you are on Windows.
I'm sure that there are others to be found.
--
-john
February 28 1997: Last day libraries could order catalogue cards
from the Library of Congress.
------------------------------
Date: Tue, 25 Nov 2003 02:23:03 -0600
From: tadmc@augustmail.com
Subject: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.4 $)
Message-Id: <U8KdneWwYaf6jF6iRVn-gQ@august.net>
Outline
Before posting to comp.lang.perl.misc
Must
- Check the Perl Frequently Asked Questions (FAQ)
- Check the other standard Perl docs (*.pod)
Really Really Should
- Lurk for a while before posting
- Search a Usenet archive
If You Like
- Check Other Resources
Posting to comp.lang.perl.misc
Is there a better place to ask your question?
- Question should be about Perl, not about the application area
How to participate (post) in the clpmisc community
- Carefully choose the contents of your Subject header
- Use an effective followup style
- Speak Perl rather than English, when possible
- Ask perl to help you
- Do not re-type Perl code
- Provide enough information
- Do not provide too much information
- Do not post binaries, HTML, or MIME
Social faux pas to avoid
- Asking a Frequently Asked Question
- Asking a question easily answered by a cursory doc search
- Asking for emailed answers
- Beware of saying "doesn't work"
- Sending a "stealth" Cc copy
Be extra cautious when you get upset
- Count to ten before composing a followup when you are upset
- Count to ten after composing and before posting when you are upset
-----------------------------------------------------------------
Posting Guidelines for comp.lang.perl.misc ($Revision: 1.4 $)
This newsgroup, commonly called clpmisc, is a technical newsgroup
intended to be used for discussion of Perl related issues (except job
postings), whether it be comments or questions.
As you would expect, clpmisc discussions are usually very technical in
nature and there are conventions for conduct in technical newsgroups
going somewhat beyond those in non-technical newsgroups.
This article describes things that you should, and should not, do to
increase your chances of getting an answer to your Perl question. It is
available in POD, HTML and plain text formats at:
http://mail.augustmail.com/~tadmc/clpmisc.shtml
For more information about netiquette in general, see the "Netiquette
Guidelines" at:
http://andrew2.andrew.cmu.edu/rfc/rfc1855.html
A note to newsgroup "regulars":
Do not use these guidelines as a "license to flame" or other
meanness. It is possible that a poster is unaware of things
discussed here. Give them the benefit of the doubt, and just
help them learn how to post, rather than assume
A note about technical terms used here:
In this document, we use words like "must" and "should" as
they're used in technical conversation (such as you will
encounter in this newsgroup). When we say that you *must* do
something, we mean that if you don't do that something, then
it's unlikely that you will benefit much from this group.
We're not bossing you around; we're making the point without
lots of words.
Do *NOT* send email to the maintainer of these guidelines. It will be
discarded unread. The guidelines belong to the newsgroup so all
discussion should appear in the newsgroup. I am just the secretary that
writes down the consensus of the group.
Before posting to comp.lang.perl.misc
Must
This section describes things that you *must* do before posting to
clpmisc, in order to maximize your chances of getting meaningful replies
to your inquiry and to avoid getting flamed for being lazy and trying to
have others do your work.
The perl distribution includes documentation that is copied to your hard
drive when you install perl. Also installed is a program for looking
things up in that (and other) documentation named 'perldoc'.
You should either find out where the docs got installed on your system,
or use perldoc to find them for you. Type "perldoc perldoc" to learn how
to use perldoc itself. Type "perldoc perl" to start reading Perl's
standard documentation.
Check the Perl Frequently Asked Questions (FAQ)
Checking the FAQ before posting is required in Big 8 newsgroups in
general, there is nothing clpmisc-specific about this requirement.
You are expected to do this in nearly all newsgroups.
You can use the "-q" switch with perldoc to do a word search of the
questions in the Perl FAQs.
Check the other standard Perl docs (*.pod)
The perl distribution comes with much more documentation than is
available for most other newsgroups, so in clpmisc you should also
see if you can find an answer in the other (non-FAQ) standard docs
before posting.
It is *not* required, or even expected, that you actually *read* all of
Perl's standard docs, only that you spend a few minutes searching them
before posting.
Try doing a word-search in the standard docs for some words/phrases
taken from your problem statement or from your very carefully worded
"Subject:" header.
Really Really Should
This section describes things that you *really should* do before posting
to clpmisc.
Lurk for a while before posting
This is very important and expected in all newsgroups. Lurking means
to monitor a newsgroup for a period to become familiar with local
customs. Each newsgroup has specific customs and rituals. Knowing
these before you participate will help avoid embarrassing social
situations. Consider yourself to be a foreigner at first!
Search a Usenet archive
There are tens of thousands of Perl programmers. It is very likely
that your question has already been asked (and answered). See if you
can find where it has already been answered.
One such searchable archive is:
http://groups.google.com/advanced_group_search
If You Like
This section describes things that you *can* do before posting to
clpmisc.
Check Other Resources
You may want to check in books or on web sites to see if you can
find the answer to your question.
But you need to consider the source of such information: there are a
lot of very poor Perl books and web sites, and several good ones
too, of course.
Posting to comp.lang.perl.misc
There can be 200 messages in clpmisc in a single day. Nobody is going to
read every article. They must decide somehow which articles they are
going to read, and which they will skip.
Your post is in competition with 199 other posts. You need to "win"
before a person who can help you will even read your question.
These sections describe how you can help keep your article from being
one of the "skipped" ones.
Is there a better place to ask your question?
Question should be about Perl, not about the application area
It can be difficult to separate out where your problem really is,
but you should make a conscious effort to post to the most
applicable newsgroup. That is, after all, where you are the most
likely to find the people who know how to answer your question.
Being able to "partition" a problem is an essential skill for
effectively troubleshooting programming problems. If you don't get
that right, you end up looking for answers in the wrong places.
It should be understood that you may not know that the root of your
problem is not Perl-related (the two most frequent ones are CGI and
Operating System related), so off-topic postings will happen from
time to time. Be gracious when someone helps you find a better place
to ask your question by pointing you to a more applicable newsgroup.
How to participate (post) in the clpmisc community
Carefully choose the contents of your Subject header
You have 40 precious characters of Subject to win out and be one of
the posts that gets read. Don't waste them. Take care while
composing them, they are the key that opens the door to getting an
answer.
Spend them indicating what aspect of Perl others will find if they
should decide to read your article.
Do not spend them indicating "experience level" (guru, newbie...).
Do not spend them pleading (please read, urgent, help!...).
Do not spend them on non-Subjects (Perl question, one-word
Subject...)
For more information on choosing a Subject see "Choosing Good
Subject Lines":
http://www.cpan.org/authors/id/D/DM/DMR/subjects.post
Part of the beauty of newsgroup dynamics, is that you can contribute
to the community with your very first post! If your choice of
Subject leads a fellow Perler to find the thread you are starting,
then even asking a question helps us all.
Use an effective followup style
When composing a followup, quote only enough text to establish the
context for the comments that you will add. Always indicate who
wrote the quoted material. Never quote an entire article. Never
quote a .signature (unless that is what you are commenting on).
Intersperse your comments *following* each section of quoted text to
which they relate. Unappreciated followup styles are referred to as
"Jeopardy" (because the answer comes before the question), or
"TOFU".
Reversing the chronology of the dialog makes it much harder to
understand (some folks won't even read it if written in that style).
For more information on quoting style, see:
http://web.presby.edu/~nnqadmin/nnq/nquote.html
Speak Perl rather than English, when possible
Perl is much more precise than natural language. Saying it in Perl
instead will avoid misunderstanding your question or problem.
Do not say: I have variable with "foo\tbar" in it.
Instead say: I have $var = "foo\tbar", or I have $var = 'foo\tbar',
or I have $var = <DATA> (and show the data line).
Ask perl to help you
You can ask perl itself to help you find common programming mistakes
by doing two things: enable warnings (perldoc warnings) and enable
"strict"ures (perldoc strict).
You should not bother the hundreds/thousands of readers of the
newsgroup without first seeing if a machine can help you find your
problem. It is demeaning to be asked to do the work of a machine. It
will annoy the readers of your article.
You can look up any of the messages that perl might issue to find
out what the message means and how to resolve the potential mistake
(perldoc perldiag). If you would like perl to look them up for you,
you can put "use diagnostics;" near the top of your program.
Do not re-type Perl code
Use copy/paste or your editor's "import" function rather than
attempting to type in your code. If you make a typo you will get
followups about your typos instead of about the question you are
trying to get answered.
Provide enough information
If you do the things in this item, you will have an Extremely Good
chance of getting people to try and help you with your problem!
These features are a really big bonus toward your question winning
out over all of the other posts that you are competing with.
First make a short (less than 20-30 lines) and *complete* program
that illustrates the problem you are having. People should be able
to run your program by copy/pasting the code from your article. (You
will find that doing this step very often reveals your problem
directly. Leading to an answer much more quickly and reliably than
posting to Usenet.)
Describe *precisely* the input to your program. Also provide example
input data for your program. If you need to show file input, use the
__DATA__ token (perldata.pod) to provide the file contents inside of
your Perl program.
Show the output (including the verbatim text of any messages) of
your program.
Describe how you want the output to be different from what you are
getting.
If you have no idea at all of how to code up your situation, be sure
to at least describe the 2 things that you *do* know: input and
desired output.
Do not provide too much information
Do not just post your entire program for debugging. Most especially
do not post someone *else's* entire program.
Do not post binaries, HTML, or MIME
clpmisc is a text only newsgroup. If you have images or binaries
that explain your question, put them in a publically accessible
place (like a Web server) and provide a pointer to that location. If
you include code, cut and paste it directly in the message body.
Don't attach anything to the message. Don't post vcards or HTML.
Many people (and even some Usenet servers) will automatically filter
out such messages. Many people will not be able to easily read your
post. Plain text is something everyone can read.
Social faux pas to avoid
The first two below are symptoms of lots of FAQ asking here in clpmisc.
It happens so often that folks will assume that it is happening yet
again. If you have looked but not found, or found but didn't understand
the docs, say so in your article.
Asking a Frequently Asked Question
It should be understood that you may have missed the applicable FAQ
when you checked, which is not a big deal. But if the Frequently
Asked Question is worded similar to your question, folks will assume
that you did not look at all. Don't become indignant at pointers to
the FAQ, particularly if it solves your problem.
Asking a question easily answered by a cursory doc search
If folks think you have not even tried the obvious step of reading
the docs applicable to your problem, they are likely to become
annoyed.
If you are flamed for not checking when you *did* check, then just
shrug it off (and take the answer that you got).
Asking for emailed answers
Emailed answers benefit one person. Posted answers benefit the
entire community. If folks can take the time to answer your
question, then you can take the time to go get the answer in the
same place where you asked the question.
It is OK to ask for a *copy* of the answer to be emailed, but many
will ignore such requests anyway. If you munge your address, you
should never expect (or ask) to get email in response to a Usenet
post.
Ask the question here, get the answer here (maybe).
Beware of saying "doesn't work"
This is a "red flag" phrase. If you find yourself writing that,
pause and see if you can't describe what is not working without
saying "doesn't work". That is, describe how it is not what you
want.
Sending a "stealth" Cc copy
A "stealth Cc" is when you both email and post a reply without
indicating *in the body* that you are doing so.
Be extra cautious when you get upset
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.
AUTHOR
Tad McClellan <tadmc@augustmail.com> and many others on the
comp.lang.perl.misc newsgroup.
------------------------------
Date: Tue, 25 Nov 2003 17:27:11 +1100
From: Edo <eddhig22@yahool.com>
Subject: Re: push @arr, slice-of-href
Message-Id: <3FC2F63F.2080901@yahool.com>
>
> Then why not just
>
> my @k = keys %$set;
>
that works, I guss looking too close to the screen blinded me on the
overlook picture.
the problem which is the important part of getting the HoAoH correct.
my ($dbits, $sbits, $set) = @_;
my @kd = keys %$dbits; my @ks = keys %$sbits;
my @vs = @$sbits{ @ks };
for( 0 .. (@kd - @ks) ) {
my @vd = @$dbits{ @kd[$_ .. $_+@ks-1 ] };
my $tmp = check( \@vd, \@vs );
my @k = keys %$set;
my $max = (sort {$a <=> $b} @k)[0] || 0;
if ( $tmp > $max ) {
------->> $set->{$tmp} = @$dbits{@kd[$_ .. $_+@ks-1 ]};
}
}
I need to have
%set-HoAoH = (
tmp1 => [
dbits slice1,
dbits slice2 if the same tmp
#each slice @kd[$_ .. $_+@ks-1 ] and has its own keys
and values
]
tmp2 =>
tmp3 =>
)
------------------------------
Date: Tue, 25 Nov 2003 21:52:02 +1100
From: Edo <eddhig22@yahool.com>
Subject: Re: push @arr, slice-of-href
Message-Id: <3FC33452.1060604@yahool.com>
ok, here is my brain dump
sub scan (\%\%\%) {
my ($dbits, $sbits, $set) = @_;
my @kd = keys %$dbits; my @ks = keys %$sbits;
my @vs = @$sbits{ @ks };
for( 0 .. (@kd - @ks) ) {
my @kdslic = @kd[$_ .. $_+@ks-1 ];
my @vd = @$dbits{@kdslic};
my $tmp = check( \@vd, \@vs );
my @k = keys %$set;
my $max = (sort {$a <=> $b} @k)[0] || 0;
if ( $tmp > $max ) {
foreach my $ky ( @kdslic ){
tie my (%slic), 'Tie::IxHash';
49:
$slic{$ky} = %$dbits{$ky};
}
push @{$set->{$tmp}},\%slic;
}
}
54:}
syntax error at prog/trend line 49, near "$dbits{"
syntax error at prog/trend line 54, near "}"
why? I tried %dbits{$ky}, $dbits{$ky} for no avail
------------------------------
Date: Tue, 25 Nov 2003 07:03:37 GMT
From: "MichaelC" <mickyc@NOshaSPAMw.ca>
Subject: Regexp issue . . .
Message-Id: <d9Dwb.492453$9l5.241927@pd7tw2no>
Hi all. I am having a particularly difficult time with a perl script that I
am writing. The problem area is a place where I need to strip some newlines
out of a file.
My source data is text which is in paragraph form, but has line breaks
within the paragraphs. I need to do as much processing as possible in order
to minimise the amount of manual changes that I have to make.
Sample text is as follows:
"This document is intended to give you an
overview of DG as well as highlight some of
the features. This is a brought to your handheld using DG."
With DG you can view and edit word processing and spreadsheet files on
your handheld. Simple push-button synchronization of
the handheld with the desktop will maintain the most up-to-date
version of a file on both the desktop and handheld.
I want these to be parsed as follows:
"This document is intended to give you an overview of DG as well as
highlight some of the features. This is a brought to your handheld using
DG." With DG you can view and edit word processing and spreadsheet files on
your handheld. Simple push-button synchronization of the handheld with the
desktop will maintain the most up-to-date version of a file on both the
desktop and handheld.
--
One way that I thought might work is to catch all lines that begin upper
case, prepend them with a line break, strip the trailing break, then trap
all lines that start lower case and dump them as-is. Repeat this until no
matches are made on the lower case test, then clean up all those extra line
breaks.
I came up with this . . . but all it seems to do is strip all newlines out.
while( <infl> ) {
my $x = $_;
if ( $x =~ ?^[^a-z]? ) { $x =~ s!(.*)\n!\n\1 ! }
else { $x =~ s!(.*)\n!\1 ! }
print outfl $x;
}
Any help would be greately appreciated.
Michael
------------------------------
Date: 25 Nov 2003 10:27:51 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Regexp issue . . .
Message-Id: <bpvar7$cs8$1@mamenchi.zrz.TU-Berlin.DE>
[comp.lang.perl removed from newsgroups. it's dead]
MichaelC <mickyc@NOshaSPAMw.ca> wrote in comp.lang.perl.misc:
> Hi all. I am having a particularly difficult time with a perl script that I
> am writing. The problem area is a place where I need to strip some newlines
> out of a file.
>
> My source data is text which is in paragraph form, but has line breaks
> within the paragraphs. I need to do as much processing as possible in order
> to minimise the amount of manual changes that I have to make.
>
> Sample text is as follows:
>
> "This document is intended to give you an
> overview of DG as well as highlight some of
> the features. This is a brought to your handheld using DG."
> With DG you can view and edit word processing and spreadsheet files on
> your handheld. Simple push-button synchronization of
> the handheld with the desktop will maintain the most up-to-date
> version of a file on both the desktop and handheld.
>
> I want these to be parsed as follows:
>
> "This document is intended to give you an overview of DG as well as
> highlight some of the features. This is a brought to your handheld using
> DG." With DG you can view and edit word processing and spreadsheet files on
> your handheld. Simple push-button synchronization of the handheld with the
> desktop will maintain the most up-to-date version of a file on both the
> desktop and handheld.
>
> --
You don't say how paragraphs are to be recognized in your original text.
Are there double line-feeds between paragraphs?
Otherwise it seems that you just want to re-cast each paragraph with
reasonable linefeeds.
This guesswork is frustrating. An example is fine, but you must also say
in words what you want to do.
> One way that I thought might work is to catch all lines that begin upper
> case, prepend them with a line break, strip the trailing break, then trap
> all lines that start lower case and dump them as-is. Repeat this until no
> matches are made on the lower case test, then clean up all those extra line
> breaks.
This sounds as if you want to recorgnize a paragraph from the fact that
its first line starts with a capital letter. That is going to fail on
more than a few occasions.
> I came up with this . . . but all it seems to do is strip all newlines out.
[code snipped]
If I understand you, you will have to check paragraph boundaries manually
in any case. Do it now, and make them double line-feeds. Then the
standard module Text::Wrap can do the rest of the formatting:
use Text::Wrap;
$/ = ''; # paragraph mode
$Text::Wrap::columns = 72;
while ( <DATA> ) {
tr/\n/ /d; # line feeds to spaces
print wrap( '', '', $_), "\n\n";
}
Anno
------------------------------
Date: Tue, 25 Nov 2003 22:06:41 +1100
From: Edo <eddhig22@yahool.com>
Subject: Re: undif as if it is 0
Message-Id: <3FC337C1.8050405@yahool.com>
Bob Walton wrote:
> Edo wrote:
>
> ...
>
>> I am getting $max = undif if nothing in @top3, but due to the way the
>
>
> undef?----------------^^^^^
>
>> code below is written, I need it to show 0 instead.
>> do I have to change the code? or there is an operator to change undif
>> to 0 in this case?
>
> ...
>
>> my @kd = keys %$dbits; my @ks = keys %$sbits;
>> my @vs = @$sbits{ @ks };
>>
>> for( 0 .. 5 ) {
>> my $tmp = 4;
>> my $max = (sort {$b <=> $a} @top3)[0];
>> if ( $tmp > $max ) {
>> ... code
>> push @top3, \%set;
>> }
>> }
>>
>
> Unless you need the contents of $max for something else not shown, it
> will not matter if $max is 0 or undef. Since > is a numeric comparison
> operator, undef will be treated the same as 0 in the comparison, and you
> don't use $max elsewhere. If you really need it to be a numeric 0, put:
>
> $max+=0;
>
> after the sort. That will force a "numerification" of $max, and will be
> a no-op if $max is already numeric. Or append +0 to the end of the
> sort, as in:
>
> my $max = (sort {$b <=> $a} @top3)[0]+0;
>
on the first round of the loop, nothing is in the @top3 which makes $max
undef
>
> BTW, please improve your indenting style. The lack of reasonable
> indenting makes your program harder to follow than necessary. Thanks.
>
I have all indentaion style working good in emacs as well as when I copy
and paste
using the mouse button3 but when I post it changes the indention, I
have no control over
this unless I am missing somthing.
------------------------------
Date: Mon, 24 Nov 2003 22:25:05 -0800
From: "Tom" <tom@nosleep.net>
Subject: Re: use strick & hash ref
Message-Id: <3fc30322$1@nntp0.pdx.net>
> What you're looking for is that you possibly have two variables with
> the same name, one $hash, the other %hash. While this is perfectly
> valid, you do need to be always aware of when you're using $hash->{...}
> (using $hash) vs $hash{...} (using %hash). Thus, in general, I'd
> suggest attempting to avoid this.
>
Thanks, I think you are right, but I just got time to check it.
I did have it on, but had a problem and turned it off, then forgot to
uncomment it.
Thanks,
Tom
------------------------------
Date: Mon, 24 Nov 2003 23:30:10 -0800
From: "Tom" <tom@nosleep.net>
Subject: Re: use strick & hash ref
Message-Id: <3fc3125d$1@nntp0.pdx.net>
> What you're looking for is that you possibly have two variables with
> the same name, one $hash, the other %hash. While this is perfectly
> valid, you do need to be always aware of when you're using $hash->{...}
> (using $hash) vs $hash{...} (using %hash). Thus, in general, I'd
> suggest attempting to avoid this.
Hi
O.K., this makes semse, but what does not make sense is, I was originally
only using $hash{....} and was unable to get the hash to save.
so, I swithed to this:
$nasstk->{DAILY} = join(":",@daily);
This is local, and assigned to tied hash:
$ndbhsh{$keyval} = \%$nasstk;
Works fine, but the hash is tied like this:
# Tie Database
tie(%ndbhsh,"MLDBM",$ndbfile,O_RDWR | O_CREAT) || die "Can't tie junk:
$!";
$nasstk = $ndbhsh{$keyval};
So, this is reverse order, here in order:
use strict;
my %ndbhsh;
# my $nbdhsh;
# my %nasstk = ();
my $nasstk;
my @dailty;
my $val1 = 1;
my $val2 = 2;
# Tie Database
tie(%ndbhsh,"MLDBM",$ndbfile,O_RDWR | O_CREAT) || die "Can't tie junk:
$!";
$nasstk = $ndbhsh{$keyval};
# Build Hash Entry
@daily = ();
push(@daily,$val1,$va2);
$nasstk->{DAILY} = join(":",@daily);
$ndbhsh{$keyval} = \%$nasstk;
untie %ndbhsh;
Now, I've tred just using %hash for all hash declarations and referencing
via $hash{...}, but when I did this, no data would make it into the tied
disk hash, i.e. data was undefined.
If I use all $hash->{...}, all I get are these:
Global symbol "$ndbhsh" requires explicit package name at ./fs.pl line 762.
I followed everything form examples out there, except in all the examples,
it never shows the correct way to declare everything.
Can someone please help?
Also, what is the difference between these two different ways of declaring
hashes?
Thanks,
Tom
------------------------------
Date: Mon, 24 Nov 2003 23:42:04 -0800
From: "Tom" <tom@nosleep.net>
Subject: Re: use strick & hash ref
Message-Id: <3fc31526$1@nntp0.pdx.net>
>
> use strict;
>
> my %ndbhsh;
> # my $nbdhsh;
> # my %nasstk = ();
> my $nasstk;
>
> my @dailty;
> my $val1 = 1;
> my $val2 = 2;
>
> # Tie Database
> tie(%ndbhsh,"MLDBM",$ndbfile,O_RDWR | O_CREAT) || die "Can't tie junk:
> $!";
>
> $nasstk = $ndbhsh{$keyval};
>
> # Build Hash Entry
> @daily = ();
> push(@daily,$val1,$va2);
>
>
> $nasstk->{DAILY} = join(":",@daily);
>
> $ndbhsh{$keyval} = \%$nasstk;
>
> untie %ndbhsh;
>
> Now, I've tred just using %hash for all hash declarations and referencing
> via $hash{...}, but when I did this, no data would make it into the tied
> disk hash, i.e. data was undefined.
>
> If I use all $hash->{...}, all I get are these:
> Global symbol "$ndbhsh" requires explicit package name at ./fs.pl line
762.
>
>
> I followed everything form examples out there, except in all the examples,
> it never shows the correct way to declare everything.
>
> Can someone please help?
>
> Also, what is the difference between these two different ways of declaring
> hashes?
>
> Thanks,
> Tom
>
>
So, by the way, it only works when both of the following are declared:
my %nasstk = ();
my $nasstk;
Which I do not understand.
>
>
------------------------------
Date: Tue, 25 Nov 2003 00:17:53 -0800
From: "Tom" <tom@nosleep.net>
Subject: Re: use strick & hash ref
Message-Id: <3fc31d88@nntp0.pdx.net>
>
> So, by the way, it only works when both of the following are declared:
> my %nasstk = ();
> my $nasstk;
>
> Which I do not understand.
>
I only wish I knew what the hell I keep doing to make this work, then not
work, then work again, when "use strict" is included.
It works all the time with it off.
Too strange.
I have diffed files during working and non, and nothing is different.
------------------------------
Date: Tue, 25 Nov 2003 08:27:30 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: use strick & hash ref
Message-Id: <x765h8vonh.fsf@mail.sysarch.com>
>>>>> "T" == Tom <tom@nosleep.net> writes:
T> I only wish I knew what the hell I keep doing to make this work, then not
T> work, then work again, when "use strict" is included.
T> It works all the time with it off.
T> Too strange.
T> I have diffed files during working and non, and nothing is different.
is this mod_perl? if so, it may be running cached versions which have
strict off. have you tested your code with perl -c? that is always a
good thing to do when cleaning up strict errors.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 25 Nov 2003 01:13:25 -0800
From: "Tom" <tom@nosleep.net>
Subject: Re: use strick & hash ref
Message-Id: <3fc32a8b$1@nntp0.pdx.net>
"Uri Guttman" <uri@stemsystems.com> wrote in message
news:x765h8vonh.fsf@mail.sysarch.com...
> >>>>> "T" == Tom <tom@nosleep.net> writes:
>
> T> I only wish I knew what the hell I keep doing to make this work, then
not
> T> work, then work again, when "use strict" is included.
> T> It works all the time with it off.
> T> Too strange.
> T> I have diffed files during working and non, and nothing is different.
>
> is this mod_perl? if so, it may be running cached versions which have
> strict off. have you tested your code with perl -c? that is always a
> good thing to do when cleaning up strict errors.
>
I'm not sure what that is, but I'll try -c tomorrow night.
Thanks,
Tom
------------------------------
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.
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 5855
***************************************