Sponsored Content
Top Forums Shell Programming and Scripting Perl : converting file to different scalar elements Post 302962287 by scriptscript on Friday 11th of December 2015 06:50:47 AM
Old 12-11-2015
Perl : converting file to different scalar elements

I have a text file containing 2 exec statements as below and trying to store the below 2 execs into 2 different scalar variables in perl.

Code:
/* ICD Dist, Total */  /* need to export to Excel, sheet=ICD_Dist__Total */
exec(
'select sum(count(*)) 
		cast(count(*)*100.0/sum(count(*)) over() as decimal(18,2)) as percent_total
from DETAIL_' + @dataset_id + ' 
 
)


/* ICD Dist, by Month */  /* need to export to Excel */
exec(
'select  serv_yrmo_tot_claims, 
		cast(count(*)*100.0/sum(count(*)) over(partition by left(convert(varchar,SERVICE_DT,112),6)) as decimal(18,2)) as percent_per_mth
from DETAIL_' + @dataset_id + ' 
 
)


final output should be like

Code:
$query1 = 'exec(
'select sum(count(*)) 
		cast(count(*)*100.0/sum(count(*)) over() as decimal(18,2)) as percent_total
from DETAIL_' + @dataset_id + ' 
 
)'
$query2 = 'exec(
'select  serv_yrmo_tot_claims, 
		cast(count(*)*100.0/sum(count(*)) over(partition by left(convert(varchar,SERVICE_DT,112),6)) as decimal(18,2)) as percent_per_mth
from DETAIL_' + @dataset_id + ' 
 
)'


tried with few possible regex but couldn't able to make it.
Could anyone please help out in solving this.

Last edited by scriptscript; 12-11-2015 at 07:57 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl scalar variable in backquoted string

hi I've been searching all over the internet to simply do the following: $tempfile = "/usr/school/tempfile.dat"; $myvar = param('add'); ###add is the variable assigned to a popup menu `ls -l $myvar * >> $tempfile` ###I also tried `ls -l ${myvar}* >>$tempfile` open(ADDLIST,... (6 Replies)
Discussion started by: mehdi9
6 Replies

2. Shell Programming and Scripting

