Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Problem on multiple splits

Posted on 2003-12-02
4
349 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…

828 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