[17463] in Perl-Users-Digest
Perl-Users Digest, Issue: 4883 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 14 03:10:35 2000
Date: Tue, 14 Nov 2000 00:10:13 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <974189413-v9-i4883@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 14 Nov 2000 Volume: 9 Number: 4883
Today's topics:
Re: Problem with chomp and print <arm@home.com>
Re: Problems compiling DBI and HP-UX 11.0 <quagly@home.com>
Re: Random Array with Sort? <quantum_mechanic@my-deja.com>
Re: regular expression for jpg images <wyzelli@yahoo.com>
Re: Simple regex problem <uri@sysarch.com>
Re: Simple regex problem <soeder@ai-lab.fh-furtwangen.de>
Re: Target of goto is too deeply nested (Rafael Garcia-Suarez)
What is P5P? <z_0_d@my-deja.com>
Re: What is P5P? (Ported and Polished Fluffy)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 14 Nov 2000 05:49:21 GMT
From: Alan Melton <arm@home.com>
Subject: Re: Problem with chomp and print
Message-Id: <3A10D1AE.1F3EC26B@home.com>
Martien Verbruggen wrote:
> On Mon, 13 Nov 2000 23:44:00 GMT,
> Alan Melton <arm@home.com> wrote:
> > By using this program:
>
> You are not useing -w, and you are not using strict. Those two are
> really, really valuable tools when debugging.
>
> > @a = <IN>; # read all lines of this file
> > chomp (@vals=@a[1,2,3,10,13,14,15]);
> > print OUTPUT join (" ",@vals), "\n";
> > chomp (@vals=@a[1,2,3,17,20,21,22]);
>
> Why don't you just chomp(@a) once, instead of repeatedly needing to do
>
> it for the same components? Then you can just do something like:
>
> print OUTPUT join(" ", @a[1,2,3,10,13,14,15]), "\n";
>
> and you won't need the temporary @vals.
>
> > print OUTPUT join (" ",@vals), "\n";
> > print unless $a eq /^$/;
> ^^
> Where did that come from?
> What is it supposed to be?
>
> Why the eq? Did you mean to match a pattern, or did you mean to check
> that something was equal to something else? And what were those
> things?
> And why are you printing to STDOUT suddenly? And what do you want to
> print? You're actually printing the valeu of $_, whatever that is.
>
> > chomp (@vals=@a[1,2,3,24,27,28,29]);
> > print OUTPUT join (" ",@vals), "\n";
> > print unless ($a[22]) eq /^$/;
>
> print OUTPUT "something\n" unless $a[22] eq "";
>
> > chomp (@vals=@a[1,2,3,31,34,35,36]);
> > print OUTPUT join (" ",@vals), "\n";
> > print unless ($a[28]) eq /^$/;
> > chomp (@vals=@a[1,2,3,38,41,42,43]);
> > print OUTPUT join (" ",@vals), "\n";
> > print unless ($a[34]) eq /^$/;
> > chomp (@vals=@a[1,2,3,45,48,49,50]);
> > print OUTPUT join (" ",@vals), "\n";
> > print unless ($a[40]) eq /^$/;
> > chomp (@vals=@a[1,2,3,52,55,56,57]);
> > print OUTPUT join (" ",@vals), "\n";
> > print unless ($a[46]) eq /^$/;
> > chomp (@vals=@a[1,2,3,59,62,63,64]);
> > print OUTPUT join (" ",@vals), "\n";
> > print unless ($a[52]) eq /^$/;
>
> I only count 45 lines in your input. Your indexes are much larger than
> 44.
>
> Why don't you just tell us what it is you're trying to do?
I am trying to convert an order to something more legible.
One person may order 1 item, another four items, another two items.
Their order looks like this if they order one item
CHAN@CORE.COM
10 <====== I want on one output line
30 <====== I want on one output line
2000 <====== I want on one output line
49.90
2.87
5.00
57.77
Csh
@
0-07-407248-X <====== I want on first output line preceeded by
10 30 2000
STAFF
11497
1 <====== I want on first output line
preceeded by 10 30 2000
49.90 <====== I want on first output line
preceeded by 10 30 2000
49.90 <====== I want on first output line
preceeded by 10 30 2000
MS OFFICE 2000- W98 (W/CD) (New)0-07-407248-X
THEIR ORDER ENDS HERE
and this if they order 4 items:
t-adam03@cougar.com
10 <====== I want on each output line for each item
30 <====== I want on each output line for each item
2000 <====== I want on each output line for each item
46.15
2.65
2.50
51.30
Call
@
0-06-093195-7 <====== I want on first output line preceeded by
10 30 2000
STAFF
12499
1 <====== I want on first output line
preceeded by 10 30 2000
9.05 <====== I want on first output line
preceeded by 10 30 2000
9.05 <====== I want on first output line
preceeded by 10 30 2000
ODYSSEY OF HOMER (TRANS LATTIMORE)(PERENNIAL
0-226-30784-0 <====== I want on second output
line preceeded by 10 30 2000
STAFF
12499
1 <====== I want on second
output line preceeded by 10 30 2000
9.30 <====== I want on second
output line preceeded by 10 30 2000
9.30 <====== I want on second
output line preceeded by 10 30 2000
EURIPIDES V: THREE TRAGEDIES (P) (New)0-226-30784-0
0-226-30780-8 <====== I want on
third output line preceeded by 10 30 2000
STAFF
12499
1 <====== I want
on third output line preceeded by 10 30 2000
9.25 <====== I want on
third output line preceeded by 10 30 2000
9.25 <====== I want on
third output line preceeded by 10 30 2000
EURIPIDES I: FOUR TRAGEDIES (P) (New)0-226-30780-8
0-226-30792-1 <====== I want on
fourth output line preceeded by 10 30 2000
STAFF
12499
1 and so on
9.30
9.30
SOPHOCLES I: THREE TRAGEDIES (P) (New)0-226-30792-1
0-87220-390-5
STAFF
ALL
1
9.25
9.25
ORESTEIA (TRANS MEINECK) (P) (New)0-87220-390-5
THEIR ORDER ENDS HERE
The first 10 lines are identical. I want the first three lines after the
email, followed by the info on lines 10,13,14,15 in one output line
Then go on to the next order which is in a different file.
Problem is, I am checking if they order 15 items on each file but if
they only order one
I am getting:
10 30 2000 0-06-093195-7 1 9.05 9.05
10 30 2000 0-226-30784-0 1 9.30 9.30
10 30 2000 0-226-30780-8 1 19.25 19.25
10 30 2000 0-226-30792-1 1 29.30 29.30
10 30 2000 0-87220-390-5 1 229.25 229.25
10 30 2000 <====these are all blanks
10 30 2000 <====these are all blanks
10 30 2000 <====these are all blanks
10 30 2000 <====these are all blanks
10 30 2000 <====these are all blanks
10 30 2000
10 30 2000
10 30 2000
10 30 2000
10 30 2000 until it reaches the next record
10 30 2000 0-324-03301-X 1 8.25 8.25
10 30 2000
10 30 2000
10 30 2000
I want to skip those and end the checking after the last item in the
order but I don't know
when that occurs.
>
>
> > How do I perform a next unless a certain field has a value
>
> Is that what you are trying to do? Well, you do
>
> next if $a[22] eq '';
>
> or
>
> next unless $a[22] eq 'something';
>
> but you'll have to be inside a loop. Are you?
>
> Are you trying to figure out whether there was a line 45 before you
> use
> it?
>
> next unless @a >= 45;
>
> > or skip if there is no value in that field and go to the next
> record.
>
> What is a record? Was that input that we just saw a single record? if
> so, where do the other records live, in other files? If so, you could
> set up a loop
>
> # warning, untested pseudo-code follows. Check, adapt and debug as
> # needed
>
> RECORD:
> foreach my $record (@records)
> {
> open (REC, $record) or die "Cannot open record $record: $!";
>
> chomp(my @a = <REC>); # no more chomping needed after this
>
> # insert correct processing code here, one of the checks could be;
>
> next RECORD if @a <= 45;
>
> # more code
>
> close REC;
> }
>
> > Also, the last two fields are numeric and can be 4, 5 or 6
> characters
> > (dollar amounts)
> > but I want them right justified as the final result i.e.
> > 10 30 2000 0-06-093195-7 1 9.05 9.05
> > 10 30 2000 0-226-30784-0 1 9.30 9.30
> > 10 30 2000 0-226-30780-8 1 19.25 19.25
> > 10 30 2000 0-226-30792-1 1 29.30 29.30
> > 10 30 2000 0-87220-390-5 1 229.25 229.25
>
> use a format, or use sprintf of printf. This is really what formats
> were
> designed for. See the perlform documentation.
>
> > should printf or sprintf come into play here and how
>
> Yes, or no. I'd use a format in this particular case. But I can't be
> much more specific, because I really don't know what you are trying to
>
> do.
>
> Martien
> --
> Martien Verbruggen |
> Interactive Media Division | Think of the average person. Half of
>
> Commercial Dynamics Pty. Ltd. | the people out there are dumber.
> NSW, Australia |
Subject:
Re: Problem with chomp and print
Date:
Tue, 14 Nov 2000 11:43:58 +1100
From:
mgjv@tradingpost.com.au (Martien Verbruggen)
Organization:
Heliotrope Productions Pty. Ltd.
Newsgroups:
comp.lang.perl.misc
References:
1
On Mon, 13 Nov 2000 23:44:00 GMT,
Alan Melton <arm@home.com> wrote:
> By using this program:
You are not useing -w, and you are not using strict. Those two are
really, really valuable tools when debugging.
> @a = <IN>; # read all lines of this file
> chomp (@vals=@a[1,2,3,10,13,14,15]);
> print OUTPUT join (" ",@vals), "\n";
> chomp (@vals=@a[1,2,3,17,20,21,22]);
Why don't you just chomp(@a) once, instead of repeatedly needing to do
it for the same components? Then you can just do something like:
print OUTPUT join(" ", @a[1,2,3,10,13,14,15]), "\n";
and you won't need the temporary @vals.
> print OUTPUT join (" ",@vals), "\n";
> print unless $a eq /^$/;
^^
Where did that come from?
What is it supposed to be?
Why the eq? Did you mean to match a pattern, or did you mean to check
that something was equal to something else? And what were those things?
And why are you printing to STDOUT suddenly? And what do you want to
print? You're actually printing the valeu of $_, whatever that is.
> chomp (@vals=@a[1,2,3,24,27,28,29]);
> print OUTPUT join (" ",@vals), "\n";
> print unless ($a[22]) eq /^$/;
print OUTPUT "something\n" unless $a[22] eq "";
> chomp (@vals=@a[1,2,3,31,34,35,36]);
> print OUTPUT join (" ",@vals), "\n";
> print unless ($a[28]) eq /^$/;
> chomp (@vals=@a[1,2,3,38,41,42,43]);
> print OUTPUT join (" ",@vals), "\n";
> print unless ($a[34]) eq /^$/;
> chomp (@vals=@a[1,2,3,45,48,49,50]);
> print OUTPUT join (" ",@vals), "\n";
> print unless ($a[40]) eq /^$/;
> chomp (@vals=@a[1,2,3,52,55,56,57]);
> print OUTPUT join (" ",@vals), "\n";
> print unless ($a[46]) eq /^$/;
> chomp (@vals=@a[1,2,3,59,62,63,64]);
> print OUTPUT join (" ",@vals), "\n";
> print unless ($a[52]) eq /^$/;
I only count 45 lines in your input. Your indexes are much larger than 44.
Why don't you just tell us what it is you're trying to do?
> How do I perform a next unless a certain field has a value
Is that what you are trying to do? Well, you do
next if $a[22] eq '';
or
next unless $a[22] eq 'something';
but you'll have to be inside a loop. Are you?
Are you trying to figure out whether there was a line 45 before you use
it?
next unless @a >= 45;
> or skip if there is no value in that field and go to the next record.
What is a record? Was that input that we just saw a single record? if
so, where do the other records live, in other files? If so, you could
set up a loop
# warning, untested pseudo-code follows. Check, adapt and debug as
# needed
RECORD:
foreach my $record (@records)
{
open (REC, $record) or die "Cannot open record $record: $!";
chomp(my @a = <REC>); # no more chomping needed after this
# insert correct processing code here, one of the checks could be;
next RECORD if @a <= 45;
# more code
close REC;
}
> Also, the last two fields are numeric and can be 4, 5 or 6 characters
> (dollar amounts)
> but I want them right justified as the final result i.e.
> 10 30 2000 0-06-093195-7 1 9.05 9.05
> 10 30 2000 0-226-30784-0 1 9.30 9.30
> 10 30 2000 0-226-30780-8 1 19.25 19.25
> 10 30 2000 0-226-30792-1 1 29.30 29.30
> 10 30 2000 0-87220-390-5 1 229.25 229.25
use a format, or use sprintf of printf. This is really what formats were
designed for. See the perlform documentation.
> should printf or sprintf come into play here and how
Yes, or no. I'd use a format in this particular case. But I can't be
much more specific, because I really don't know what you are trying to
do.
Martien
--
Martien Verbruggen |
Interactive Media Division | Think of the average person. Half of
Commercial Dynamics Pty. Ltd. | the people out there are dumber.
NSW, Australia |
------------------------------
Date: Tue, 14 Nov 2000 02:33:58 GMT
From: quagly <quagly@home.com>
Subject: Re: Problems compiling DBI and HP-UX 11.0
Message-Id: <3A10A48F.9ADAB3F1@home.com>
Frank Harris wrote:
> I'm having a heck of a time trying to get DBI to compile with my HP-UX
> 11 system. I am guessing that the version of CC on the system isn't
> exactly ANSI compliant, so I went ahead and installed GCC without any
> troubles. Now I receive this message when I compile DBI using GCC:
>
> /opt/gcc/bin/gcc -c -Ae -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O
> +Onolimit -DVERSION=\"1.14\" -DXS_VERSION=\"1.14\" +z
> -I/opt/perl5/lib/5.6.0/PA-RISC1.1/CORE -DDBI_NO_THREADS Perl.c
> gcc: +Onolimit: No such file or directory
> gcc: +z: No such file or directory
> *Initialization*:1: missing token-sequence in `#assert'
> *** Error exit code 1
>
> Stop.
>
> -----------------------------------------
> Any ideas how to fix this problem?
>
> Any help that can be provided on this issue would be greatly
> appreciated.
>
> Thanks,
> Frank
This is a known HP/DBI problem. We had to link DBI/DBD statically to get
it to work.
Thanks,
~quagly
------------------------------
Date: Tue, 14 Nov 2000 04:02:49 GMT
From: Quantum Mechanic <quantum_mechanic@my-deja.com>
Subject: Re: Random Array with Sort?
Message-Id: <8uqdh7$4ve$1@nnrp1.deja.com>
In article <m3itptt9yl.fsf@mumonkan.sunstarsys.com>,
Joe Schaefer <joe+usenet@sunstarsys.com> wrote:
> Ilmari Karonen <iltzu@sci.invalid> writes:
>
> > I think your implementation has a bug. The way you've written it,
the
> > probability of selecting element $i (i.e. no swap occurring) is
twice
> > as high as that of selecting any lower element. Here's a fix:
> >
> > sub shuffle {
> > my $i = @_;
> > while ($i > 0) {
> > my $j = int rand($i--); # HOW RANDOM ???
> > @_[$i,$j] = @_[$j,$i];
> > }
> > }
> >
> > That also got rid of the line marked "UGLY".
>
> I think you're right- I like yours better anyway :)
>
> > I would assume that restoring it would only hurt performance, since
> > the check is likely to take longer than the extra swap. I seem to
> > recall somebody having benchmarked this.
>
> There was some discussion of benchmarks for F-Y about 1y ago;
> here'a a URL:
>
>
http://faqchest.dynhost.com/prgm/perlu-l/perl-99/perl-9911/perl-991100/p
erl99110303_18504.html
Thanks for the URL, that was good information and a place I had
forgotten.
>
> --
> Joe Schaefer
>
--
Quantum Mechanics: The dreams stuff is made of.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 14 Nov 2000 16:00:35 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: regular expression for jpg images
Message-Id: <IV4Q5.7$eK.4845@vic.nntp.telstra.net>
"chris @ home" <dextre@pacbell.net> wrote in message
news:3A10632A.A41D82D@pacbell.net...
> How do I convert this regular expression, which gets a handle on all
> images:
>
> <img[^>]+>
>
> To only get image tags which are jpegs, aka, no gifs or pngs. I just
> want to get the
>
> <img src="http://www.wherever.org/images/thisorthat.jpg">
>
This should be a suitable modification, with the caveats that Gwyn
already raised.
<img[^>]+jpg[^>]*>
<img[^>]+jpe?g[^>]*> # this will grab all jpeg as well
Wyzelli
--
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;
------------------------------
Date: Tue, 14 Nov 2000 05:54:32 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Simple regex problem
Message-Id: <x7snovf693.fsf@home.sysarch.com>
>>>>> "OS" == Oliver Söder <soeder@ai-lab.fh-furtwangen.de> writes:
OS> Scalar or array? strlen(@array).
huh? that is not a perl function.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Tue, 14 Nov 2000 07:27:26 +0100
From: Oliver =?iso-8859-1?Q?S=F6der?= <soeder@ai-lab.fh-furtwangen.de>
Subject: Re: Simple regex problem
Message-Id: <3A10DB4E.88D58D8A@ai-lab.fh-furtwangen.de>
Oliver S=F6der wrote:
> =
> "G.A.D.Miles" wrote:
> >
> > On 10 Nov 2000 18:07:18 +0000, nobull@mail.com wrote:
> >
> > >usad1@gadnet.com (G.A.D.Miles) writes:
> > >
> > >> I want to check whether a variable contains more than 1,000
> > >> characters.
> > >
> > >With a regex!?!?
> > >
> > >What's wrong with the obvious method of taking the length of the
> > >variable and using a numerical comparison operator?
> >
> > Obvious to you maybe! I'm new to this and the books aren't helping me=
> > here. I'm still none the wiser. What do you mean by "taking the lengt=
h
> > of the variable"? If I knew the length the problem would be solved.
> >
> > Regards,
> >
> > Drummond
> =
> Scalar or array? strlen(@array).
Ups sorry. =
$stringl=3Dlength($string);
$arrayl=3D$#array;
Oliver S=F6der
------------------------------
Date: Tue, 14 Nov 2000 07:23:28 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Target of goto is too deeply nested
Message-Id: <slrn911q52.an7.rgarciasuarez@rafael.kazibao.net>
Dave Hodson wrote in comp.lang.perl.misc:
>I'm attempting to fix a bug in my code which is causing the following
>DIE msg
>
>"Target of goto is too deeply nested"
>
>I know there is an ENV var that lets me change the # of "levels" a goto
>can climb through, but I cannot find it anywhere.
It seems to me that this kind of settings are set when the perl
interpreter is compiled.
Perhaps should you reshape your code? It's usually considered bad
practice to have too many levels of nesting. It's better that relying on
an environment variable to get your script accepted by the interpreter.
--
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Tue, 14 Nov 2000 04:40:30 GMT
From: Peter BARABAS <z_0_d@my-deja.com>
Subject: What is P5P?
Message-Id: <8uqfnt$6jl$1@nnrp1.deja.com>
EHLO,
I'm interested in what P5P is.
Thanks in advance.
Regards,
Peter BARABAS.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 14 Nov 2000 01:09:10 -0500
From: ftc@meowing.net (Ported and Polished Fluffy)
Subject: Re: What is P5P?
Message-Id: <87n1f3jda1.fsf@litterbox.meowing.net>
Peter BARABAS <z_0_d@my-deja.com> wrote:
> EHLO,
501 ehlo requires domain address
> I'm interested in what P5P is.
perl5-porters, the people who carry Larry Wall's luggage when they're
not too busy beating the living crap out of one another.
perldoc -q support
or read the Perl FAQ, part 1.
Meow.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 4883
**************************************