Sponsored Content
Full Discussion: Perl split and array
Top Forums Shell Programming and Scripting Perl split and array Post 302932847 by derekludwig on Sunday 25th of January 2015 05:40:06 PM
Old 01-25-2015
Don, Zam,

$list[0] is the empty string because a space was prepended to $line on line 126.

Zam,

Perhaps a little simplification is needed:
Code:
while (<fd_in>) {
   s{\s*#.*$}{};
   ($cpu_id, $key, $pic0, $pic1) = (split)[1,2,3,4];
   next if $key eq 'total';
print 'cpuID:', $cpu_id, ' pic0:', $pic0, ' pic1:', $pic1, "\n";

Remove s{\s*#.*$}{} if '#' does not begin a comment.
These 2 Users Gave Thanks to derekludwig For This Post:
 

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
cpc_set_create(3CPC)				    CPU Performance Counters Library Functions				      cpc_set_create(3CPC)

NAME
cpc_set_create, cpc_set_destroy, cpc_set_add_request, cpc_walk_requests - manage sets of counter requests SYNOPSIS
cc [ flag... ] file... -lcpc [ library... ] #include <libcpc.h> cpc_set_t *cpc_set_create(cpc_t *cpc); int cpc_set_destroy(cpc_t *cpc, cpc_set_t *set); int cpc_set_add_request(cpc_t *cpc, cpc_set_t *set, const char *event, uint64_t preset, uint_t flags, uint_t nattrs, const cpc_attr_t *attrs); void cpc_walk_requests(cpc_t *cpc, cpc_set_t *set, void *arg, void (*action)(void *arg, int index, const char *event, uint64_t preset, uint_t flags, int nattrs, const cpc_attr_t *attrs)); DESCRIPTION
The cpc_set_create() function returns an initialized and empty CPC set. A CPC set contains some number of requests, where a request repre- sents a specific configuration of a hardware performance instrumentation counter present on the processor. The cpc_set_t data structure is opaque and must not be accessed directly by the application. Applications wanting to program one or more performance counters must create an empty set with cpc_set_create() and add requests to the set with cpc_set_add_request(). Once all requests have been added to a set, the set must be bound to the hardware performance counters (see cpc_bind_curlwp(), cpc_bind_pctx(), and cpc_bind_cpu(), all described on cpc_bind_curlwp(3CPC)) before counting events. At bind time, the system attempts to match each request with an available physical counter capable of counting the event specified in the request. If the bind is successful, a 64-bit virtualized counter is created to store the counts accumulated by the hardware counter. These counts are stored and managed in CPC buffers separate from the CPC set whose requests are being counted. See cpc_buf_create(3CPC) and cpc_set_sam- ple(3CPC). The cpc_set_add_request() function specifies a configuration of a hardware counter. The arguments to cpc_set_add_request() are: event A string containing the name of an event supported by the system's processor. The cpc_walk_events_all() and cpc_walk_events_pic() functions (both described on cpc_npic(3CPC)) can be used to query the processor for the names of available events. Certain processors allow the use of raw event codes, in which case a string representation of an event code in a form acceptable to strtol(3C) can be used as the event argument. preset The value with which the system initializes the counter. flags Three flags are defined that modify the behavior of the counter acting on behalf of this request: CPC_COUNT_USER The counter should count events that occur while the processor is in user mode. CPC_COUNT_SYSTEM The counter should count events that occur while the processor is in privileged mode. CPC_OVF_NOTIFY_EMT Request a signal to be sent to the application when the physical counter overflows. A SIGEMT signal is delivered if the processor is capable of delivering an interrupt when the counter counts past its maximum value. All requests in the set containing the counter that overflowed are stopped until the set is rebound. At least one of CPC_COUNT_USER or CPC_COUNT_SYSTEM must be specified to program the hardware for counting. nattrs, attrs The nattrs argument specifies the number of attributes pointed to by the attrs argument, which is an array of cpc_attr_t structures containing processor-specific attributes that modify the request's configuration. The cpc_walk_attrs() function (see cpc_npic(3CPC)) can be used to query the processor for the list of attributes it accepts. The library makes a private copy of the attrs array, allowing the application to dispose of it immediately after calling cpc_set_add_request(). The cpc_walk_requests() function calls the action function on each request that has been added to the set. The arg argument is passed unmodified to the action function with each call. RETURN VALUES
Upon successful completion, cpc_set_create() returns a handle to the opaque cpc_set_t data structure. Otherwise, NULL is returned and errno is set to indicate the error. Upon successful completion, Cpc_set_destroy() returns 0. Otherwise, -1 is returned and errno is set to indicate the error. Upon successful completion, cpc_set_add_request() returns an integer index used to refer to the data generated by that request during data retrieval. Otherwise, -1 is returned and errno is set to indicate the error. ERRORS
These functions will fail if: EINVAL An event, attribute, or flag passed to cpc_set_add_request() was invalid. For cpc_set_destroy() and cpc_set_add_request(), the set parameter was not created with the given cpc_t. ENOMEM There was not enough memory available to the process to create the library's data structures. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Committed | +-----------------------------+-----------------------------+ |MT-Level |Safe | +-----------------------------+-----------------------------+ SEE ALSO
cpc_bind_curlwp(3CPC), cpc_buf_create(3CPC), cpc_npic(3CPC), cpc_seterrhndlr(3CPC), libcpc(3LIB), strtol(3C), attributes(5) NOTES
The system automatically determines which particular physical counter to use to count the events specified by each request. Applications can force the system to use a particular counter by specifying the counter number in an attribute named picnum that is passed to cpc_set_add_request(). Counters are numbered from 0 to n - 1, where n is the number of counters in the processor as returned by cpc_npic(3CPC). Some processors, such as UltraSPARC, do not allow the hardware counters to be programmed differently. In this case, all requests in the set must have the same configuration, or an attempt to bind the set will return EINVAL. If a cpc_errhndlr_t has been registered with cpc_seter- rhndlr(3CPC), the error handler is called with subcode CPC_CONFLICTING_REQS. For example, on UltraSPARC pic0 and pic1 must both program events in the same processor mode (user mode, kernel mode, or both). For example, pic0 cannot be programmed with CPC_COUNT_USER while pic1 is programmed with CPC_COUNT_SYSTEM. Refer to the hardware documentation referenced by cpc_cpuref(3CPC) for details about a particular pro- cessor's performance instrumentation hardware. SunOS 5.11 20 Aug 2007 cpc_set_create(3CPC)
All times are GMT -4. The time now is 10:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy