Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: REGEXP removing - il- - -b-f and - il- - - - f
On 4/27/05, DBSMITH@ohiohealth.com <DBSMITH@ohiohealth.com> wrote:
> yes I agree I was a little ambiguous... I was in a hurry. sorry.  Anyway
> here is my updated code. and here is a sample output:
> My goal is to get all F01 which I am but I am having issues capturing all
> of these values into my array.  When I run the I get the data I want to s=
ee
> which is just the F01 column, but when I comment out line 14 and uncommen=
t
> line 15 and uncomment line 21 I see no data in the array???
> In the end I want the F01 column and the % column.
>=20
> thank you,
>=20
> derek
>=20
>  1     2005/01/20 15:39   17   2%  -il-o-b- - - - -  sg F01000
>    2     2005/01/20 15:53   14   1%  -il-o-b-----  sg F01001
>    3     2005/01/18 09:53    2   0%  -il-o-b-----  sg F01002
>    4     2005/02/04 16:41  196 100%  -il-o-b----f  sg F01003
>    5     2005/02/05 21:13  305 100%  -il-o-b----f  sg F01004
>    6     2005/02/28 22:47  180 100%  -il-o-b-----  sg F01005
>   13     2005/02/08 16:07  112 100%  -il-o-b----f  sg F01006
>   14     2005/02/09 21:56  122 100%  -il-o-b----f  sg F01007
>   15     2005/02/11 10:51  147 100%  -il-o-b----f  sg F01008
>   16     2005/02/13 11:35  193 100%  -il-o-b----f  sg F01009
>   17     2005/02/14 23:46   79 100%  -il-o-b- - - -f  sg F01010
>=20
> #!/usr/bin/perl
> 1> use strict;
> 2> use warnings;
> 3> $ENV{"PATH"} =3D
> 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 =3D();
> 6> my @ha =3D();
> 7> my $i =3D0;
> 8>        foreach (<V4> ) {
> 9>               local $, =3D "\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++] =3D +(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";
>=20
> Derek B. Smith
> OhioHealth IT
> UNIX / TSM / EDM Teams
>=20
>              "Ing. Branislav
>              Gerzo"
>              <konfera@2ge.us>                                           T=
o
>                                        beginners@perl.org
>              04/27/2005 02:46                                           c=
c
>              AM
>                                                                    Subjec=
t
>                                        Re: REGEXP
>=20
> DBSMITH@OhioHealth.com [D], on Tuesday, April 26, 2005 at 17:12
> (-0400) made these points:
>=20
> D> s/sg//, s/\- {1,}(\w{1,})//,print +(split)[5,6,7], if (m/f01(\d+)/gi )
>=20
> I think no one replied to you because we don't know what should be
> output.
>=20

If all you want is the last column, this is a really long way to go about i=
t.

while (<V4> ) {
print (split)[7];
print "\n";
}

If you want to do output redierection using the shell, you could just
do it on the command line:

perl -lane 'print $F[7]' `samcmd v4 2>\&1`

See perldoc perlrun for details.  In any case, don't mess with the
builtins (i.e. $,).  If you want a "\n", print a "\n".  Also,

s {\-*} ()g;

is not a valid substitution statement.

s{\-*}()g;

is a valid statement.  Notice the lack of spaces.  Moving on:

4> open (V4, "samcmd v4 2>\&1 |" ) || die "unable to open pipe...
Broken?$!";

Don't do this.  the precedence of || is too high.  your code attempts
to open a pipe, and if it can't, then it attempts to open "die..." and
starts throwing exceptions.  You want:

open (V4, "samcmd v4 2>\&1 |" ) or die "unable to open pipe... Broken?$=
!";

This should be enough to get you started.  On the whole, though, I'd
seriously recommend that you pick up a copy of a good intro perl book
(_Learning Perl_ springs to mind), and read the FAQ for this group on
how to identify (bad) examples of Perl 4 code, which it seems you've
been looking at.

HTH,

Jay

Report this thread to moderator Post Follow-up to this message
Old Post
Jay Savage
04-27-05 08:56 PM


Re: REGEXP removing - il- - -b-f and - il- - - - f

> If all you want is the last column, this is a really long way to go about 
it.
>
>     while (<V4> ) {
>         print (split)[7];
>         print "\n";
> }

I think that won't work due to some rows formatted like so:

2005/01/20 15:39   17   2%  -il-o-b- - - - -  sg F01000

unless that was typo?

In that case "7" isn't always the index of the last item in the list
from split.

while (<V4> ) {
my @tmp = split;
print "$tmp[ $#tmp ]\n";
}

> This should be enough to get you started.  On the whole, though, I'd
> seriously recommend that you pick up a copy of a good intro perl book
> (_Learning Perl_ springs to mind), and read the FAQ for this group on
> how to identify (bad) examples of Perl 4 code, which it seems you've
> been looking at.

I second that!

Report this thread to moderator Post Follow-up to this message
Old Post
JupiterHost.Net
04-27-05 08:56 PM


Re: REGEXP removing - il- - -b-f and - il- - - - f
yes that is true, [5,6,7]  need to be typed otherwise all entries are not
accounted for.

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 11:13                                           cc
AM
Subject
Re: REGEXP removing - il- - -b-f
and - il- - - - f











> If all you want is the last column, this is a really long way to go about
it.
>
>     while (<V4> ) {
>         print (split)[7];
>         print "\n";
> }

I think that won't work due to some rows formatted like so:

2005/01/20 15:39   17   2%  -il-o-b- - - - -  sg F01000

unless that was typo?

In that case "7" isn't always the index of the last item in the list
from split.

while (<V4> ) {
my @tmp = split;
print "$tmp[ $#tmp ]\n";
}

> This should be enough to get you started.  On the whole, though, I'd
> seriously recommend that you pick up a copy of a good intro perl book
> (_Learning Perl_ springs to mind), and read the FAQ for this group on
> how to identify (bad) examples of Perl 4 code, which it seems you've
> been looking at.

I second that!

--
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>





Report this thread to moderator Post Follow-up to this message
Old Post
DBSMITH@OhioHealth.com
04-27-05 08:56 PM


Re: REGEXP removing - il- - -b-f and - il- - - - f

DBSMITH@OhioHealth.com wrote:
> yes that is true, [5,6,7]  need to be typed otherwise all entries are not

Yes what is true? Please reply inline.

Report this thread to moderator Post Follow-up to this message
Old Post
JupiterHost.Net
04-28-05 01:56 AM


Re: REGEXP removing - il- - -b-f and - il- - - - f
I am  with your email.

what does (split) [-1]   mean?

Finally,

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?

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 02:26                                           cc
PM
Subject
Re: REGEXP removing - il- - -b-f
and - il- - - - f












DBSMITH@OhioHealth.com wrote:
> yes that is true, [5,6,7]  need to be typed otherwise all entries are not

Yes what is true? Please reply inline.

--
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>





Report this thread to moderator Post Follow-up to this message
Old Post
DBSMITH@OhioHealth.com
04-28-05 01:56 AM


Re: REGEXP removing - il- - -b-f and - il- - - - f
all f01 records are not printed if one uses print +(split)[7]
rather print +(split)[5,6,7] will print all f01 records.


sorry
derek




"JupiterHost.Net"
<mlists@jupiterho
st.net>                                                    To
beginners@perl.org
04/27/2005 02:26                                           cc
PM
Subject
Re: REGEXP removing - il- - -b-f
and - il- - - - f












DBSMITH@OhioHealth.com wrote:
> yes that is true, [5,6,7]  need to be typed otherwise all entries are not

Yes what is true? Please reply inline.

--
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>





Report this thread to moderator Post Follow-up to this message
Old Post
DBSMITH@OhioHealth.com
04-28-05 01:56 AM


Re: REGEXP removing - il- - -b-f and - il- - - - f
Jay Savage wrote:
>
>     4> open (V4, "samcmd v4 2>\&1 |" ) || die "unable to open pipe...
> Broken?$!";
>
> Don't do this.  the precedence of || is too high.  your code attempts
> to open a pipe, and if it can't, then it attempts to open "die..." and
> starts throwing exceptions.

No, that is NOT what happens, it will NEVER attempt to open "die..." with or
without the parentheses.  The ONLY time it will attempt to open "die..." is 
if
there are no parentheses and the expression on the left hand side of the ||
operator evaluates to false.

open V4, '0' || die $!;

But even then it will NOT attempt to open "die..." because die() exits the
program!



John
--
use Perl;
program
fulfillment

Report this thread to moderator Post Follow-up to this message
Old Post
John W. Krahn
04-28-05 01:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:29 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.