The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need Help with Perl Scripting Issue. manik112 Shell Programming and Scripting 23 12-13-2008 12:52 PM
Perl Script Issue - Please Help * Thanks!!! jroberson Shell Programming and Scripting 8 11-03-2008 03:47 AM
perl issue .. zedex Shell Programming and Scripting 3 09-13-2008 11:22 PM
issue with if loop in perl amitrajvarma Shell Programming and Scripting 4 01-09-2008 12:02 AM
Perl problem (compiling issue) 01000101 Shell Programming and Scripting 3 05-24-2006 10:15 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
  #8 (permalink)  
Old 01-27-2009
KevinADC KevinADC is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2008
Posts: 731
maybe:

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

tr/"//d for @fields;
  #9 (permalink)  
Old 01-27-2009
raj001 raj001 is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 13
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 (permalink)  
Old 01-27-2009
KevinADC KevinADC is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2008
Posts: 731
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 (permalink)  
Old 01-28-2009
raj001 raj001 is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 13
Kevin-

I really thank you for all your efforts.

Might be any other Perl experts can help me out on this forum.
  #12 (permalink)  
Old 01-28-2009
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,884
Quote:
Originally Posted by raj001 View Post
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 (permalink)  
Old 01-28-2009
raj001 raj001 is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 13
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 (permalink)  
Old 01-29-2009
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,884
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.
Sponsored Links
Closed Thread

Bookmarks

Tags
perl, perl shift, shift, shift perl

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:38 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0