scalar variable assignment in perl + { operator

When reading over some perl code in a software document, I came across an assignment statement like this $PATH = ${PROJECT}/......./.... In this particular form of scalar variable assignment, what does the curly braces operators do ? Also, what is the benefit in doing scalar assignment this... (3 Replies)
Discussion started by: JamesGoh
3 Replies

3. Shell Programming and Scripting

Perl - New line in array elements

Hello, I have a comma delimited input feed file. The first field has directory location and the second field has file name. Ex of input feed: /export/appl/a,abc*.dat /export/appl/b,xyz*.dat /export/appl/c,pmn*.dat Under each directory, there would be many files like... . . .... (4 Replies)
Discussion started by: bperl
4 Replies

4. Shell Programming and Scripting

[Perl] Accessing array elements within a sed command in Perl script

I am trying to use a script to replace the header of each file, whose filename are stored within the array $test, using the sed command within a Perl script as follows: $count = 0; while ( $count < $#test ) { `sed -e 's/BIOGRF 321/BIOGRF 332/g' ${test} > 0`; `cat 0 >... (2 Replies)
Discussion started by: userix
2 Replies

5. Shell Programming and Scripting

Perl:Use of array elements in pattern matching

I need to use array elements while pattern matching. @myarr = (ELEM1, ELEM2, ELEM3); following is the statement which I am using in my code. Basically I want to replace the ELEM1/2/3 with other thing which is mentioned as REPL here. if (condition) { s/(ELEM1|ELEM2|ELEM3): REPL: /; } I... (3 Replies)
Discussion started by: deo_kaustubh
3 Replies

6. Shell Programming and Scripting

perl DBI: populate a scalar from a select statement

hi every resource i see regarding DBI refers to retrieving data from a database into and array or a hash, but i havent seen anything on how to pull out a single value to a scalar in my database i have a field called "forcewrite" with a value of "6". I am trying to connect to the database,... (2 Replies)
Discussion started by: hcclnoodles
2 Replies

7. Shell Programming and Scripting

Perl Array Elements Replacement

Hello, I have the following perl array: @longname = (Fasthernet0/0 Fasthernet0/1 Serial0/1/0 Serial0/2/1 Tunnel55 Tunnel77) with the followinh array: @shortname = (Fa0/0 Fa0/1 Se0/1/0 Se0/2/1 Tu55 Tu77) in other words, I need to remove the following from each element in the array... (4 Replies)
Discussion started by: ahmed_zaher
4 Replies

8. Shell Programming and Scripting

Help required converting XSD to XML file in PERL

Hi, Please find below the xsd. <?xml version="1.0" encoding="ISO-8859-1" ?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="fruitorder"> <xs:complexType> <xs:sequence> <xs:element name="orderperson"... (2 Replies)
Discussion started by: vanitham
2 Replies

9. Shell Programming and Scripting

Array elements comparison using perl

Experts, I am looking to compare elements of 2 array using perl. Below is not the actual code but logic wise something like this. my $version = "MYSQlcl-5.2.4-264.x86_64"; <-- split this word into array as (5 2 4 264) ( which is to extract only the version number from the package name) my... (1 Reply)
Discussion started by: solaix14
1 Replies

10. Shell Programming and Scripting

Perl : to get the no. of elements from DataDumper

Hello Folks, I have a DataDumper variable and the output of the dataDumper is printed in the below manner. print Dumper \%mnemonics; VAR1 = { 'SYS-7-CLI_SCHEDULER_LOG_STORED' => , 'CRYPTO-6-IKMP_MODE_FAILURE' => , 'AAAA-4-SERVUNDEF' => , ... (1 Reply)
Discussion started by: scriptscript
1 Replies
RawIP::libpcap(3pm)					User Contributed Perl Documentation				       RawIP::libpcap(3pm)

NAME
Net::RawIP::libpcap - An interface to libpcap in Net::RawIP(3pm) DESCRIPTION
Function The input parameters The output parameters open_live a network Return value is a pcap_t* device(eth0,ppp0,...); If retval less than zero a snap length; then $err filled with a promisc - boolean; an error string. a timeout in sec; $err is an undef scalar; open_offline a filename which is filled Return value is pcap_t* with a raw output of dump; If retval less than zero $err is an unfef scalar; then $err filled with an error string. dump_open pcap_t*; Return value is a FILE* $err; lookupdev $err; Return value is a name of first device which is found by libpcap lookupnet a network device; a netnumber; a netnumer is undef; a netmask; a netmask is undef; If retval less than zero $err is undef; then $err filled with an error string. dispatch a scalar with pcap_t*; No output parameters. number of packets for proce- ssing; reference to the perl call- back,this callback will be called with 3 parameters: $_[0] is fourth parameter from dispatch, $_[1] is a scalar with struc- ture pcap_pkthdr for a current packet, $_[2] is a scalar with a current packet; fourth parameter could be an array or a hash reference or a pointer (FILE*) returned by dump_open,it can be unre- ferenced in the perl call- back or be used as a perl filehandle in that callback. loop As for dispatch. As for dispatch. dump As for a perl callback No output. but $_[0] must be a pointer (FILE*) only. compile a scalar with pcap_t*; a scalar with bpf_program. a bpf_program is undef; If retval is less than zero a scalar with filter string; then there was a problem with a boolean value (optimize or filter grammar. not); a scalar with netmask; setfilter a scalar with pcap_t*; If retval is less than zero a scalar with bpf_program then there was a problem while returned by compile. settting filter. next a scalar with pcap_t*; A scalar with next packet; a scalar with with struc- a scalar with with structure ture pcap_pkthdr for a current pcap_pkthdr also will be modi packet,originally is undef. filed for an every packet and it can be accessed but for read only. datalink a scalar with pcap_t*; Retval is the link layer type, e.g. DLT_EN10MB. snapshot a scalar with pcap_t*; Retval is the snapshot length specified when open_live was called. is_swapped a scalar with pcap_t*; returns true if the current savefile uses a different byte order than the current system. major_version a scalar with pcap_t*; returns the major number of the version of the pcap used to write the savefile. minor_version a scalar with pcap_t*; returns the minor number of the version of the pcap used to write the savefile. file a scalar with pcap_t*; returns the name of the savefile. stats a scalar with pcap_t*; If retval 0 then a scalar a scalar with structure with structure pcap_stat will pcap_stat,originally undef be filled with the packet statistics. fileno a scalar with pcap_t*; returns the file descriptor number of the savefile. A core perl function is available as CORE::fileno. geterr a scalar with pcap_t*; returns the error text pertaining to the last pcap library error. perror a scalar with pcap_t*; prints the text of the last a scalar with prefix; pcap library error on stderr, prefixed by prefix. close a scalar with pcap_t*; closes the files associated with pcap_t* and deallocates resources. A core perl function is available as CORE::close. dump_close a scalar with pcap_t*; closes the savefile. AUTHOR
Sergey Kolychev <ksv@al.lg.ua> SEE ALSO
Net::RawIP(3pm),pcap(3). perl v5.14.2 2007-04-03 RawIP::libpcap(3pm)
All times are GMT -4. The time now is 01:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy