LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-26-2011, 01:12 PM   #1
casperdaghost
Member
 
Registered: Aug 2009
Posts: 346

Rep: Reputation: 16
Use of uninitialized value in pattern match - perl


I want to strip the process name from the hosts - i did it with the code below.

I have two questions - is there a more compact way to strip off the process names? usalso i want to get rid of the errors after extracting the hostname. It is complaing about $arry[1]. using my $arry[1] is not allowed. Assigning the slice to a value, as is 'my $sliced_arry = $arry[1]; print $sliced_arry , does not work either.
Code:
 

#!/usr/bin/perl -w
use strict;
  open NEWCOMM, "newcomm_stat -n local mis100 |";
   while (<NEWCOMM>) {
             my @arry  = split (/\s+/ , $_);
             print "$arry[1]\n";
             }
(zeusUS@mit201
Use of uninitialized value in pattern match (m//) at newcomm_stats.pl3 line 7, <NEWCOMM> line 10
(odin@ibmis100
Use of uninitialized value in pattern match (m//) at newcomm_stats.pl3 line 7, <NEWCOMM> line 12
(thorUS@mit201
Use of uninitialized value in pattern match (m//) at newcomm_stats.pl3 line 7, <NEWCOMM> line 14
(balder@mis102
Use of uninitialized value in pattern match (m//) at newcomm_stats.pl3 line 7, <NEWCOMM> line 16
here i get what i want - just the host name, but still get those nasty errors. assigning a value to $1 does not work, and localizing $1 with 'my' is not allowed.

Code:
#!/usr/bin/perl -w
use strict;
  open NEWCOMM, "newcomm_stat -n localtick ibmis100 |";
   while (<NEWCOMM>) {
             my @arry  = split (/\s+/ , $_);
             if ($arry[1] =~ /\(\w+@(\w+)/){
                  my $newcomm_hosts =  $1;
                  print "$newcomm_hosts\n";
                  sleep 1;
             }
   }



mit102
Use of uninitialized value in pattern match (m//) at newcomm_stats.pl3 line 7, <NEWCOMM> line 10.
ibmis100
Use of uninitialized value in pattern match (m//) at newcomm_stats.pl3 line 7, <NEWCOMM> line 12.
ibmis100
Use of uninitialized value in pattern match (m//) at newcomm_stats.pl3 line 7, <NEWCOMM> line 14.
mit201
Use of uninitialized value in pattern match (m//) at newcomm_stats.pl3 line 7, <NEWCOMM> line 26.
 
Old 06-26-2011, 01:45 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
For starters, you didn't give us info what line #7 is.

I suggest to

cat -n your_file.pl

and copy-paste screen output of the above here.
...
Read carefully 'perdoc -f split' - near the end. Check values of '@arry'. Consider using "split(' ', $whatever)" instead of "split(/\s+/, $whatever)" - you practically never need the latter (I don't remember such a case in my life).
 
Old 06-26-2011, 02:19 PM   #3
casperdaghost
Member
 
Registered: Aug 2009
Posts: 346

Original Poster
Rep: Reputation: 16
thank you i am reading it now
 
Old 06-26-2011, 02:42 PM   #4
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by casperdaghost View Post
thank you i am reading it now
I meant

Code:
split(' ', $whatever);
, i.e. space as first argument.
 
Old 06-27-2011, 07:31 PM   #5
casperdaghost
Member
 
Registered: Aug 2009
Posts: 346

Original Poster
Rep: Reputation: 16
I read the perl doc's for split, and ended up traversing the array with a for each loop - use strict seems to like that.
no more errors.

Code:
#!/usr/bin/perl -w
use strict;
 #open NEWCOMM , "/home/tops11/wjohnson/newcomm.ibfarm100:localtick";
 open NEWCOMM, "newcomm_stat -n localtick ibmis100 |";
  while (<NEWCOMM>) {
           ###my @arry  = split (/\s+/ , $_);
            my @arry  = split (' ' , $_);
            foreach my $line(@arry){
                 my $sliced_newcomm = $arry[1];
                 if ($sliced_newcomm =~ /\(\w+@(\w+)/){
                    my $newcomm_hosts =  $1;
                    print "$newcomm_hosts\n";
                    sleep 1;
                 }
           }
  }
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Use of uninitialized value in pattern match (m//) koshihaku Linux - Newbie 2 08-10-2010 01:07 PM
[SOLVED] Adding (not replacing) a pattern match with a similar pattern? b-bri Linux - Newbie 2 08-31-2009 12:36 AM
irrelevant characters match in PERL pattern matching gaynut Programming 2 08-21-2008 10:52 PM
perl pattern match question lluciano Programming 4 02-28-2006 05:59 AM


All times are GMT -5. The time now is 03:37 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration