Personally, I'd do it the other way around, that is, just write the whole thing in Perl... but ok, embedding Perl into a longer shell script is ok too, I guess... ;-)

I'm assuming you're using bash, and you don't seem to need STDIN in your Perl script, so I'd probably use a here doc, like in the following. I've also made some tweaks, plus you didn't seem to be passing the Perl script any filenames. (Note: I tested without RTF::TEXT::Converter.)

function fConvert { perl -wMstrict -- - $@ <<'ENDPERL' use RTF::TEXT::Converter; my $result = ''; my $object = RTF::TEXT::Converter->new( output => \$result ); foreach my $filename (@ARGV) { $object->parse_stream($filename); print $result; $result = ''; } ENDPERL }

Update: Or, just make it a oneliner ;-) (the module just prints its output by default)

perl -wMstrict -MRTF::TEXT::Converter -00ne 'RTF::TEXT::Converter->new->parse_string($_)'

Update 2: I guess I should mention why I'd suggest a heredoc: when the delimiter is quoted (as in 'ENDPERL'), you don't have to worry about special characters within the heredoc.


In reply to Re: Perl and Shell (text conversion) (updated) by haukex
in thread Perl and Shell (text conversion) by Bryan882

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, details, 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, summary, 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.