Sponsored Content
Full Discussion: Perl split and array
Top Forums Shell Programming and Scripting Perl split and array Post 302932726 by Zam_1234 on Friday 23rd of January 2015 06:17:04 PM
Old 01-23-2015
Computer Perl split and array

Hello, I have the following code:
Code:
 while ($line = <fd_in>) {
   126    $line = " " . $line ;
   127  print "our_line:$line\n";
   128    @list = split (/\s+/, $line) ;
   129  print "after_split:@list\n";
   130  print "$list[0]\t$list[1]\t$list[2]\t$list[3]\t$list[4]\t$list[5]$list[6]\t\n";
   131    $len = $#list ;
   132  print "length of array:$len\n";
   133
   134
   135    if (($len >= 7) && ($list[3] ne "total")) { # Ignore header and totals
   136      $cpu_id = $list[2] ;
   137      print "$list[0]\t$list[1]\t$list[2]\t$list[3]\t$list[4]\n";
   138      print "cpu_id: $cpu_id\n";
   139      $pic0 = $list[4] ;
   140      print "pic0: $pic0\n";
   141      $pic1 = $list[5] ;

And when I ran the code, here is one of the output:
Code:
our_line:   1.023  25  tick         8       635  # pic0=L2_dmiss_ld,pic1=Instr_cnt

after_split: 1.023 25 tick 8 635 # pic0=L2_dmiss_ld,pic1=Instr_cnt
        1.023   25      tick    8       635#
length of array:7
        1.023   25      tick    8
cpu_id: 25
pic0: 8

What I am not getting is, line 127 is printing out the whole array and then the "split" is splitting the array based on one or more spaces (I might be wrong, but the output shows like that).
But then in the code line 130, I am trying to print all the elements of the array which is not making sense. It is not printing out all the elements.

Later, line 136 is taking cpu_id as 3rd element of the array ($list[2]), but it should be $list [1]. I am not sure how it is working and might be missing the clue.

Any help is much appreciated.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

split to array in perl

Collegues I have flat file in the following format. 137 (NNP Kerala) (NNP India) 92 (NN Rent) (NN Range) 70 (NNP Thiruvananthapuram) (NNP Kerala) 43 (NNP Tourist) (NNP Home) 40 (NNP Reserve) (NNP Now) 25 (SYM @) (NN hotelskerala) 25 (NNP Thiruvananthapuram-695001) (NNP Kerala) 23 (NN... (3 Replies)
Discussion started by: jaganadh
3 Replies

2. Shell Programming and Scripting

How to get array to not split at spaces?

I have been working on some code for a while, that will parse a log file, look for a specified time discrepancy between entries, and then print that line +/- n other lines out to a file... #!/bin/bash file=$1 # The input log file maxTime=$2 # The time discrepancy to look for n=$3 ... (1 Reply)
Discussion started by: jjinno
1 Replies

3. Shell Programming and Scripting

split variable values into array

i have these values inside variable $blah BUNGA TERATAI 3 5055 ITH 1 0 0 0 1 1 JADE TRADER 143W ITH 4 0 0 0 4 4 MOL SPLENDOR 0307A ITH 3 0 0 0 3 3 so how do I split them into array with the... (4 Replies)
Discussion started by: finalight
4 Replies

4. Shell Programming and Scripting

split and making an array inside another array

I want to run an awk split on a value that has been pushed through an array and I was wondering what the syntax should be?? e.g. running time strings through an array and trying to examine just minutes: 12:25:30 10:15:13 08:55:23 awk ' NR==FNR{ ... (2 Replies)
Discussion started by: dcfargo
2 Replies

5. Shell Programming and Scripting

perl, put one array into many array when field is equal to sth

Hi Everyone, #!/usr/bin/perl use strict; use warnings; my @test=("a;b;qqq;c;d","a;b;ggg;c;d","a;b;qqq;c;d"); would like to split the @test array into two array: @test1=(("a;b;qqq;c;d","a;b;qqq;c;d"); and @test2=("a;b;ggg;c;d"); means search for 3rd filed. Thanks find the... (0 Replies)
Discussion started by: jimmy_y
0 Replies

6. Shell Programming and Scripting

[Perl] Split lines into array - variable line items - variable no of lines.

Hi, I have the following lines that I would like to see in an array for easy comparisons and printing: Example 1: field1,field2,field3,field4,field5 value1,value2,value3,value4,value5Example 2: field1,field3,field4,field2,field5,field6,field7... (7 Replies)
Discussion started by: ejdv
7 Replies

7. Shell Programming and Scripting

PERL : Read an array and write to another array with intial string pattern checks

I have an array and two variables as below, I need to check if $datevar is present in $filename. If so, i need to replace $filename with the values in the array. I need the output inside an ARRAY How can this be done. Any help will be appreciated. Thanks in advance. (2 Replies)
Discussion started by: irudayaraj
2 Replies

8. Shell Programming and Scripting

split string into array in shell

Hi all, I want to split a string into array based on given delimiter, for example: String: "foo|bar|baz" with delimiter "|" into array: strArr to strArr with values foo, bar and baz. Thanks a lot. Roy987 (5 Replies)
Discussion started by: Roy987
5 Replies

9. UNIX for Beginners Questions & Answers

How to split a string into array?

value=malayalam # i need to store the value in an array by splitting the character #the output i need is m a l a y a l a m Please use CODE tags for output data as well as required by forum rules! (5 Replies)
Discussion started by: Meeran Rizvi
5 Replies

10. UNIX for Beginners Questions & Answers

How to split the string value to an array?

Test1.txt Tom is hot Test.sh filename="/directory/Test1.txt" set - A store while IFS= read value do awk '{split($value,store," ")}' done < "$filename" echo ${#sore} From the code in the executing file, I would like each... (8 Replies)
Discussion started by: TestKing
8 Replies
busstat(1M)						  System Administration Commands					       busstat(1M)

NAME
busstat - report bus-related performance statistics SYNOPSIS
busstat -e device-inst | -h | -l busstat [-a] [-n] [-w device-inst [,pic0=event,picn=event ]]... [-r device-inst]... [interval [count]] DESCRIPTION
busstat provides access to the bus-related performance counters in the system. These performance counters allow for the measurement of sta- tistics like hardware clock cycles, bus statistics including DMA and cache coherency transactions on a multiprocessor system. Each bus device that supports these counters can be programmed to count a number of events from a specified list. Each device supports one or more Performance Instrumentation Counters (PIC) that are capable of counting events independently of each other. Separate events can be selected for each PIC on each instance of these devices. busstat summarizes the counts over the last interval sec- onds, repeating forever. If a count is given, the statistics are repeated count times. Only root users can program these counters. Non-root users have the option of reading the counters that have been programmed by a root user. The default value for the interval argument is 1 second, and the default count is unlimited. The devices that export these counters are highly platform-dependent and the data may be difficult to interpret without an in-depth under- standing of the operation of the components that are being measured and of the system they reside in. OPTIONS
The following options are supported: -a Display absolute counter values. The default is delta values. -e device-inst Display the list of events that the specified device supports for each pic. Specify device-inst as device (name) followed by an optional instance number. If an instance number is specified, the events for that instance are displayed. If no instance number is specified, the events for the first instance of the specified device are displayed. -h Print a usage message. -l List the devices in the system which support performance counters. -n Do not display a title in the output. The default is to display titles. -r device-inst Read and display all pic values for the specified device Specify device-inst as device (name) followed by instance number, if specifying an instance number of a device whose counters are to be read and displayed. If all instances of this device are to be read, use device (name) without an instance number. All pic values will be sampled when using the -r option. -w device-inst [,pic0=event] [,picn=event] Program (write) the specified devices to count the specified events. Write access to the counters is restricted to root users only. Non-root users can use -r option. Specify device-inst as device (name) followed by an optional instance number. If specifying an instance number of a device to program these events on. If all instances of this device are to be programmed the same, then use device without an instance number. Specify an event to be counted for a specified pic by providing a comma separated list of picn=event values. The -e option displays all valid event names for each device. Any devices that are programmed will be sampled every interval seconds and repeated count times. It is recommended that the interval specified is small enough to ensure that counter wraparound will be detected. The rate at which counters wraparound varies from device to device. If a user is programming events using the -w option and busstat detects that another user has changed the events that are being counted, the tool will terminate as the programmed devices are now being controlled by another user. Only one user can be programming a device instance at any one time. Extra devices can be sampled using the -r option. Using multiple instances of the -w option on the same command line, with the same device-inst specifying a differ- ent list of events for the pics will give the effect of multiplexing for that device. busstat will switch between the list of events for that device every interval seconds. Event can be a string representing the event name, or even a number representing the bit pat- tern to be programmed into the Performance Control Register (PCR). This assumes explicit knowledge of the meaning of the control reg- ister bits for a device. The number can be specified in hexadecimal, decimal, or octal, using the usual conventions of strtol(3C). EXIT STATUS
The following exit values are returned: 0 Successful completion. 1 An error occurred. 2 Another user is writing to the same devices. EXAMPLES
SPARC Only Example 1: Programming and monitoring the Address Controller counters In this example, ac0 refers to the Address Controller instance 0. The counters are programmed to count Memory Bank stalls on an Ultra Enterprise system at 10 second intervals with the values displayed in absolute form instead of deltas. # busstat -a -w ac0,pic0=mem_bank0_stall,pic1=mem_bank1_stall 10 time dev event0 pic0 event1 pic1 10 ac0 mem_bank0_stall 1234 mem_bank1_stall 5678 20 ac0 mem_bank0_stall 5678 mem_bank1_stall 12345 30 ac0 mem_bank0_stall 12345 mem_bank1_stall 56789 ... For a complete list of the supported events for a device, use the -e option. Example 2: Programming and monitoring the counters on all instances of the Address Controller In this example, ac refers to all ac instances. This example programs all instances of the Address Controller counters to count_clock cycles and mem_bank0_rds at 2 second intervals, 100 times, displaying the values as deltas. # busstat -w ac,pic0=clock_cycles,pic1=mem_bank0_rds 2 100 time dev event0 pic0 event1 pic1 2 ac0 clock_cycles 167242902 mem_bank0_rds 3144 2 ac1 clock_cycles 167254476 mem_bank0_rds 1392 4 ac0 clock_cycles 168025190 mem_bank0_rds 40302 4 ac1 clock_cycles 168024056 mem_bank0_rds 40580 ... Example 3: Monitoring the events being counted This example monitors the events that are being counted on the sbus1 device, 100 times at 1 second intervals. It suggests that a root user has changed the events that sbus1 was counting to be dvma_tlb_misses and interrupts instead of pio_cycles. % busstat -r sbus0 1 100 time dev event0 pic0 event1 pic1 1 sbus1 pio_cycles 2321 pio_cycles 2321 2 sbus1 pio_cycles 48 pio_cycles 48 3 sbus1 pio_cycles 49 pio_cycles 49 4 sbus1 pio_cycles 2281 pio_cycles 2281 5 sbus1 dvma_tlb_misses 0 interrupts 0 6 sbus1 dvma_tlb_misses 6 interrupts 2 7 sbus1 dvma_tlb_misses 8 interrupts 11 ... Example 4: Event Multiplexing This example programs ac0 to alternate between counting (clock cycles, mem_bank0_rds) and (addr_pkts, data_pkts) at 2 second intervals while also monitoring what ac1 is counting : It shows the expected output of the above busstat command. Another root user on the machine has changed the events that this user had pro- grammed and busstat has detected this and terminates the command with a message. # busstat -w ac0,pic0=clock_cycles,pic1=mem_bank0_rds -w ac0,pic0=addr_pkts,pic1=data_pkts -r ac1 2 time dev event0 pic0 event1 pic1 2 ac0 addr_pkts 12866 data_pkts 17015 2 ac1 rio_pkts 385 rio_pkts 385 4 ac0 clock_cycles 168018914 mem_bank0_rds 2865 4 ac1 rio_pkts 506 rio_pkts 506 6 ac0 addr_pkts 144236 data_pkts 149223 6 ac1 rio_pkts 522 rio_pkts 522 8 ac0 clock_cycles 168021245 mem_bank0_rds 2564 8 ac1 rio_pkts 387 rio_pkts 387 10 ac0 addr_pkts 144292 data_pkts 159645 10 ac1 rio_pkts 506 rio_pkts 506 12 ac0 clock_cycles 168020364 mem_bank0_rds 2665 12 ac1 rio_pkts 522 rio_pkts 522 busstat: events changed (possibly by another busstat). # ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
iostat(1M), mpstat(1M), vmstat(1M), strtol(3C), attributes(5) SunOS 5.10 1 Nov 1999 busstat(1M)
All times are GMT -4. The time now is 01:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy