Solved

Problem on multiple splits

Posted on 2003-12-02
4
322 Views
Last Modified: 2008-03-17
this code is for monitoring netbackup jobs. Here is a portion of my code:

$error=`/usr/openv/netbackup/bin/admincmd/bperror -l -t backstat -d $newtime`;

print ALLERROR "$error\n";
close(ALLERROR);

open(ALLERROR,"$all_errors") || die "Can't open infile: $!\n";

while(<ALLERROR>){

 ($junk1, $junk2, $junk3, $junk4, $media, $dt, $junk7, $junk8, $client, $junk10, $junk11, $junk12, $junk13, $policy, $junk15, $schedule, $junk17, $junk18, $nbstatus) =split(" ",$_);

############################ Start: Find Oracle jobs and their owners ########################################################

if  ( $nbstatus==0 | nbstatus==1 && $schedule =~  "ORACLE" )  {
                                                             
next if /^(\s)*$/;  # skip blank lines

@owner=`/usr/openv/netbackup/bin/admincmd/bpdbjobs -report -all_columns | grep $dt | grep -v grep | awk -F',' '{print $20}'`;

 ($jk1, $jk2, $jk3, $jk4, $jk5, $jk6, $jk7, $jk8, $jk9, $jk10, $jk11, $jk12, $jk13, $jk14, $jk15, $jk16, $jk17, $jk18, $jk19, $own) =split(/\,/,$_);


The first split works. The second splitl does not. For the second split I only what the 20th field, $own. However if I do a print $jk1 I get the entire line for the frist split, ie

junk1, $junk2, $junk3, $junk4, $media, $dt, $junk7, $junk8, $client, $junk10, $junk11, $junk12, $junk13, $policy, $junk15, $schedule, $junk17, $junk18, $nbstatus


Thougths?


0
Comment
Question by:MatthewF
  • 2
4 Comments
 
LVL 19

Expert Comment

by:Kim Ryan
Comment Utility
$_ will still be set to the contents of the curre line in file ALLERROR. What data do you want to use for the second split?
Also, it is quicker to say:
(@values) =split(/\,/,$_);
$last_value = pop(values); # get last value of array


0
 

Author Comment

by:MatthewF
Comment Utility
The second split:
@owner=`/usr/openv/netbackup/bin/admincmd/bpdbjobs -report -all_columns | grep $dt | grep -v grep | awk -F',' '{print $20}'`;

 ($jk1, $jk2, $jk3, $jk4, $jk5, $jk6, $jk7, $jk8, $jk9, $jk10, $jk11, $jk12, $jk13, $jk14, $jk15, $jk16, $jk17, $jk18, $jk19, $own) =split(/\,/,$_);


I want to return $own. I didnt try to use a pop becuase the array of owener is generally 30+ fields, not all which are always populated. ie
The first 10 fields

1,2,3,4,,6,7,8,9,10,
or
1,2,3,4,,6,,8,,10,

etc, etc

0
 
LVL 19

Accepted Solution

by:
Kim Ryan earned 175 total points
Comment Utility
The problem is you are not linking @owner to the data to split on, its still using the current line
form the filehandle. I think you may want something like:

$owner=`/usr/openv/netbackup/bin/admincmd/bpdbjobs -report -all_columns | grep $dt | grep -v grep | awk -F',' '{print $20}'`;

 ($jk1, $jk2, $jk3, $jk4, $jk5, $jk6, $jk7, $jk8, $jk9, $jk10, $jk11, $jk12, $jk13, $jk14, $jk15, $jk16, $jk17, $jk18, $jk19, $own) =split(/\,/,$owner);

0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 75 total points
Comment Utility
#It's also easier to say
$own = (split/\,/,$owner)[19];
 
($media, $dt, $client, $policy, $schedule, $nbstatus)=(split)[5,6,9,14,16,19];
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now