Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • 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 lurking in the Monastery: (5)
    As of 2024-07-12 19:00 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?
      erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.