Perl Issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl Issue
# 8  
Old 01-27-2009
maybe:

Code:
sub get 
{
return $_[0]->exists($_[1]) ?
       $_[0]->get($_[1])->[$_[2] ?
       $_[2] =~ tr/"//d : 0] : '';
}

remove this line:

tr/"//d for @fields;
# 9  
Old 01-27-2009
Thanks for reply.

However, it is not working. Can't you put the same thing on this variable "$_[0]"?

I believe this is value which gets printed.
# 10  
Old 01-27-2009
Sorry raj001,

I have never used that module and I have no idea what the underlying data structure is so I can't really figure it out.
# 11  
Old 01-28-2009
Kevin-

I really thank you for all your efforts.

Might be any other Perl experts can help me out on this forum.
# 12  
Old 01-28-2009
Quote:
Originally Posted by raj001
The following commad actually prints header, cant we use the same thing on the below line which prints data field values;

print '"'.(join '","', "@dn",map {get $entry, $_->[1], $_->[2]} @fields)."\"\n";
Raj,

Kevin's scriptlet should work just fine. Printing the headers is an entirely different matter. You only want the data to be processed. Again, what happens when you do this?
Code:
@dn = map {s/[a-z]+=//gi; tr/"//d; $_ = ucfirst} # organization

# 13  
Old 01-28-2009
Let me explain this further, the output of my file looks as following :

"Domain","address","department","displayname","sn","roomno","site","location"
"Internal","1234","HCM","John D","JOHN D","rocks" 12","seigo"
"Internal","12345","TDM","Mr Say","Mr Say T","hupt","margo"

There are three ways in which this csv file is written out:

First the header, then the first field value (Internal) which remains same across all the rows,and last all the fields values for each user in a row.

As pointed by you, the following line prints only the first field value:

@dn = map {s/[a-z]+=//gi; tr/"//d; $_ = ucfirst} # organization

this line prints the header:

print '"'.(join '","', "DuPont_ECD_Report",map {$_->[0]} @fields)."\"\n"; # header

and last line which prints out fields values:

print '"'.(join '","', "@dn",map {get $entry, $_->[1], $_->[2]} @fields)."\"\n";

the above line uses a subroutine "get", which I am unable to comprehend as how it process each entry.

sub get
{
return $_[0]->exists($_[1])
? $_[0]->get($_[1])->[$_[2] ? $_[2] : 0]
: '';
}

The issue is to remove the quotes occuring within the field values as mentioned in the first row.

Hope this makes things clear.

Thanks.
# 14  
Old 01-29-2009
Ah, @dn is only the first field? That's weird. Why use an array?? Oh well. So for the second join, just do this:
Code:
print '"'.(join '","', "@dn",grep {tr/"//d,$_} map {get $entry, $_->[1], $_->[2]} @fields)."\"\n";

The grep routine evaluates the expression and returns the last result for each line in the input. Its input is the output of the map expression. The reason you wouldn't use map here is because map returns every result for each line in the input and because tr returns a number.

Don't worry about this get routine so much.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Perl - EMail issue - NEED Help

I have a perl that is sending emails in a bad format: "begin 644 Included.doc M*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ M*BHJ*BHJ*BHJ*BH*4U5#0T534T953"!-1$XG<R!F;W(@07)C:&EV92!022`M M($-A;F-E;`HJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ... (1 Reply)
Discussion started by: mrn6430
1 Replies

2. Shell Programming and Scripting

Out of memory issue in perl

I am getting a out of memory issue while executing the perl program. Per version : /opt/acc_perl/lib/site_perl/5.14.2 Read in 54973 total records Read in 54973 table records from table. Out of memory! so the job get failed due to out of memory. need to get rid of the out of memory... (3 Replies)
Discussion started by: ramkumar15
3 Replies

3. Shell Programming and Scripting

Perl format issue

Input : day :15 and count -100 printf ("%6.6ld %10.10s %s\n",day,count) any idea what would be the format it will be. (3 Replies)
Discussion started by: ramkumar15
3 Replies

4. Shell Programming and Scripting

PERL - issue with OPEN

Hi, I have a menu script written in PERL which calls some shell scripts and displays the return. I'm having a problem with OPEN. A section of the code is below: `./scriptlist.ksh 1`; open OUTPUT, "</home/$SCRIPTUSER/output"; { local $/ = undef; $_ =... (2 Replies)
Discussion started by: chris01010
2 Replies

5. Shell Programming and Scripting

perl command issue

Hi, Please could someone advise on a perl command : export ENVPROP="$HOME/cfg/environment.properties.template" export LM_LICENSE=`awk -F= '!/^#/ && /LM_LICENSE/{print $2}' environment.properties` echo $LM_LICENSE $DATA_FILE/licenses/sample.demo.lic perl -i -npe... (1 Reply)
Discussion started by: venhart
1 Replies

6. Shell Programming and Scripting

wc -l command issue with perl

Hi Team, the Following program execute with out error but the out is not save with create2.txt. kindly help me!!! print "Enter your Number \n"; my $name = <STDIN>; if ($name =="*91111*") { @dirlist1 = `wc -l $name > create2.txt`; } else {print "do not match";} (3 Replies)
Discussion started by: adaleru
3 Replies

7. Shell Programming and Scripting

Perl issue - please help!

Hello. I've been writing some code in Perl to read in strings from html files and have been having issues. In the html file, each "paragraph" is a certain file on the website. I need to find every one of the files that is a certain type, in this case, having green color....therefore... (7 Replies)
Discussion started by: akreibich07
7 Replies

8. Shell Programming and Scripting

Perl Script Issue - Please Help * Thanks!!!

Please help me with my script please. I am trying to do the following: 1. Read files for the current directory 2. Open and read from nbe files files only 3. Read only the lines with the results pattern 4. Split the line and print 3rd field Please indicate what line I need to modify. ... (8 Replies)
Discussion started by: jroberson
8 Replies

9. Shell Programming and Scripting

perl issue ..

hi one perl issue i have xml file with 2 values and one condition b.w them <rule> <val1>12</val1> <cond>and</cond> <val2>13</val2> </rule> i read these values in hash in perl code $one{val1} = 12 $one{cond} = and $one{val2} = 13 now i want to form... (3 Replies)
Discussion started by: zedex
3 Replies

10. Shell Programming and Scripting

issue with if loop in perl

Hi I have a log file, I am having problem with "if else" loop in my perl script which does, find a string in that file ,If that string is found append to success.txt else append it to failed.txt. problem is: else part of loop it is not working I am adding problem part of the script. ... (4 Replies)
Discussion started by: amitrajvarma
4 Replies
Login or Register to Ask a Question