Sponsored Content
Full Discussion: Perl Issue
Top Forums Shell Programming and Scripting Perl Issue Post 302280523 by raj001 on Tuesday 27th of January 2009 07:14:23 AM
Old 01-27-2009
Perl Issue

Hi,

I got this script from the web, this generates an LDAP report in CSV format.

Code:
#!/usr/bin/perl
#
# Copyright (c) 2004
# Ali Onur Cinar &060;cinar&064;zdo.com&062;
#
# License:
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for non-commercial purposes and without fee is hereby
# granted, provided that the above copyright notice appear in all copies
# and that both the copyright notice and this permission notice and
# warranty disclaimer appear in supporting documentation, and that the name
# of Ali Onur Cinar not be used in advertising or publicity pertaining to
# distribution of the software without specific, written prior permission.
#
# @author A. Onur Cinar <cinar(a)zdo.com># @version $Id: ldap2csv.pl,v 1.1 2004/12/07 15:12:38 cinar Exp $#
use Net::LDAP;
@fields = # fields to export
(  # Label Field Name Index 
  ['First Name', 'givenName' , 0], ['Last Name' , 'sn' , 0], ['Title' , 'title' , 0],
  ['Email' , 'mail' , 0], ['Email 2' , 'mail' , 1], ['Phone' , 'telephoneNumber', 0], 
  ['Phone' , 'telephoneNumber', 1], ['Phone' , 'telephoneNumber', 2], 
  ['Phone' , 'telephoneNumber', 3], ['Phone' , 'telephoneNumber', 4], 
  ['Mobile' , 'mobile' , 0], 
  ['Birthday' , 'birthday' , 0], ['Address' , 'street' , 0], ['Address' , 'street' , 1], 
  ['Address' , 'street' , 2],
);
 
$ldap = Net::LDAP->new('localhost') or die "$@"; # open connection
$mesg = $ldap->bind( # login 
            "uid=test", password => "password");
$mesg = $ldap->search( # search 
            base => "dc=abc", 
            filter => "(objectClass=inetOrgPerson)"
);
 
$DATETIME=`date`;
 
sub get # get field value
{ return $_[0]->exists($_[1]) ? $_[0]->get($_[1])->[$_[2] ? $_[2] : 0] : '';}
 
print "$DATETIME"; # first line with file created date/time
print '"'.(join '","', "Report", # header map {$_->[0]} @fields)."\"\n";
foreach $entry ($mesg->all_entries) # for each entry
{ 
   @dn = map {s/[a-z]+=//gi; $_ = ucfirst} # organization 
          reverse split /,/, $entry->dn; 
   shift @dn; shift @dn; 
   shift @dn; pop @dn; 
 
   print '"'
       . (join '","', "@dn",         # row map   
            {get $entry, $_->[1], $_->[2]} @fields)
       . "\"\n";
}
$mesg = $ldap->unbind; # close connection

This script prints value in the following format :

Code:
 
"abc","1234","HCM","John D","JOHN D","rocks" 12","seigo"
"abc2","12345","TDM","Mr Say","Mr Say T","hupt","margo"

If you see there is a quote in the field (rocks" 12), I want to remove the quote from the field value only.Is there any way to modify the script and remove the quotes occuring in any of the field?

Thanks in Advance.

Last edited by otheus; 01-28-2009 at 06:31 AM.. Reason: formatting
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
TAP::Parser::Source::Perl(3pm)				 Perl Programmers Reference Guide			    TAP::Parser::Source::Perl(3pm)

NAME
TAP::Parser::Source::Perl - Stream Perl output VERSION
Version 3.17 SYNOPSIS
use TAP::Parser::Source::Perl; my $perl = TAP::Parser::Source::Perl->new; my $stream = $perl->source( [ $filename, @args ] )->get_stream; DESCRIPTION
Takes a filename and hopefully returns a stream from it. The filename should be the name of a Perl program. Note that this is a subclass of TAP::Parser::Source. See that module for more methods. METHODS
Class Methods "new" my $perl = TAP::Parser::Source::Perl->new; Returns a new "TAP::Parser::Source::Perl" object. Instance Methods "source" Getter/setter the name of the test program and any arguments it requires. my ($filename, @args) = @{ $perl->source }; $perl->source( [ $filename, @args ] ); "croak"s if $filename could not be found. "switches" my $switches = $perl->switches; my @switches = $perl->switches; $perl->switches( @switches ); Getter/setter for the additional switches to pass to the perl executable. One common switch would be to set an include directory: $perl->switches( ['-Ilib'] ); "get_stream" my $stream = $source->get_stream($parser); Returns a stream of the output generated by executing "source". Must be passed an object that implements a "make_iterator" method. Typically this is a TAP::Parser instance. "shebang" Get the shebang line for a script file. my $shebang = TAP::Parser::Source::Perl->shebang( $some_script ); May be called as a class method "get_taint" Decode any taint switches from a Perl shebang line. # $taint will be 't' my $taint = TAP::Parser::Source::Perl->get_taint( '#!/usr/bin/perl -t' ); # $untaint will be undefined my $untaint = TAP::Parser::Source::Perl->get_taint( '#!/usr/bin/perl' ); SUBCLASSING
Please see "SUBCLASSING" in TAP::Parser for a subclassing overview. Example package MyPerlSource; use strict; use vars '@ISA'; use Carp qw( croak ); use TAP::Parser::Source::Perl; @ISA = qw( TAP::Parser::Source::Perl ); sub source { my ($self, $args) = @_; if ($args) { $self->{file} = $args->[0]; return $self->SUPER::source($args); } return $self->SUPER::source; } # use the version of perl from the shebang line in the test file sub _get_perl { my $self = shift; if (my $shebang = $self->shebang( $self->{file} )) { $shebang =~ /^#!(.*perl.*?)(?:(?:s)|(?:$))/; return $1 if $1; } return $self->SUPER::_get_perl(@_); } SEE ALSO
TAP::Object, TAP::Parser, TAP::Parser::Source, perl v5.12.5 2012-11-03 TAP::Parser::Source::Perl(3pm)
All times are GMT -4. The time now is 11:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy