Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl -w # # address.pl # # -h to print the help doco # # to generate the export of the notes address book, go to # address book, # file->export-> <choose file name> ->export -> # <replace if file already exists> -> # <select all documents> <select character code 12> # <select wrap width=75> ->OK # use strict; use Getopt::Std; my %settings = ( debug => 0, print_fields => ["CompanyName", "OfficePhoneNumber", "CellPhoneNumber", "PhoneNumber", "MailAddress", "OfficeFAXPhoneNumber"], number_srch => 0, print_all_fields => 0, ); # $settings->{print_fields}: we will print these if they have a value { my %args; local $SIG{'__WARN__'} = sub { print "$_[0]\n"; help(); exit 1; }; getopts("n:ha", \%args); $args{h} and do { help(); exit; }; $settings{number_srch} = $args{n} if $args{n}; $settings{print_all_fields} = 1 if $args{a}; } my $address_file = $ENV{'HOME'} . '/dev/docs/address.txt' ; my @addresses; read_address_file($address_file); my $pattern = $ARGV[0] || '.*'; $pattern =~ s/(?<!\.)\*/\.\*/g; $pattern = '\b' . $pattern; print "[$pattern]\n" if $settings{debug}; for my $record ( @addresses ){ if ( $settings{number_srch} ){ for ( @{$settings{print_fields}} ){ if ( $record->{$_} =~ /$settings{number_srch}/ ){ print_record($record); last; } } next; } if ( $record->{FullName} =~ /$pattern/i ){ print_record($record); } } exit; sub print_record { my $record = $_[0]; my $full_name = $record->{FullName}; $full_name = parse_full_name($full_name) if ( $full_name =~ /,/ ); print $full_name, ":\n"; unless ($settings{print_all_fields}){ for ( @{$settings{print_fields}} ){ my $value = $record->{$_}; # don't print the company name if it is "personal" next if ( /^CompanyName$/ and $value =~ /^personal$/i ); printf "\t%-20s: %s\n", $_, $value if ( $value ); } # notes can give them an InternetAddress instead of a MailAddress. +.. if ( ! $record->{MailAddress} ){ my $value = $record->{InternetAddress}; printf "\t%-20s: %s\n", 'InternetAddress', $value if ( $value ); } return; } # print everything! for (keys %{$record}){ my $value = $record->{$_}; printf "\t%-20s: %s\n", $_, $value if ( $value ); } } sub read_address_file { my $address_file = shift || die "You didn't tell me the name of the +address file!\n"; my @temp=(); open(ADDRESS, $address_file) || die "Could not open $address_file: $ +!\n"; while (<ADDRESS>){ s/\r//g; s/\s*$//; chomp; my $rec={}; if (/^\s*$/ ){ # whitespace record delimiter... next if (! @temp); for my $fields (@temp){ my ($field, $value) = split /:\s*/, $fields; $value =~ s/\s+/ /g; $rec->{$field} = $value; if ( $field eq "FullName" ){ $value =~ s/[\s\W]//g; $rec->{SortName} = lc ($value); } } push @addresses, $rec; @temp = (); next; } push @temp, $_; } close(ADDRESS); @addresses = sort { $a->{SortName} cmp $b->{SortName} } @addresses; } sub parse_full_name { # sometimes lotus does odd things to the name... my $name = shift || die "sub parse_full_name did not get a parameter +\n"; my @bits = split /,/, $name; for (@bits){ next if /\./; next if /@/; next if /=/; next unless /\s+/; $name = $_; } return $name; } sub help { print "$0: [-n number] [-h] [-a] \"name_pattern\"\n"; print "\tname pattern: case insensitive, understands *, over-ridden +by -n\n"; print "\t-n matches numerically against number\n"; print "\t-h prints this message\n"; print "\t-a print all fields not just the default ones\n"; }

In reply to Lotus Notes address book export browser by greenFox

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-05-24 04:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found