Solved

Problem on multiple splits

Posted on 2003-12-02
4
333 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
ID: 9862372
$_ 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
ID: 9862966
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
ID: 9863056
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
ID: 9863894
#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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

932 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

20 Experts available now in Live!

Get 1:1 Help Now