[9361] in Perl-Users-Digest
Perl-Users Digest, Issue: 2956 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 24 02:07:31 1998
Date: Tue, 23 Jun 98 23:00:26 -0700
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, 23 Jun 1998 Volume: 8 Number: 2956
Today's topics:
Re: after 5 hrs, the beginner beats the s/// (Ronald J Kimball)
Re: CGI.pm without warnings? (Tom Mornini)
Re: Flames.... (nobody)
Re: Flames.... (Chip Salzenberg)
Re: Flames.... (Chip Salzenberg)
Re: Have we got a good free Perl manual? <hp@pobox.com>
Re: MD5 and Perl4 (Abigail)
Re: More Complete Delete Example <luckys@geocities.com>
Newbie Question again johnsand@usa.net
Re: Newbie Question again (Larry Rosler)
Re: Parsing <tags> <melkor@Cal040031.student.utwente.nl>
Re: print and the . operator ?? <eschult.NOSPAM@squonk.net>
Re: print and the . operator ?? <eschult.NOSPAM@squonk.net>
Re: print and the . operator ?? <eschult.NOSPAM@squonk.net>
Re: print and the . operator ?? <eschult.NOSPAM@squonk.net>
Re: print and the . operator ?? <ljz@asfast.com>
Re: printf in assignments <rootbeer@teleport.com>
Re: Problem compiling in Linux <rootbeer@teleport.com>
Re: Regex dilemma (Martien Verbruggen)
Re: Regex dilemma (Ronald J Kimball)
split(); <probavm@h8mail.laf.cat.com>
Re: split(); (Larry Rosler)
Re: split(); <ljz@asfast.com>
Re: system() and security again (Abigail)
Re: Testing perl knowledge (Ronald J Kimball)
THE C.L.P.M. PRAYER [Was Re: Flames...] birgitt@my-dejanews.com
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 24 Jun 1998 01:44:21 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: after 5 hrs, the beginner beats the s///
Message-Id: <1db3q81.1mnn5vjdzx5fkN@bay1-64.quincy.ziplink.net>
Tom Christiansen <tchrist@mox.perl.com> wrote:
> None of whom (modulo me) actually provided the proper answer.
I provided almost exactly the same answer, several hours earlier.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Wed, 24 Jun 1998 04:40:37 GMT
From: tmornini@netcom.com (Tom Mornini)
Subject: Re: CGI.pm without warnings?
Message-Id: <tmorniniEv1Gzp.A2L@netcom.com>
Vivek Khera (khera@kciLink.com) wrote:
: TM> I've been developing an app with CGI.pm and have learned
: TM> a great deal about it. I recently got down to some actual
: TM> control code that decides what to do based upon multiple
: TM> Submit buttons with different names with code that looks
: TM> like this:
: TM> if ($query->param('Submit') eq 'Button 1') {#code here}
: If the button is not "pressed" on the form, then CGI.pm will not have
: a value for the parameter 'Submit', so it returns the value undef.
: if (defined($query->param('Submit')) and
: $query->param('Submit') eq 'Button 1') {#code here}
Ah, yes! Thank you very much. :-)
-- Tom Mornini
-- InfoMania
------------------------------
Date: 24 Jun 1998 04:49:24 GMT
From: ac1@fspc.netsys.itg.telecom.com.au (nobody)
Subject: Re: Flames....
Message-Id: <6mq0gk$aer@newsserver.trl.OZ.AU>
Are these roman dates correct? I read the following as:
1754 September 1993.
The 1754 may be a time of day (rather than the day of month I
expected), but the year is wrong, I beleive (should be
MCMXCVIII ?).
AC.
Abigail (abigail@fnx.com) wrote:
: T. Ames (ames0009@tc.umn.edu) wrote on MDCCLIV September MCMXCIII in
: <URL: news:358c35a7.837222@news.tc.umn.edu>:
: ++ On 20 Jun 1998 19:09:04 GMT, Tom Christiansen <tchrist@mox.perl.com>
: ++ wrote:
: ++
: ++ >grep. man -k. less. find. whatever.
: ++ >
: ++ >If you haven't figured out how to search for things,
: ++ >turn off your computer until you can buy yourself
: ++ >a pet trainer.
: ++ >
: ++ >--tom
: ++
: ++ This is exactly the kind of response that the original poster was
: ++ addressing. You are assuming that someone new to Perl and new to this
: ++ newsgroup (for those are the people who would post a simple question
: ++ or a question that is answered in the FAQ) already knows a) what
: ++ "grep" is and b) how to use it.
: If someone is new to Perl, I assume they did at least one of the following:
: - bought a collection of good books. (Llama and Camel for instance).
: - read perlfunc, perlop, perlsyn and the faq. Skimmed through the rest
: of the documentation.
: Then you either have an index to use, or would know where to find what.
: Now, if you don't want to buy a book, and your computer skills are so
: low you can't even browse a file, you shouldn't be programming Perl anyway.
: Abigail
: --
: perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
: 0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
: =>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
: !$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'
------------------------------
Date: Wed, 24 Jun 1998 00:35:34 GMT
From: chip@mail.atlantic.net (Chip Salzenberg)
Subject: Re: Flames....
Message-Id: <6mphnh$b3a$1@cyprus.atlantic.net>
According to les@MCS.COM (Leslie Mikesell):
>Tom Phoenix <rootbeer@teleport.com> wrote:
>>No, the rule is that a questioner should look in the most appropriate
>>place for their answer. If it's a question about CGI programming, the
>>docs, FAQs, and newsgroups about that are going to be more appropriate
>>than a newsgroup about Perl.
>
>Does that mean it would be a really bad idea to go the to Perl
>Conference to learn about CGI programming --- in spite of the
>fact that the agenda seems to be mostly web-related?
O'Reilly isn't a bunch of volunteers discussing their work/play amongst
themselves. They're a profit-making entity, albeit one with a slightly
broader mind and longer view than most. So there is no real comparison.
--
Chip Salzenberg - a.k.a. - <chip@pobox.com>
"I brought the atom bomb. I think it's a good time to use it." //MST3K
-> Ask me about Perl training and consulting <-
Like Perl? Want to help out? The Perl Institute: www.perl.org
------------------------------
Date: Wed, 24 Jun 1998 00:37:57 GMT
From: chip@mail.atlantic.net (Chip Salzenberg)
Subject: Re: Flames....
Message-Id: <6mphs0$b3r$1@cyprus.atlantic.net>
According to tchrist@mox.perl.com (Tom Christiansen):
>You may have to wait a long time. Unless you're planning
>to campaign in favor of it, I can't help but think that the
>evil news.groupies FUD-spreaders shall have sunk it.
Campaigning for it is the most likely way to kill it.
<doctor> Don't do that, then. </doctor>
--
Chip Salzenberg - a.k.a. - <chip@pobox.com>
"I brought the atom bomb. I think it's a good time to use it." //MST3K
-> Ask me about Perl training and consulting <-
Like Perl? Want to help out? The Perl Institute: www.perl.org
------------------------------
Date: Wed, 24 Jun 1998 04:25:03 GMT
From: robert havoc pennington <hp@pobox.com>
Subject: Re: Have we got a good free Perl manual?
Message-Id: <wsnwwa7whnk.fsf@harper.uchicago.edu>
"Matthew O. Persico" <mpersico@erols.com> writes:
>
> Then what is the solution? Don't use Perl? No. Write a good free manual?
> Yes. Now, who wants to volunteer? How 'bout any of the people Carp
> qw(ing) about the unavailability of said manual? Do I see RMS at the
> front of that line?
Aside from whether the manual already exists, yes, you do see RMS at
the front of the line, that's why it's on the FSF task list. I guess
it's lower priority than whatever else the FSF is doing right now; but
they're planning to do it if no one else does first, assuming the
existing manual isn't satisfactory (and it appears that RMS doesn't
really know if it is).
Putting something on one's list of things to do is not the same as
pointless whining about it not being done.
And no one has suggested not using Perl.
Can we please not create straw opponents?
Havoc Pennington ==== http://pobox.com/~hp
------------------------------
Date: 24 Jun 1998 04:02:47 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: MD5 and Perl4
Message-Id: <6mptp7$cn9$2@client3.news.psi.net>
Pel Lxberg (pallo-njus@orakel.ntnu.no) wrote on MDCCLVII September
MCMXCIII in <URL: news:dt4k968nz1s.fsf@verden.pvv.ntnu.no>:
++
++ Have anyone implemented MD5 checksums routines (primarily for
++ calculating MD5 checksums of files) in Perl4 without using external
++ programs?
++
++ I have used the MD5 module for Perl5, but need to do this in Perl4.
system ("/usr/local/bin/perl5 -MMD5 -e '.....'");
Abigail
--
perl -e '$a = q 94a75737420616e6f74686572205065726c204861636b65720a9 and
${qq$\x5F$} = q 97265646f9 and s g..g;
qq e\x63\x68\x72\x20\x30\x78$&eggee;
{eval if $a =~ s e..eqq qprint chr 0x$& and \x71\x20\x71\x71qeexcess}'
------------------------------
Date: Wed, 24 Jun 1998 00:47:45 -0400
From: Luckys <luckys@geocities.com>
Subject: Re: More Complete Delete Example
Message-Id: <359084F1.A17@geocities.com>
Thanks to everyone who responded, I was able to figure out how to read,
write, and delete to a DBM file. Below is my working example:
#!/usr/bin/perl
use SDBM_File;
use Fcntl;
my $dbm_file = 'fruit';
my $tmp;
# Define Associative Array #
%fruit = ("Green", "Apple", "Orange", "Orange", "Yellow", "Banna" );
# Define key to be deleted #
$tmp = 'Yellow';
# Open SDBM File to Write #
# &SDBM_INIT;
sub SDBM_INIT {
while (($k,$v) = each %fruit) {
tie %f, 'SDBM_File', $dbm_file, O_CREAT|O_RDWR, 0640;
$f{$k} = $v;
untie %f;
print "$k = $v\n";
}
}
# Open SDBM File to Read #
# &SDBM_READ;
sub SDBM_READ {
tie %f, 'SDBM_File', $dbm_file, O_RDWR, 0640;
while (($k,$v) = each %f) { # Make sure array is correct #
print "$k = $v\n";
}
untie %f;
}
# Open SDBM File to Delete #
&SDBM_DELETE;
sub SDBM_DELETE {
tie %f, 'SDBM_File', $dbm_file, O_CREAT|O_RDWR, 0640;
%t = %f;
untie %f;
while (($k,$v) = each %t) { # Make sure array is correct #
if ($k eq $tmp) {
print "Match\n";
delete $t{$k};
}
print "$k = $v\n";
}
print "\n";
system "rm delete.dir";
system "rm delete.pag";
while (($k,$v) = each %t) {
tie %t, 'SDBM_File', $dbm_file, O_CREAT|O_RDWR, 0640;
$t{$k} = $v;
untie %t;
print "$k = $v\n";
}
}
------------------------------
Date: Wed, 24 Jun 1998 04:22:18 GMT
From: johnsand@usa.net
Subject: Newbie Question again
Message-Id: <35907c9f.25130811@news6.bellatlantic.net>
Ok... Since I was not very clear before. I will try to
explain this a little better.... I am not asking anyone to write the
script for me, but I am not sure how to handle the ranges. I think I
figured out the first 2 parts...
What I have is pre-formatted Web Pages such as the following (skipped
the HTML code to be clearer):
Number of Levels : 3
Area of Construction : CountyName
Asking Price = $ 28,000
And I have a form that allows the user to select the MINIMUM
ranges from each of the above lines.... The problem is the last
option list. I have values such as 10000-20000 and 20000-30000
How can I parse the selection the user enters and compare the values
with the 3rd line (Asking Price)
For example.. The user enters the 20000-30000 option. How do I parse
the 20000-30000 into 2 values and then compare if 20000 < 28000 and
30000 > 28000
I hope this is a little clearer... :-)
John Sanderbeck
------------------------------
Date: Tue, 23 Jun 1998 21:39:25 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Newbie Question again
Message-Id: <MPG.ffa22d6838782609896f1@nntp.hpl.hp.com>
In article <35907c9f.25130811@news6.bellatlantic.net>, johnsand@usa.net
<johnsand@usa.net> says...
...
> For example.. The user enters the 20000-30000 option. How do I parse
> the 20000-30000 into 2 values and then compare if 20000 < 28000 and
> 30000 > 28000
$option =~ /(\d+)-(\d+)/; if ($1 < $value && $value < $2) { ... }
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 24 Jun 1998 04:16:28 GMT
From: Thomas van Gulick <melkor@Cal040031.student.utwente.nl>
Subject: Re: Parsing <tags>
Message-Id: <6mpuis$3k2$1@dinkel.civ.utwente.nl>
Tom Christiansen <tchrist@mox.perl.com> wrote:
> [courtesy cc of this posting sent to cited author via email]
>
> In comp.lang.perl.misc,
> Thomas van Gulick <melkor@Cal040031.student.utwente.nl> writes:
> :I was wondering if this might be done using a faster routine.
>
> Is there some reason why you don't use the canned parsing
> returns from LWP?
I've checked it after you mentioned it, but I can't seem to find anythimg
similar to parsing a HTML file for specific tags..
Thomas
--
http://utumno.student.utwente.nl/
melkor@utumno.student.utwente.nl
------------------------------
Date: Mon, 22 Jun 1998 23:57:14 -0400
From: "Eschult" <eschult.NOSPAM@squonk.net>
Subject: Re: print and the . operator ??
Message-Id: <6mpr3a$6ah$1@duke.squonk.net>
$line includes the line termination character, which you are appending to
$grades{student}. The print is printing it, yielding the extra blanks in
your output.
Try adding 'chop $line;' as your first line after the 'while ($line......)
{' line.
As to why '.=' behaves like '=', in your sample data there are no duplicates
of student names. If there were '.=' would append the grades, whereas "="
would replace the 1st grade with the 2nd.
Which is 'right' depends on what you're trying to accomplish.
Seo Choi wrote in message ...
>#!/usr/bin/perl
>
>open(GRADES, "grades") || die "Can't open grades: $!\n";
>while($line = <GRADES>) {
> ($student, $grade) = split(" ", $line);
> $grades{$student} .= $grade . " ";
> $gList{$student} = $grade . " ";
>}
>
>foreach $student (%grades) {
> print "$grades{$student}\n";
>}
>
>print "-" x 25, "\n";
>foreach $student (%gList) {
> print "$grades{$student}\n";
>}
>
>from the code above I have two questions. the first is why in the line
> $grades{$student} .=
>behaves the same way as
> $grades{$student} = without the dot
>
>
>the second question is why I have the output when using the attachment as
>the input file as:
>3
>
>5
>
>4
>
>1
>
>2
>
>-------------------------
>3
>
>5
>
>4
>
>1
>
>2
>
>because when i take the "\n" from the two foreach loops the out pout is
>only two lines long??
------------------------------
Date: Mon, 22 Jun 1998 23:57:14 -0400
From: "Eschult" <eschult.NOSPAM@squonk.net>
Subject: Re: print and the . operator ??
Message-Id: <6mps40$6dm$1@duke.squonk.net>
$line includes the line termination character, which you are appending to
$grades{student}. The print is printing it, yielding the extra blanks in
your output.
Try adding 'chop $line;' as your first line after the 'while ($line......)
{' line.
As to why '.=' behaves like '=', in your sample data there are no duplicates
of student names. If there were '.=' would append the grades, whereas "="
would replace the 1st grade with the 2nd.
Which is 'right' depends on what you're trying to accomplish.
Seo Choi wrote in message ...
>#!/usr/bin/perl
>
>open(GRADES, "grades") || die "Can't open grades: $!\n";
>while($line = <GRADES>) {
> ($student, $grade) = split(" ", $line);
> $grades{$student} .= $grade . " ";
> $gList{$student} = $grade . " ";
>}
>
>foreach $student (%grades) {
> print "$grades{$student}\n";
>}
>
>print "-" x 25, "\n";
>foreach $student (%gList) {
> print "$grades{$student}\n";
>}
>
>from the code above I have two questions. the first is why in the line
> $grades{$student} .=
>behaves the same way as
> $grades{$student} = without the dot
>
>
>the second question is why I have the output when using the attachment as
>the input file as:
>3
>
>5
>
>4
>
>1
>
>2
>
>-------------------------
>3
>
>5
>
>4
>
>1
>
>2
>
>because when i take the "\n" from the two foreach loops the out pout is
>only two lines long??
------------------------------
Date: Mon, 22 Jun 1998 23:57:14 -0400
From: "Eschult" <eschult.NOSPAM@squonk.net>
Subject: Re: print and the . operator ??
Message-Id: <6mpp02$65c$1@duke.squonk.net>
$line includes the line termination character, which you are appending to
$grades{student}. The print is printing it, yielding the extra blanks in
your output.
Try adding 'chop $line;' as your first line after the 'while ($line......)
{' line.
As to why '.=' behaves like '=', in your sample data there are no duplicates
of student names. If there were '.=' would append the grades, whereas "="
would replace the 1st grade with the 2nd.
Which is 'right' depends on what you're trying to accomplish.
Seo Choi wrote in message ...
>#!/usr/bin/perl
>
>open(GRADES, "grades") || die "Can't open grades: $!\n";
>while($line = <GRADES>) {
> ($student, $grade) = split(" ", $line);
> $grades{$student} .= $grade . " ";
> $gList{$student} = $grade . " ";
>}
>
>foreach $student (%grades) {
> print "$grades{$student}\n";
>}
>
>print "-" x 25, "\n";
>foreach $student (%gList) {
> print "$grades{$student}\n";
>}
>
>from the code above I have two questions. the first is why in the line
> $grades{$student} .=
>behaves the same way as
> $grades{$student} = without the dot
>
>
>the second question is why I have the output when using the attachment as
>the input file as:
>3
>
>5
>
>4
>
>1
>
>2
>
>-------------------------
>3
>
>5
>
>4
>
>1
>
>2
>
>because when i take the "\n" from the two foreach loops the out pout is
>only two lines long??
------------------------------
Date: Mon, 22 Jun 1998 23:57:14 -0400
From: "Eschult" <eschult.NOSPAM@squonk.net>
Subject: Re: print and the . operator ??
Message-Id: <6mpq2q$670$1@duke.squonk.net>
$line includes the line termination character, which you are appending to
$grades{student}. The print is printing it, yielding the extra blanks in
your output.
Try adding 'chop $line;' as your first line after the 'while ($line......)
{' line.
As to why '.=' behaves like '=', in your sample data there are no duplicates
of student names. If there were '.=' would append the grades, whereas "="
would replace the 1st grade with the 2nd.
Which is 'right' depends on what you're trying to accomplish.
Seo Choi wrote in message ...
>#!/usr/bin/perl
>
>open(GRADES, "grades") || die "Can't open grades: $!\n";
>while($line = <GRADES>) {
> ($student, $grade) = split(" ", $line);
> $grades{$student} .= $grade . " ";
> $gList{$student} = $grade . " ";
>}
>
>foreach $student (%grades) {
> print "$grades{$student}\n";
>}
>
>print "-" x 25, "\n";
>foreach $student (%gList) {
> print "$grades{$student}\n";
>}
>
>from the code above I have two questions. the first is why in the line
> $grades{$student} .=
>behaves the same way as
> $grades{$student} = without the dot
>
>
>the second question is why I have the output when using the attachment as
>the input file as:
>3
>
>5
>
>4
>
>1
>
>2
>
>-------------------------
>3
>
>5
>
>4
>
>1
>
>2
>
>because when i take the "\n" from the two foreach loops the out pout is
>only two lines long??
------------------------------
Date: 24 Jun 1998 00:26:46 -0400
From: Lloyd Zusman <ljz@asfast.com>
Subject: Re: print and the . operator ??
Message-Id: <lt90mne86x.fsf@asfast.com>
"Eschult" <eschult.NOSPAM@squonk.net> writes:
> $line includes the line termination character, which you are appending to
> $grades{student}. The print is printing it, yielding the extra blanks in
> your output.
>
> Try adding 'chop $line;' as your first line after the 'while ($line......)
> {' line.
One small point: `chomp' may a bit better than `chop' here, although
you may not notice a difference in your particular case. But `chomp'
is more intelligent than `chop' and is preferred here.
`chop' ... remove the rightmost character from a string
`chomp' ... if the rightmost character of a string is the
"input record separator" (usually newline), then
remove it from the string; otherwise, do nothing
> [ ... ]
--
Lloyd Zusman ljz@asfast.com
perl -e '$n=170;for($d=2;($d*$d)<=$n;$d+=(1+($d%2))){for($t=0;($n%$d)==0;
$t++){$n=int($n/$d);}while($t-->0){push(@r,$d);}}if($n>1){push(@r,$n);}
$x=0;map{$x+=(($_>0)?(1<<log($_-0.5)/log(2.0)+1):1)}@r;print"$x\n"'
------------------------------
Date: Wed, 24 Jun 1998 05:36:40 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: printf in assignments
Message-Id: <Pine.GSO.3.96.980623222901.16155D-100000@user2.teleport.com>
On 24 Jun 1998, Stuart Cooper wrote:
> Those from a C programming background should also note that the return
> value of a successful Perl printf is 1; while the return value of a C
> printf is number-of-characters-printed. Maybe this should be documented
> in perltrap in the 'C traps' section; next to the note about printf not
> supporting the '*' format.
Or, even better, in place of that note. :-) (These days, printf does
support the '*' format.) When you make your patch to the docs, be sure to
mention that print, like printf, normally returns 1.
> If you need to get number of characters printf will print;
> try a combination of sprintf and length like this:
>
> $width= length(sprintf("%d%s",$count," bananas"));
Oh, that's a waste. Now you're going to calculate that string a second
time merely to print it? It's only a small inefficiency but, still,
anything you're calculating twice you should probably have saved the first
time.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 24 Jun 1998 05:44:14 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Problem compiling in Linux
Message-Id: <Pine.GSO.3.96.980623224110.16155E-100000@user2.teleport.com>
On Wed, 24 Jun 1998, Ken Ingram wrote:
> I've tried to compile and run a simple program with:
>
> cc -O2 -Dbool=char -DHAS_BOOL -I/usr/local/include
> -L/usr/local/lib -o try try.c -lgdbm -ldb -ldl -lm -lc
> ./try
>
> and I got the following output:
>
> /usr/i486-linux/bin/ld: cannot open -ldl: No such file or directory
> I can't compile the test program.
I'm not sure, but have you considered the possibility that maybe you
shouldn't have -ldl in there? The folks on a Linux newsgroup may know
more. Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 24 Jun 1998 03:49:50 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Regex dilemma
Message-Id: <6mpt0u$t4n$1@comdyn.comdyn.com.au>
In article <he_j1.124$lC3.3299462@news.rdc1.md.home.com>,
"Dave Methvin" <dm@ho.com> writes:
> local $/ = '\014';
> while ( <INFILE>) {
> %fields = m/^([^:]+):\s*(.*)$/mg;
I think the \s in there might be matching the newline... Should it..
Hmm.. anyway, if you want to match a possible space, you should
probably just say so in this case:
%fields = m/^([^:]+): ?(.*)$/mg;
works for me. Sometimes it pays off to match as minimally as possible:
if you mean a space, call it a space.
> # do something with the record here...
> }
>
> The problem is that empty items like Address2 mess up the pairing that I
> wanted to capture in the match. Any ideas on how to adjust the regex to fix
> this? Ideally I'd like to get an empty string or undef for items that had no
Maybe even better: use split, instead of a regexp. I personally find
it more readable.
#!/usr/local/bin/perl -w
use strict;
$/ = "\014";
while (<DATA>)
{
chomp;
my @rows = split /\n/;
foreach (@rows)
{
next if ($_ eq '');
my ($key, $value) = split /:\s?/;
print "$key, $value\n";
}
}
__DATA__
Name: George Watson
Address1: 123 Any Street
Address2:
City: Columbus
State: GA
Name: Sally Simpson
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au |
Commercial Dynamics Pty. Ltd. | Curiouser and curiouser, said Alice.
NSW, Australia |
------------------------------
Date: Wed, 24 Jun 1998 01:44:22 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Regex dilemma
Message-Id: <1db3sw7.132wpmq15q9nr8N@bay1-64.quincy.ziplink.net>
[posted and mailed]
Dave Methvin <dm@ho.com> wrote:
> Address1: 123 Any Street
> Address2:
> City: Columbus
> %fields = m/^([^:]+):\s*(.*)$/mg;
^^^
\s* is matching the newline following an empty item.
Try changing it to [ \t]* or [^\s\n]*.
You also might want to change [^:] to [^:\n].
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Tue, 23 Jun 1998 14:49:32 -0500
From: "Vincent M. Probasco" <probavm@h8mail.laf.cat.com>
Subject: split();
Message-Id: <359006CC.EF9052F5@h8mail.laf.cat.com>
I know there must be a simple solution to this but it's beyond my scope.
I've looked at the manual
again and again and I can't see what's wrong with this.
$theline contains
981269|<TD> <A
HREF="mailto:probavm@h8mail.laf.cat.com">probavm@h8mail.laf.cat.c
om</A></TD>|<TD> 5555 </TD>|<TD> Minor: test </TD>|2|pending
before hitting the split.(except it's all 1 line. There is no \n
character.)
($number,$user,$dept,$descript,$time,$category)=split(/|/, $theline);
I'm getting the number 981269 split like $number = 9, $user = 8, $dept =
1, $descript = 2,...
Any advice would be really helpfull right now. Thanks,
Vince
------------------------------
Date: Tue, 23 Jun 1998 21:34:54 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: split();
Message-Id: <MPG.ffa21c8536eed039896f0@nntp.hpl.hp.com>
In article <359006CC.EF9052F5@h8mail.laf.cat.com>, Vincent M. Probasco
<probavm@h8mail.laf.cat.com> says...
...
> ($number,$user,$dept,$descript,$time,$category)=split(/|/, $theline);
'|' is a metacharacter in the split regex. Use
split(/\|/, ...
and all will be well.
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 24 Jun 1998 00:36:14 -0400
From: Lloyd Zusman <ljz@asfast.com>
Subject: Re: split();
Message-Id: <lt67hre7r5.fsf@asfast.com>
"Vincent M. Probasco" <probavm@h8mail.laf.cat.com> writes:
> [ ... ]
>
> ($number,$user,$dept,$descript,$time,$category)=split(/|/, $theline);
>
> I'm getting the number 981269 split like $number = 9, $user = 8, $dept =
> 1, $descript = 2,...
>
> Any advice would be really helpfull right now. Thanks,
The `|' character is special in a regular expression, and hence, you
would need to "escape" it, as follows, if you wanted to treat it
literally:
($number,$user,$dept,$descript,$time,$category)=split(/\|/, $theline);
^
backslash
--
Lloyd Zusman ljz@asfast.com
perl -e '$n=170;for($d=2;($d*$d)<=$n;$d+=(1+($d%2))){for($t=0;($n%$d)==0;
$t++){$n=int($n/$d);}while($t-->0){push(@r,$d);}}if($n>1){push(@r,$n);}
$x=0;map{$x+=(($_>0)?(1<<log($_-0.5)/log(2.0)+1):1)}@r;print"$x\n"'
------------------------------
Date: 24 Jun 1998 03:56:46 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: system() and security again
Message-Id: <6mptdu$cn9$1@client3.news.psi.net>
Marc Haber (Marc.Haber-usenet@gmx.de) wrote on MDCCLVII September
MCMXCIII in <URL: news:6mo3o1$d0p$2@nz12.rz.uni-karlsruhe.de>:
++ Russ Allbery <rra@stanford.edu> wrote:
++ >Marc Haber <Marc.Haber-usenet@gmx.de> writes:
++ >> The docs say that system() uses a subshell if shell metacharacters are
++ >> contained in the command. I know ";", ">", "<", "|" and "`" as shell
++ >> metacharacters. Are there more?
++ >
++ >Yes. "(", ")", "*", "[", "]", "^", and possibly others, depending on your
++ >shell.
++
++ Are there others for a standard bash? If that differs from shell to
++ shell, parsing for metacharacters may be a major nuisance and using a
++ different shell will break that code :-(
You forgot newline. And ?. And $. And { and }. And &. And #. And
in certain cases, =, : and -. Which of course differs from shell to
shell. And let's not forget the quotes. Or the backwack.
Abigail
--
perl -we '$_ = q ;4a75737420616e6f74686572205065726c204861636b65720as;;
for (s;s;s;s;s;s;s;s;s;s;s;s)
{s;(..)s?;qq qprint chr 0x$1 and \161 ssq;excess;}'
------------------------------
Date: Wed, 24 Jun 1998 01:44:25 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Testing perl knowledge
Message-Id: <1db3tz7.hn0bb2h0n4jN@bay1-64.quincy.ziplink.net>
John Stanley <stanley@skyking.OCE.ORST.EDU> wrote:
> >I am a Certified Perl Engineer (CPE). I sent e-mail to a guy who
> >certified me. I also certified myself.
>
> You should be careful with this. Many states assign special legal status
> to the title "engineer".
You have to be able to drive a train.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Wed, 24 Jun 1998 04:20:41 GMT
From: birgitt@my-dejanews.com
Subject: THE C.L.P.M. PRAYER [Was Re: Flames...]
Message-Id: <6mpuqp$vp$1@nnrp1.dejanews.com>
In article <6mn1a0$hlf$1@csnews.cs.colorado.edu>,
tchrist@mox.perl.com (Tom Christiansen) wrote:
>
> [courtesy cc of this posting sent to cited author via email]
>
> In comp.lang.perl.misc, birgitt@my-dejanews.com writes many things.
>
> I suggest that you draft you proposed daily postings regarding what
> people should know. I expect that it shall make no difference at all.
As I unfortunately promised to do what you asked for....
THE C.L.P.M PRAYER
Before I post
Do more than look, search
Do more than read, absorb
Do more than think, ponder
Do more than hear, listen
Do more than listen, understand
Do more than talk, say something
Do more than ask, answer
Before you post
Take time to work,
Take time to think,
Take time to be friendly,
Take time to share,
Take time to laugh,
When we post
We do all the good we can,
By all the means we can,
In all the ways we can,
In all the posts we can,
At all the times we can,
To all the people we can,
As long as ever we can.
When we have posted and done our best
We should wait the result in peace.
:-)
What should I do ? Crying, laughing or getting a rope ?
Birgitt Funk
P.S.
Forget and forgive me all the rubbish I ever posted in response to
Tom Phoenix. It took me an hour of reading Tom Phoenix posts
exclusively and it clicked. It never would work what I thought
could work.
All your answers are so desperately needed that one never could
do what I called "tough love" approach.
And please do me a favour. Killfile this thingy. I am taught to
keep my word, when I promised to do something. Very unwise of
my mom and dad as you can see ...
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 2956
**************************************