Home > Archive > PERL Beginners > April 2005 > Re: REGEXP removing - il- - -b-f and - il- - - - f
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: REGEXP removing - il- - -b-f and - il- - - - f
|
|
| Jay Savage 2005-04-27, 3:56 pm |
| On 4/27/05, JupiterHost.Net <mlists@jupiterhost.net> wrote:
>=20
ut it.[color=darkred]
>=20
> I think that won't work due to some rows formatted like so:
>=20
> 2005/01/20 15:39 17 2% -il-o-b- - - - - sg F01000
>=20
> unless that was typo?
>=20
> In that case "7" isn't always the index of the last item in the list
> from split.
>=20
> while (<V4> ) {
> my @tmp =3D split;
> print "$tmp[ $#tmp ]\n";
> }
>=20
I was assuming it was a typo/email munge, and that the command he
pipes actually produces consistent output. That may be a faulty
assumption on my part. YOu know what they say about assumptions In
general, though, when parsing log files (which seems to be waht's
going on here) if you're assured reasonably consisten data, it's
better IMNSHO to look for a particular index, because loggers are more
likely to add occasional extranious info or comments at the end of the
line than in the middle.
YMMV,
Jay
| |
| JupiterHost.Net 2005-04-27, 3:56 pm |
| > I was assuming it was a typo/email munge, and that the command he
> pipes actually produces consistent output. That may be a faulty
> assumption on my part. YOu know what they say about assumptions In
Its hard to say Derek doesn't give us much to work with :)
> general, though, when parsing log files (which seems to be waht's
> going on here) if you're assured reasonably consisten data, it's
> better IMNSHO to look for a particular index, because loggers are more
> likely to add occasional extranious info or comments at the end of the
> line than in the middle.
Yeah, I imagine you're correct in your assumption, without actual valid
info its hard to tell :)
Basically if you're gauranteed it index 7 use index 7, otherwise if
you're gauranteed its the last item (and it may be 7 and it may not be(
use the $#array version, if you can't do either redo it all based on
hoew the output is. And if you post to the list about it please send
accurate info.
| |
| DBSMITH@OhioHealth.com 2005-04-27, 3:56 pm |
| perl people.... there was a lot of threads to my question ...thank you! I
will start from the most recent.
I took and understood the advise of my @a = (); changed to my @a;
Yes I do understand the differing precedence between or and | | . I have a
habit using | |. I do also understand that if you use or you should use (
) as opposed to | | you do not have to use ( ). Any comments?
Line 15 is changed to, I forgot ti take out the + . $fa[$i++] =
(split)[-1] if (m/f01(\d+)/gi );
But I do not understand what the (split)[-1] is saying? please explain.
I reran the code and it seems to be working now.
thanks again, : )
ciao!
#!/usr/bin/perl
1> use strict;
2> use warnings;
3> $ENV{"PATH"} =
qq(/opt/SUNWsamfs/sbin:/usr/bin:/usr/sbin:/usr/local/log);
4> open (V4, "samcmd v4 2>\&1 |" ) || die "unable to open pipe... Broken?
$!";
5> my @fa =();
6> my @ha =();
7> my $i =0;
8> foreach (<V4> ) {
9> local $, = "\n";
10> #print +(split)[6,7], $,;
11> s <sg> ();
12> s {\-*} ()g;
13> s {\w+} ()i;
14> print +(split)[5,6,7], if (m/f01(\d+)/gi )
15> #$fa[$i++] = +(split)[5,6,7] if (m/f01(\d+)/gi );
16> #print +(split)[4],$,; #% column
17> }
18> close (V4);
19> print "\n";
20> print "Now printing array element 0\t", $fa[0], "\n";
21> #print "Now printing entire array \t", @fa, "\n";
22> print "Now printing array count \t", $#fa, "\n";
Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams
614-566-4145
"JupiterHost.Net"
<mlists@jupiterho
st.net> To
beginners@perl.org
04/27/2005 12:03 cc
PM
Subject
Re: REGEXP removing - il- - -b-f
and - il- - - - f
> I was assuming it was a typo/email munge, and that the command he
> pipes actually produces consistent output. That may be a faulty
> assumption on my part. YOu know what they say about assumptions In
Its hard to say Derek doesn't give us much to work with :)
> general, though, when parsing log files (which seems to be waht's
> going on here) if you're assured reasonably consisten data, it's
> better IMNSHO to look for a particular index, because loggers are more
> likely to add occasional extranious info or comments at the end of the
> line than in the middle.
Yeah, I imagine you're correct in your assumption, without actual valid
info its hard to tell :)
Basically if you're gauranteed it index 7 use index 7, otherwise if
you're gauranteed its the last item (and it may be 7 and it may not be(
use the $#array version, if you can't do either redo it all based on
hoew the output is. And if you post to the list about it please send
accurate info.
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
| |
| Ing. Branislav Gerzo 2005-04-28, 8:56 am |
| DBSMITH@OhioHealth.com [D], on Wednesday, April 27, 2005 at 12:55
(-0400) wrote the following:
D> But I do not understand what the (split)[-1] is saying? please explain.
it gets last splitted value from the list.
(split)[0] #get the first splitted value
(split)[0,1] #get first and second splitted value (assign it to @array)
(split)[-1] #get the first value from the end of list
--
How do you protect mail on web? I use http://www.2pu.net
[Punny Book: Fastest Gun In The West - Everett DeReady]
|
|
|
|
|