Automating Lotus Notes Text Style with perl? - perl

I'm trying to automate the sending of an email with an embedded attachment and some text that implements HTML code but it seems that the code that I am using will not allow me to create an HTML bolded text or a unordered list. To double check I created the code in vba then passed it through a vba to perl converter and it matched up with what I had written. Here is the part of my script that handles creating the text and embedded attachment in the email:
my $richStyle = $Document->NotesRichTextStyle();
$richStyle->{'PassThruHTML'} = 1;
my $Body = $Document->CreateRichTextItem('Body');
$Body->AppendText(">>EOT");
$Body->AppendStyle($richStyle);
**$Body->AppendText("<b>HELLO</b>");**
$Body->EmbedObject(EMBED_ATTACHMENT,'','$filename','$name');
I get this error:
Not a HASH reference at line $richStyle->{'PassThruHTML'} = 1;
The main point of this code was so that i could use HTML Tags inside the email

My best guess:
my $richStyle = $Document->NotesRichTextStyle();
From the designer help:
Set notesRichTextStyle = notesSession.CreateRichTextStyle( )
You need to create the notesRichTextStyle using the session.

I guess you want to create an HTML mail?
In that case, it would be better to use the MIME entity classes to generate native HTML mails and not to rely on the NotesRichText to HTML conversion.
You can find more info on the MIME entity in the Designer Help: http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/index.jsp?topic=/com.ibm.designer.domino.main.doc/H_NOTESMIMEENTITY_CLASS_OVERVIEW.html

