[19757] in Perl-Users-Digest
Perl-Users Digest, Issue: 1952 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 18 00:10:30 2001
Date: Wed, 17 Oct 2001 21:10:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1003378211-v10-i1952@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 17 Oct 2001 Volume: 10 Number: 1952
Today's topics:
Programmer Newbie <cej4@cornell.edu>
Re: Programmer Newbie <mragsdal@utk.edu>
Re: Programmer Newbie <tony_curtis32@yahoo.com>
Re: Programmer Newbie (Martien Verbruggen)
Re: Programmer Newbie <wyzelli@yahoo.com>
Re: Programmer Newbie (Logan Shaw)
Re: push, pop, shift, unshift, splice et al (JRoot)
Scaling a DNA string <DocDodge@hotmail.com>
Re: Scaling a DNA string <wyzelli@yahoo.com>
Re: Specifying a range of values <goldbb2@earthlink.net>
Re: Splitting on value pairs <tintin@snowy.calculus>
Re: Splitting on value pairs <tintin@snowy.calculus>
Re: Splitting on value pairs <tintin@snowy.calculus>
Re: Splitting on value pairs (Garry Williams)
Troubleshootng Bundle::libnet installation <bill02115@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 17 Oct 2001 22:11:31 -0400
From: Charles Jessop <cej4@cornell.edu>
Subject: Programmer Newbie
Message-Id: <MPG.1638044266693c75989680@newsstand.cit.cornell.edu>
Good evening!
I am learning perl on my own and need a little help. May I ask, if I had
the following array:
@chkbrd = ("xoxoxoxo", "oxoxoxox");
how would I have it print out eight total rows of alternating elements
to make a checkerboard?
I know this so very elementary, so thank you for any assistance.
Best,
Chuck
------------------------------
Date: Wed, 17 Oct 2001 22:39:54 -0400
From: Mike Ragsdale <mragsdal@utk.edu>
Subject: Re: Programmer Newbie
Message-Id: <3BCE40FA.362D19F5@utk.edu>
Charles Jessop wrote:
>
> Good evening!
>
> I am learning perl on my own and need a little help. May I ask, if I had
> the following array:
>
> @chkbrd = ("xoxoxoxo", "oxoxoxox");
>
> how would I have it print out eight total rows of alternating elements
> to make a checkerboard?
Try this:
for (my $i=0; $i<4; $i++) {
print "$chkbrd[0]\n$chkbrd[1]\n";
}
-Mike
------------------------------
Date: Wed, 17 Oct 2001 21:39:59 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Programmer Newbie
Message-Id: <87zo6pu0w0.fsf@limey.hpcc.uh.edu>
>> On Wed, 17 Oct 2001 22:39:54 -0400,
>> Mike Ragsdale <mragsdal@utk.edu> said:
> Charles Jessop wrote:
>> Good evening!
>>
>> I am learning perl on my own and need a little
>> help. May I ask, if I had the following array:
>>
>> @chkbrd = ("xoxoxoxo", "oxoxoxox");
>>
>> how would I have it print out eight total rows of
>> alternating elements to make a checkerboard?
> Try this:
> for (my $i=0; $i<4; $i++) { print
> "$chkbrd[0]\n$chkbrd[1]\n";
> }
Hmmm, to be brutal, that looks like horribly C-like; more
perlish might be:
for (1..4) {
print "$_\n" for @chkbrd;
}
hth
t
--
Oh! I've said too much. Smithers, use the amnesia ray.
------------------------------
Date: Thu, 18 Oct 2001 02:49:54 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Programmer Newbie
Message-Id: <slrn9ssgqi.l88.mgjv@verbruggen.comdyn.com.au>
On Wed, 17 Oct 2001 21:39:59 -0500,
Tony Curtis <tony_curtis32@yahoo.com> wrote:
>>> On Wed, 17 Oct 2001 22:39:54 -0400,
>>> Mike Ragsdale <mragsdal@utk.edu> said:
>> Charles Jessop wrote:
>>>
>>> @chkbrd = ("xoxoxoxo", "oxoxoxox");
>>>
>>> how would I have it print out eight total rows of
>>> alternating elements to make a checkerboard?
>
>> for (my $i=0; $i<4; $i++) { print
>> "$chkbrd[0]\n$chkbrd[1]\n";
>> }
>
> Hmmm, to be brutal, that looks like horribly C-like; more
> perlish might be:
>
> for (1..4) {
> print "$_\n" for @chkbrd;
> }
Maybe one of
print "$_\n" for (@chkbrd) x 4;
print join "\n", (@chkbrd) x 4;
print map "$_\n", (@chkbrd) x 4;
Yes, the parentheses are needed.
Martien
--
Martien Verbruggen |
| If it isn't broken, it doesn't have
Trading Post Australia Pty Ltd | enough features yet.
|
------------------------------
Date: Thu, 18 Oct 2001 12:38:18 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Programmer Newbie
Message-Id: <8Arz7.35$mP1.285@wa.nnrp.telstra.net>
"Tony Curtis" <tony_curtis32@yahoo.com> wrote in message
news:87zo6pu0w0.fsf@limey.hpcc.uh.edu...
> >> On Wed, 17 Oct 2001 22:39:54 -0400,
> >> Mike Ragsdale <mragsdal@utk.edu> said:
>
> > Charles Jessop wrote:
> >> Good evening!
> >>
> >> I am learning perl on my own and need a little
> >> help. May I ask, if I had the following array:
> >>
> >> @chkbrd = ("xoxoxoxo", "oxoxoxox");
> >>
> >> how would I have it print out eight total rows of
> >> alternating elements to make a checkerboard?
<snip>
> Hmmm, to be brutal, that looks like horribly C-like; more
> perlish might be:
>
> for (1..4) {
> print "$_\n" for @chkbrd;
> }
Just for fun, here is a way to do it with a single scalar, rather than the
array:
$brd = 'xoxoxoxo';
for (1..8) {
print "$brd\n";
$brd = reverse $brd;
}
Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass it
around');
$d='$_$a$s$b$w';$e='$_$a$s$b';sub d{$h=shift;$h=~s/\$(\w+)/${$1}/g;return$h}
sub
e{return(shift!=1)?'s':''}for(reverse(1..100)){$s=e($_);$f=d($d);$g=d($e);
$c.="$f\n$g\n$t\n";$_--;$s=e($_);$e=d($d);$c.="$e\n\n";}print"$c*hic*";
------------------------------
Date: 17 Oct 2001 22:49:59 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Programmer Newbie
Message-Id: <9qljh7$omi$1@charity.cs.utexas.edu>
In article <87zo6pu0w0.fsf@limey.hpcc.uh.edu>,
Tony Curtis <tony_curtis32@yahoo.com> wrote:
>>> On Wed, 17 Oct 2001 22:39:54 -0400,
>>> Mike Ragsdale <mragsdal@utk.edu> said:
>> Charles Jessop wrote:
>>> I am learning perl on my own and need a little
>>> help. May I ask, if I had the following array:
>>>
>>> @chkbrd = ("xoxoxoxo", "oxoxoxox");
>>>
>>> how would I have it print out eight total rows of
>>> alternating elements to make a checkerboard?
>> for (my $i=0; $i<4; $i++) { print
>> "$chkbrd[0]\n$chkbrd[1]\n";
>> }
>Hmmm, to be brutal, that looks like horribly C-like; more
>perlish might be:
>
> for (1..4) {
> print "$_\n" for @chkbrd;
> }
I was actually thinking something like
foreach my $index ( (0,1) x 4 )
{
print $chkbrd[$index], "\n";
}
Or for simplicity change "(0,1) x 4" to "0,1,0,1,0,1,0,1".
The nice and simple one-liner approach:
print "$chkbrd[0]\n$chkbrd[1]\n" x 4;
The JAPH-worthy approach:
print map ("$chkbrd[$_]\n", split (//, unpack ("B*", pack ("C", 0xff/3))));
I stole the divide-by-three trick from some other thread. It might
very well have been in this newsgroup; I can't remember.
- Logan
--
"In order to be prepared to hope in what does not deceive,
we must first lose hope in everything that deceives."
Georges Bernanos
------------------------------
Date: 17 Oct 2001 20:51:08 -0700
From: awkster@yahoo.com (JRoot)
Subject: Re: push, pop, shift, unshift, splice et al
Message-Id: <9efa6216.0110171951.47c19386@posting.google.com>
Thelma Lubkin <thelma@alpha2.csd.uwm.edu> wrote in message news:<9ql2hs$t2h$1@uwm.edu>...
> JRoot <awkster@yahoo.com> wrote:
> : I need to loop through an array, identifying each element
> : then discarding the element thus leaving an empty array when
> : the loop finishes.
>
> : I read the faq's and perldocs on push, pop, shift, unshift
> : and splice. I thought I had it figured out but when I ran this
> : little program as a test, it never empties the array. It stops
> : half way apparently because it re-indexes the array each time
> : it shifts ????
>
> : Is there someway I can get around this behaviour??
> : Please don't send me back to the faq'a ... I'm all popped out.
>
> : Thanks for the help
>
> : #!perl -w
>
> : use strict;
>
> : my($x, $y);
> : my @x = (1...10);
>
> : foreach $x(@x){
> : print "# Element $x\n";
> : print "# Array: @x\n";
> : $y = shift(@x);
> : print "# Element removed: $y\n";
> : }
>
> : # Element 1
> : # Array: 1 2 3 4 5 6 7 8 9 10
> : # Element removed: 1
> : # Element 3
> : # Array: 2 3 4 5 6 7 8 9 10
> : # Element removed: 2
> : # Element 5
> : # Array: 3 4 5 6 7 8 9 10
> : # Element removed: 3
> : # Element 7
> : # Array: 4 5 6 7 8 9 10
> : # Element removed: 4
> : # Element 9
> : # Array: 5 6 7 8 9 10
> : # Element removed: 5
>
>
> Is there a reason that you need to remove the elements one at a time?
> Why not print the elements and then set the array empty?
>
> #!perl -w
>
> use strict;
>
> my($x);
> my @x = (1...10);
>
> foreach $x(@x){
> print "# Element $x\n";
> }
>
> @x = ();
Actually there is ... in real life I will be testing each
element of the array and what doesn't pass the test will
be left in the array. The remaining array elements will
then be used in the next step of the program.
I believe the reponses to my post have answered my question.
Thanks much to all who responded.
------------------------------
Date: Wed, 17 Oct 2001 22:52:57 -0400
From: "DocDodge" <DocDodge@hotmail.com>
Subject: Scaling a DNA string
Message-Id: <9qlfsv$23b$1@bob.news.rcn.net>
Hi,
I have what is a tricky biology problem, but an easy perl problem.
Unfortunately, while I'm competent biologist, I'm a complete newbie at perl.
As you may know, the DNA which codes for all the instructions of life is
simply a string composed of the four characters A, C, G, or T. We have
experimental evidence that suggests that a motif composed of four G's or
four C's in a row might have implications for how some genes are regulated.
But, it would matter how close these motifs are to the genes they are
suppose to control.
So, I grabbed 2000 characters from nearby an important gene and stored it in
a string. Here is what part of that might look like:
...ACGACGTCCAGGGGGGTTGTTACGTCCCCAATCAGTCGGGGCTATTCAGTC...
Next I replaced all the unimportant characters with at dash so we can see
where these motifs are:
...----------GGGGGG---------CCCC--------GGGG----------...
But as you might imagine, I'm having trouble printing out these 2000
character long strings in a readable format. What I need to do is scale the
string down to a reasonable size. What I've tried to do is use a for loop
with and index of 10 to replace all the instances or 10 dashes with a single
dash. If a G or C is found in the 10 character region, a single G or C is
printed. Here is how the scaled version looks:
...-GC-GG-...
The problem is that someone looking at this scaled version would think that
this string of DNA characters has four motifs in this short region. But it
only has three. The last GGGG gets counted twice because it is crosses over
two different 10 character long chunks.
And, if I scale the string by looking for GGGG or CCCC in any 10 character
long chunk, I will underestimated the number of motifs to this:
...-GC----...
What I really want to scale the string to is this ...-GC-G--... ( or this
...-GC--G-..., small position shifts are inconsequential as long as the
number of motifs is accurate).
I hope this is clear and not to long winded. I figured the problem would be
more fun if the background context was included. Here is the code I have
written so far to scale the string:
for ($i = 0; $i < length ($sequence); $i += 10) {
if (substr ($sequence, $i, 10) =~ /G/i) {
print "G"
} elsif (substr ($sequence, $i, 10) =~/C/i) {
print "C";
} else {
print "-";
}
}
TIA
------------------------------
Date: Thu, 18 Oct 2001 13:09:51 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Scaling a DNA string
Message-Id: <I1sz7.40$mP1.461@wa.nnrp.telstra.net>
"DocDodge" <DocDodge@hotmail.com> wrote in message
news:9qlfsv$23b$1@bob.news.rcn.net...
> Hi,
>
> I have what is a tricky biology problem, but an easy perl problem.
> Unfortunately, while I'm competent biologist, I'm a complete newbie at
perl.
>
> As you may know, the DNA which codes for all the instructions of life is
> simply a string composed of the four characters A, C, G, or T. We have
> experimental evidence that suggests that a motif composed of four G's or
> four C's in a row might have implications for how some genes are
regulated.
> But, it would matter how close these motifs are to the genes they are
> suppose to control.
>
> So, I grabbed 2000 characters from nearby an important gene and stored it
in
> a string. Here is what part of that might look like:
>
> ...ACGACGTCCAGGGGGGTTGTTACGTCCCCAATCAGTCGGGGCTATTCAGTC...
{snip}
> What I really want to scale the string to is this ...-GC-G--... ( or this
> ...-GC--G-..., small position shifts are inconsequential as long as the
> number of motifs is accurate).
>
> I hope this is clear and not to long winded. I figured the problem would
be
> more fun if the background context was included. Here is the code I have
> written so far to scale the string:
Well, I am not really too clear on exactly what the rules are from the
above, but as a starting point I tried the following:
$sequence = 'ACGACGTCCAGGGGGGTTGTTACGTCCCCAATCAGTCGGGGCTATTCAGTC';
$sequence =~ s/([GC]){4}/\l$1/g; # Mark 4 char sets as a motif by a single
character (lowercase) of itself
$sequence =~ tr/GCAT/-/s; # turn everything else into a - and squash them
down
$sequence = uc($sequence); # Make the Motif uppercase again (for tidiness)
print "$sequence\n"; # Print the new version
This converts your sample string to:
-G-C-G-
But since I am not really too clear the exact rules that make up a motif (is
6 G's a motif or a motif and 2 G's ?, Are the character motifs supposed to
be on a 4 character boundary? (as in a full set?))
Why did you choose 10 as your substring length, when the sets are made up
from groups of 4?
Anyway, this might be a starting point to help you further along the way.
Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass it
around');
for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
$_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";
------------------------------
Date: Wed, 17 Oct 2001 22:13:25 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Specifying a range of values
Message-Id: <3BCE3AC5.3430B84D@earthlink.net>
Logan Shaw wrote:
>
> In article <keljstsr87pp64tgm19hom210hi41rv6gj@4ax.com>,
> Philip Newton <nospam.newton@gmx.li> wrote:
> >which I prefer personally. (Perl6 will let you do the 'maths' thing
> >and go straight for
> >
> > if( $X < $score < $Y) { ... }
> >
> >.)
>
> Say it ain't so!
>
> How does it deal with the fact that that expression is ambiguous?
>
> Since
>
> $X < $score
>
> is a subexpression with a true/false value and since that can be
> turned into a numeric value (zero for false, one for true), then the
> value of that subexpression can be compared to $Y.
Nope, that's how perl5 works, but AFAIK, in perl6 $X < $score produces a
kind of dual valued object, with a boolean part, and an integer part.
The integer part gets the the right hand side of the <, and the boolean
part gets the results of the numeric less-than comparison of the two
arguments.
If the left hand argument of perl6's < is one of these dual valued
object thingies [eg, if the lhs is the result of another comparson],
then, *first* the boolean part is looked at, and if it's false, the <
returns a dual valued object with boolpart=false. If the boolean part
is true, then the numeric comparison is made, and a dual valued thingy
is returned.
So suppose $X=5, $Y=30, $score=10.
$X < $score < $Y
is evaluated as:
(5 < 10) < 30
Which becomes
wierdthingy(true, 10) < 30
which becomes:
wierdthingy(true, 30)
And then since it's in a boolean context, it just becomes 'true'.
> That's no so bad if $X and $score and $Y are all numeric because you
> can then decide based on whether certain kinds of type conversions
> need to happen. But what if everything is a boolean value? What am I
> supposed to make of the following code?
>
> $a = (1 == 0);
$a = wierdthingy(false,0);
> $b = (1 == 1);
$b = wierdthingy(true, 1)
> $c = (0 == 1);
$a = wierdthingy(false,1);
>
> $d = ($a == $b == $c);
$d = wierdthingy(false, 1); # the 1 here is from $c's numeric part.
The false boolean part from $a's wierdthingy causes a numeric comparison
to be skipped, and for wierdthingy(false, whatever) to be returned.
> This sets to $a to false, $b to true, and $c to false.
>
> So should $d be true or false? If the two "==" operators combine to a
> "test if all three of these numbers are equal" operator, then $d
> should be set to false. But if "$a == $b" is evaluated by itself,
> then it evaluates to false, and if that value is then compared to $c,
> the comparison should have the value true (because false equals
> false), so $d should be set to true.
You're falsely assuming that comparisons must return simple result
values, and they won't.
> The result is that
>
> $d = ($a == $b == $c);
>
> might have a different value than
>
> $d = (($a == $b) == $c);
>
> And that's just WRONG, in my opinion.
>
> And yeah, you can come up with rules about what happens when (it only
> happens if the values are numeric, and not if they're boolean, or it
> only happens if you use an ordering operator instead of an equality
> operator), but that makes things way too confusing.
The rule is, if either argument is a wierdthingy, then if either
wierdthingy's boolean part is false, then the result is
wierdthingy(false, whatever), where whatever is either the RHS [if the
RHS was a number], or the numeric part of the RHS. If all involved
wierdthingies have 'true' in their boolean parts, then the result will
be a wirdthingy whose boolean part is the result of the actual
comparison, and whose numeric part is the RHS or the numeric part of the
RHS.
It's not entirely without problems... for example, while adding in
parenthesis in:
$a == $b == $c
will not make a difference [which is *good*],
they will in:
$a < $b < $c
since:
($a < $b) < $c
will, if the first comparison is true, become:
$b < $c
BUT:
$a < ($b < $c)
will become:
$a < $c
if the first comparison is true.
So:
(5 < 2) < 10
produces
wierdthingy(false,10)
but:
5 < (2 < 10)
produces:
wierdthingy(true, 10)
Maybe wierthingies should keep both their boolean part, *and* the
numeric parts of both their left and right values? Then, when used on
the left, use the right part, and when used on the right, use the left
part.
Hmm... or else you simply aren't allowed to have a wierdthingy on the
RHS of a comparison.
Oy! And what about $a <=> $b <=> $c? Sure it makes sense to return -1
or 1 if they're strictly increasing or decreasing, and 0 if they're all
equal, but what about if $b is greater than both $a and $c? undef?
blech. I think i'm confuserated.
--
"What does stupid old man mean pidgin talk? Shampoo does not talk like a
bird."
------------------------------
Date: Thu, 18 Oct 2001 11:16:19 +1000
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: Splitting on value pairs
Message-Id: <L4qz7.15$2v2.275581@news.interact.net.au>
"Garry Williams" <garry@ifr.zvolve.net> wrote in message
news:slrn9ss7bs.l0g.garry@zfw.zvolve.net...
> On Thu, 18 Oct 2001 09:37:23 +1000, Tintin <tintin@snowy.calculus> wrote:
> > I'm trying to parse a WELF (Webtrends Extended Log Format) file.
> >
> > Each record is on a single line terminated by CRLF, and each field is a
> > simple id/value pair. Each field is separated by whitespace, but if
there
> > is whitespace in the value, it is enclosed in quotes. For example:
> >
> > id=firewall time="2001-10-14 12:01:05" fw=199.9.9.9 src=199.9.9.9
> >
> > Obviously, I could do a simple split (if all values had no whitespace)
to
> > get each value pair, but how do I cater for the quoted values?
>
> Assumptions:
>
> The value immediately follows the `='.
>
> The sequence `="' cannot occur except as the start of a quoted value.
>
> The log record has been read into $line.
>
> [ untested ]
>
> my $first;
> my @records;
> for ( split " ", $line ) {
> if ( /="/ ) {
> $first = $_;
> }
> elsif ( $first ) {
> push @records, $first . $_;
> $first = "";
> }
> else {
> push @records, $_ unless /="/;
> }
> }
Doesn't work on the time field. It is still being split in two.
>
> > I tried
> >
> > my @records = split(/[\w"] [a-z]);
>
> That's a syntax error.
That very remiss of me. Sorry.
Should have been:
my @records = split(/[\w"] [a-z]/);
------------------------------
Date: Thu, 18 Oct 2001 11:16:34 +1000
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: Splitting on value pairs
Message-Id: <_4qz7.16$Mo2.227418@news.interact.net.au>
"Bart Lateur" <bart.lateur@skynet.be> wrote in message
news:vr9sstkp9rl3vb5mc86e6u2rhcmsgtv3ia@4ax.com...
> Tintin wrote:
>
> >id=firewall time="2001-10-14 12:01:05" fw=199.9.9.9 src=199.9.9.9
> >
> >Obviously, I could do a simple split (if all values had no whitespace) to
> >get each value pair, but how do I cater for the quoted values?
>
> Assuming there can be no nested quotes (or you'll have to patch for that
> yourself), you can turn this inside out:
>
> @data = /((?:[^" ]|"[^"]*")+)/g;
I tried that, but the time field was still split in two.
------------------------------
Date: Thu, 18 Oct 2001 11:39:57 +1000
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: Splitting on value pairs
Message-Id: <Vqqz7.18$5p2.237596@news.interact.net.au>
"Tintin" <tintin@snowy.calculus> wrote in message
news:_Doz7.11$5p2.237596@news.interact.net.au...
> I'm trying to parse a WELF (Webtrends Extended Log Format) file.
>
> Each record is on a single line terminated by CRLF, and each field is a
> simple id/value pair. Each field is separated by whitespace, but if there
> is whitespace in the value, it is enclosed in quotes. For example:
>
> id=firewall time="2001-10-14 12:01:05" fw=199.9.9.9 src=199.9.9.9
>
> Obviously, I could do a simple split (if all values had no whitespace) to
> get each value pair, but how do I cater for the quoted values?
>
> I tried
>
> my @records = split(/[\w"] [a-z]);
Playing around a bit more, I've found a solution that seems to work well for
me:
my @records = split(/ (?=[a-z]+=)/);
------------------------------
Date: Thu, 18 Oct 2001 03:08:44 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Splitting on value pairs
Message-Id: <slrn9sshtr.l1i.garry@zfw.zvolve.net>
On Thu, 18 Oct 2001 11:16:19 +1000, Tintin <tintin@snowy.calculus> wrote:
>
> "Garry Williams" <garry@ifr.zvolve.net> wrote in message
> news:slrn9ss7bs.l0g.garry@zfw.zvolve.net...
>> On Thu, 18 Oct 2001 09:37:23 +1000, Tintin <tintin@snowy.calculus> wrote:
>> > I'm trying to parse a WELF (Webtrends Extended Log Format) file.
>> >
>> > Each record is on a single line terminated by CRLF, and each field is a
>> > simple id/value pair. Each field is separated by whitespace, but if there
>> > is whitespace in the value, it is enclosed in quotes. For example:
>> >
>> > id=firewall time="2001-10-14 12:01:05" fw=199.9.9.9 src=199.9.9.9
>> >
>> > Obviously, I could do a simple split (if all values had no whitespace) to
>> > get each value pair, but how do I cater for the quoted values?
>>
>> Assumptions:
>>
>> The value immediately follows the `='.
>>
>> The sequence `="' cannot occur except as the start of a quoted value.
>>
>> The log record has been read into $line.
>>
>> [ untested ]
>>
>> my $first;
>> my @records;
>> for ( split " ", $line ) {
>> if ( /="/ ) {
>> $first = $_;
>> }
>> elsif ( $first ) {
>> push @records, $first . $_;
>> $first = "";
>> }
>> else {
>> push @records, $_ unless /="/;
>> }
>> }
[ I corrected your quoted text that ruined my original indentations. ]
> Doesn't work on the time field. It is still being split in two.
I don't believe you.
Here's why:
$ cat try
#!/usr/bin/perl -wl
use strict;
my $line = q{id=firewall time="2001-10-14 12:01:05" }
. q{fw=199.9.9.9 src=199.9.9.9};
my $first;
my @records;
for ( split " ", $line ) {
if ( /="/ ) {
$first = $_;
}
elsif ( $first ) {
push @records, $first . $_;
$first = "";
}
else {
push @records, $_ unless /="/;
}
}
$, = "|";
print @records;
$ perl try
id=firewall|time="2001-10-1412:01:05"|fw=199.9.9.9|src=199.9.9.9
$
Although the time field was "squeezed" together, the code correctly
separated the individual key=value pairs.
I will leave it to you to correct the missing space in the time field.
(I did claim the code was untested. :-)
--
Garry Williams
------------------------------
Date: 17 Oct 2001 21:43:42 -0400
From: bill <bill02115@hotmail.com>
Subject: Troubleshootng Bundle::libnet installation
Message-Id: <9qlc4e$fcc$1@panix3.panix.com>
I tried to install Bundle::libnet (following CPAN.pm's
recommendation), but the installation fails for reasons I don't
understand. I include CPAN.pm's entire output below, but the crucial
portion, as far as I can tell, is this:
Running make test
PERL_DL_NONLAZY=1 /usr/local/bin/perl -Iblib/arch -Iblib/lib -I/usr/local/lib/perl5/5.6.1/i586-linux -I/usr/local/lib/perl5/5.6.1 -e 'use Test::Harness qw(&runtests $verbose); $verbose=0; runtests @ARGV;' t/*.t
t/ftp...............skipped test on this platform
t/hostname..........Use of uninitialized value in pattern match (m//) at blib/lib/Net/Domain.pm line 226.
Use of uninitialized value in split at blib/lib/Net/Domain.pm line 233.
ok
t/nntp..............skipped test on this platform
t/require...........FAILED tests 8-9
Failed 2/11 tests, 81.82% okay
t/smtp..............skipped test on this platform
Failed Test Status Wstat Total Fail Failed List of Failed
--------------------------------------------------------------------------------
t/require.t 11 2 18.18% 8-9
3 tests skipped.
Failed 1/5 test scripts, 80.00% okay. 2/12 subtests failed, 83.33% okay.
make: *** [test_dynamic] Error 29
/usr/bin/make test -- NOT OK
Running make install
make test had returned bad status, won't install without force
Bundle summary: The following items in bundle Bundle::libnet had
installation problems:
Net::Cmd
I'm at a loss as to how to proceed. All I know is that some tests
failed, but there is no indication of why they failed. Any
suggestions on what to do next would be most welcome.
FWIW, the machine I'm trying to install Bundle::libnet on is connected
to the Internet via a PPP connection. My ISP is Panix.
Thanks,
bill
PS. The full CPAN.pm session is given below
$ perl -MCPAN -e shell
cpan shell -- CPAN exploration and modules installation (v1.59_54)
ReadLine support enabled
cpan> install Bundle::libnet
Going to read /root/.cpan/sources/authors/01mailrc.txt.gz
Going to read /root/.cpan/sources/modules/02packages.details.txt.gz
Database was generated on Mon, 15 Oct 2001 21:32:56 GMT
CPAN: HTTP::Date loaded ok
Going to read /root/.cpan/sources/modules/03modlist.data.gz
Data::Dumper is up to date.
Net::Telnet is up to date.
Running install for module Net::Cmd
Running make for G/GB/GBARR/libnet-1.0704.tar.gz
CPAN: MD5 loaded ok
Checksum for /root/.cpan/sources/authors/id/G/GB/GBARR/libnet-1.0704.tar.gz ok
Scanning cache /root/.cpan/build for sizes
libnet-1.0704/
libnet-1.0704/Net/
libnet-1.0704/Net/NNTP.pm
libnet-1.0704/Net/FTP/
libnet-1.0704/Net/FTP/dataconn.pm
libnet-1.0704/Net/FTP/I.pm
libnet-1.0704/Net/FTP/L.pm
libnet-1.0704/Net/FTP/A.pm
libnet-1.0704/Net/FTP/E.pm
libnet-1.0704/Net/POP3.pm
libnet-1.0704/Net/SMTP.pm
libnet-1.0704/Net/FTP.pm
libnet-1.0704/Net/Time.pm
libnet-1.0704/Net/Cmd.pm
libnet-1.0704/Net/Config.pm
libnet-1.0704/Net/Domain.pm
libnet-1.0704/Net/libnetFAQ.pod
libnet-1.0704/Net/Netrc.pm
libnet-1.0704/t/
libnet-1.0704/t/require.t
libnet-1.0704/t/hostname.t
libnet-1.0704/t/nntp.t
libnet-1.0704/t/smtp.t
libnet-1.0704/t/ftp.t
libnet-1.0704/Configure
libnet-1.0704/demos/
libnet-1.0704/demos/smtp.self
libnet-1.0704/demos/nntp
libnet-1.0704/demos/pop3
libnet-1.0704/demos/nntp.mirror
libnet-1.0704/demos/ftp
libnet-1.0704/demos/time
libnet-1.0704/demos/inetd
libnet-1.0704/Hostname.pm.eg
libnet-1.0704/ChangeLog
libnet-1.0704/Makefile.PL
libnet-1.0704/README
libnet-1.0704/Config.eg
libnet-1.0704/MANIFEST
Removing previously used /root/.cpan/build/libnet-1.0704
CPAN.pm: Going to build G/GB/GBARR/libnet-1.0704.tar.gz
Checking for Socket...ok
Checking for IO::Socket...ok
Checking if your kit is complete...
Looks good
Ah, I see you already have installed libnet before.
Do you want to modify/update your configuration (y|n) ? [no]
This script will prompt you to enter hostnames that can be used as
defaults for some of the modules in the libnet distribution.
To ensure that you do not enter an invalid hostname, I can perform a
lookup on each hostname you enter. If your internet connection is via
a dialup line then you may not want me to perform these lookups, as
it will require you to be on-line.
Do you want me to perform hostname lookups (y|n) ? [yes]
The following questions all require a list of host names, separated
with spaces. If you do not have a host available for any of the
services, then enter a single space, followed by <CR>. To accept the
default, hit <CR>
Enter a list of available NNTP hosts : []
Enter a list of available SMTP hosts : []
Enter a list of available POP3 hosts : []
Enter a list of available SNPP hosts : []
Enter a list of available PH Hosts : []
Enter a list of available TIME Hosts : []
Enter a list of available DAYTIME Hosts : []
Do you have a firewall/ftp proxy between your machine and the internet
If you use a SOCKS firewall answer no
(y|n) ? [no]
Normally when FTP needs a data connection the client tells the server
a port to connect to, and the server initiates a connection to the client.
Some setups, in particular firewall setups, can/do not work using this
protocol. In these situations the client must make the connection to the
server, this is called a passive transfer.
Should all FTP connections be passive (y|n) ? [no]
What is your local internet domain name : []
If you specified some default hosts above, it is possible for me to
do some basic tests when you run `make test'
This will cause `make test' to be quite a bit slower and, if your
internet connection is via dialup, will require you to be on-line
unless the hosts are local.
Do you want me to run these tests (y|n) ? [yes]
To allow Net::FTP to be tested I will need a hostname. This host
should allow anonymous access and have a /pub directory
What host can I use : []
Writing libnet.cfg
Writing Makefile for Net
cp Net/POP3.pm blib/lib/Net/POP3.pm
cp Net/libnetFAQ.pod blib/lib/Net/libnetFAQ.pod
cp Net/Config.pm blib/lib/Net/Config.pm
cp Net/Domain.pm blib/lib/Net/Domain.pm
cp Net/SMTP.pm blib/lib/Net/SMTP.pm
cp Net/Time.pm blib/lib/Net/Time.pm
cp Net/NNTP.pm blib/lib/Net/NNTP.pm
cp Net/Cmd.pm blib/lib/Net/Cmd.pm
cp Net/Netrc.pm blib/lib/Net/Netrc.pm
cp Net/FTP/L.pm blib/lib/Net/FTP/L.pm
cp Net/FTP/dataconn.pm blib/lib/Net/FTP/dataconn.pm
cp Net/FTP.pm blib/lib/Net/FTP.pm
cp Net/FTP/E.pm blib/lib/Net/FTP/E.pm
cp Net/FTP/A.pm blib/lib/Net/FTP/A.pm
cp Net/FTP/I.pm blib/lib/Net/FTP/I.pm
cp libnet.cfg blib/lib/Net/libnet.cfg
Manifying blib/man3/Net::POP3.3
Manifying blib/man3/Net::Domain.3
Manifying blib/man3/Net::libnetFAQ.3
Manifying blib/man3/Net::SMTP.3
Manifying blib/man3/Net::Time.3
Manifying blib/man3/Net::NNTP.3
Manifying blib/man3/Net::Cmd.3
Manifying blib/man3/Net::Netrc.3
Manifying blib/man3/Net::FTP.3
/usr/bin/make -- OK
Running make test
PERL_DL_NONLAZY=1 /usr/local/bin/perl -Iblib/arch -Iblib/lib -I/usr/local/lib/perl5/5.6.1/i586-linux -I/usr/local/lib/perl5/5.6.1 -e 'use Test::Harness qw(&runtests $verbose); $verbose=0; runtests @ARGV;' t/*.t
t/ftp...............skipped test on this platform
t/hostname..........Use of uninitialized value in pattern match (m//) at blib/lib/Net/Domain.pm line 226.
Use of uninitialized value in split at blib/lib/Net/Domain.pm line 233.
ok
t/nntp..............skipped test on this platform
t/require...........FAILED tests 8-9
Failed 2/11 tests, 81.82% okay
t/smtp..............skipped test on this platform
Failed Test Status Wstat Total Fail Failed List of Failed
--------------------------------------------------------------------------------
t/require.t 11 2 18.18% 8-9
3 tests skipped.
Failed 1/5 test scripts, 80.00% okay. 2/12 subtests failed, 83.33% okay.
make: *** [test_dynamic] Error 29
/usr/bin/make test -- NOT OK
Running make install
make test had returned bad status, won't install without force
Bundle summary: The following items in bundle Bundle::libnet had
installation problems:
Net::Cmd
------------------------------
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 1952
***************************************