$ perl -Mdiagnostics -e " []->{1}=2 "
Not a HASH reference at -e line 1 (#1)
(F) Perl was trying to evaluate a reference to a hash value, but found a
reference to something else instead. You can use the ref() function to
find out what kind of ref it really was. See perlref.
Uncaught exception from user code:
Not a HASH reference at -e line 1.
at -e line 1
so whatever NotesRichTextStyle returns doesn't like ->{...} so maybe use ->SetProperty... or something else :/

Related

How to perl convert xml (name with pattern) to json?

The next convert test.xml to json:
perl -MJSON::Any -MXML::Simple -le'print JSON::Any->new()->objToJson(XMLin("/tmp/test.xml "))'
but I need convert any xml (example test-1.xml test-2.xml test-3.xml test-4.xml etc) with pattern name /tmp/test-*.xml, but if I use:
perl -MJSON::Any -MXML::Simple -le'print JSON::Any->new()->objToJson(XMLin("/tmp/test-*.xml "))'
I have the next messages:
File does not exist: /tmp/test-*.xml at -e line 1
How I do it?
There's problems with what you're trying to do:
XML::Simple isn't simple. It's for simple XML. It'll mangle your XML and give inconsistent results. See: Why is XML::Simple "Discouraged"?
XML is fundamentally more complicated than JSON, so there's no linear transformation. You need to figure out what'd you'd do with attributes and duplicate elements for a start.
File does not exist: /tmp/test-*.xml at -e line 1 - means the file doesn't exist. So you're not going to get very far. But XMLin doesn't accept wildcards. You'll have to process one file at a time.
The first two points are solvable, provided you accept that this cannot be a generic solution - to give a moderately general solution, we'll need an example of your source XML. But it won't be a one liner.
You seem to be asking how to find files matching a file glob.
You could use
my #qfns = glob("/tmp/test-*.xml");
If you just want the first matching file, use
my ($qfn) = glob("/tmp/test-*.xml");
Do not use the following since glob acts an iterator in scalar context.
my $qfn = glob("/tmp/test-*.xml"); # XXX
You can try this using glob and map functions.
perl -MJSON::Any -MXML::Simple -le'local $,="\n"; print map { JSON::Any->new()->objToJson(XMLin($_)) } glob "/path/to/my/test*.xml"'

Retrieving String with single quotes from database and storing in Perl

I have a SQL query
select name from Employee
Output :
Sharma's
How can I store this output in perl string.
I tried below :
$sql =qq {select Name from Employee};
$Arr = &DataBaseQuery( $dbHandle, $sql );
$name = $Arr;
But when I print $name I get output as
Sharma::s
How can I store the single quote in the $name.
First of all, non of standard DBI/DBD exibits behavior you listed, in my experience.
Without knowing details of what DataBaseQuery() does it's impossible to answer conclusively, but a plausible theory can be formed:
Apostrophe is a valid package separator in Perl, equivalent to "::".
Reference: perldoc perlmod
The old package delimiter was a single quote, but double colon is now the preferred delimiter, in part because it's more readable to humans, and in part because it's more readable to emacs macros. It also makes C++ programmers feel like they know what's going on--as opposed to using the single quote as separator, which was there to make Ada programmers feel like they knew what was going on. Because the old-fashioned syntax is still supported for backwards compatibility, if you try to use a string like "This is $owner's house" , you'll be accessing $owner::s ; that is, the $s variable in package owner , which is probably not what you meant. Use braces to disambiguate, as in "This is ${owner}'s house" .
perl -e 'package A::B; $A::B=1; 1;
package main;
print "double-colon: $A::B\n";
print "apostrophe: $A'"'"'B\n";'
double-colon: 1
apostrophe: 1
I have a strong suspicion something within your own libraries inside DataBaseQuery() call was written to be "smart" and to convert apostrophes to double-colons because of this.
If you can't figure out root cause, you can always do one of the following:
Write your own DB wrapper
Assuming your text isn't likely to contain "::", run a regex to fix s#::#'#g; on all results from DataBaseQuery() (likely, in a function serving as a wrapper-replacement for DataBaseQuery())

How to print variable inside function

I'm using RRDs::Simple function and it needs bunch of parameters.
I have placed these parameters in a special variable (parsing, sorting and calculating data from a file) with all quotes, commas and other stuff.
Of course
RRDs::create ($variable);
doesn't work.
I've glanced through all perl special variables and have found nothing.
How to substitute name of variable for the data that contained in that variable?
At least could you tell me with what kind of tools(maybe another special variables) it can be done?
Assuming I'm understanding what you're asking:
You've build the 'create' data in $variable, and are now trying to use RRDs::create to actually do it?
First step is:
print $variable,"\n"; - to see what is actually there. You should be able to use this from the command line, with rrdtool create. (Which needs a filename, timestep, and some valid DS and RRA parameters)
usually, I'll use an array to pass into RRDs::create:
RRDs::create ( "test.rrd", "-s 300",
"DS:name:GAUGE:600:U:U", )
etc.
If $variable contains this information already, then that should be ok. The way to tell what went wrong is:
if ( RRDs::error ) { print RRDs::error,"\n"; }
It's possible that creating the file is the problem, or that your RRD definitions are invalid for some reason. rrdtool create on command line will tell you, as will RRDs::error;

Strange problem with Email::MIME - can't use string as a HASH ref

I'm having a strange problem with Email:MIME. I have the following code, which is intended to parse a MIME email message piped to it:
my $parsed = Email::MIME->new(<STDIN>);
print $parsed->body;
When I run this, either by piping a sample MIME email into it, or by setting my host to pipe new email to it and sending myself one, I get the following error on the first line:
> Can't use string ("Received: from
> servera02.tk2adsm") as a HASH ref
> while "strict refs" in use at
> /usr/lib/perl5/site_perl/5.8.8/Email/Simple.pm
> line 100, <STDIN> line 71.
The line shown in the error varies according to the email but it is always the second line of the email content (so I'm really not very sure why it's claiming it's STDIN line 71). I've done some googling about this and it really seems to be unique to me - does anyone have any ideas?
I'm not a Perl expert by a long way, and I've never used Email::MIME, so I'm hoping this is something simple.
Chris
The documentation says that new() expects its argument to be a message in the form of a string. <STDIN> is an array (since an argument list is in list context).
Try converting the message to a string as you pass it: my $parsed = Email::MIME->new(join('', <STDIN>));
i mean you might not get the error if you turn off strict refs

Print freeform text in a Perl function?

I have been getting a very odd error when trying to print freeform text in a subroutine in Perl. Below is the code I am calling
print OUTFILE <<"HEADER";
The freeform text would go here
HEADER
The odd thing is that this only works in the main of my function. As soon as I place it in a function call, I get this error:
Can't find string terminator "HEADER" anywhere before EOF
Meaning it can't find the HEADER, even though it is there. Can you not use freeform text within a function (subroutine)?
Make sure that there is no space/tab/indentation before ending string identifier, that is HEADER. Your code should look like this:
function someFunc(){
print OUTFILE <<"HEADER";
The freeform text would go here
HEADER
}
Notice that there is no space/tab/indentation before HEADER there. It should start from first character of its line.
Check this tutorial out for more information:
Perl Here-Doc Tutorial
Quoting:
The important rule to remember is that
you finish a here-doc using the same
word you started, and it must be by
itself on the line