Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Binding Operator =~ Pattern Matching
Hi All.

I'm having trouble getting my program to work with the files that contain
trailing white spaces...  I've been reading chapters 8 "More about Reg exp"
and 9 "Using Reg exp" and I think I'm close...  I can get the program to
work if the txt files do not have trailing spaces but they are coming from a
mini-frame that uses field length (30) and the files are right justified.
For example:

(my $orders_dir)
File 121212.TXT ...contains
12345.html  <spaces> CR
12346.html  <spaces> CR

Here is the piece I'm having trouble w/

foreach my $html (@htmls) {
if ($html =~ /^($_)\s*/) {
my $msg = MIME::Lite->new (


This actually does the same thing as this piece of code...  which works only
if the files do not have trailing spaces...

foreach my $html (@htmls) {
if ($_ eq $html) {
my $msg = MIME::Lite->new (

Here is the entire program..

#!/usr/bin/perl

use strict;
use warnings;
use MIME::Lite;
use Net::SMTP;

# directory contains html files
my $html_dir = "M:";

opendir(DIR, $html_dir) or die "Can't open the $html_dir: $!\n";

# read file/directory names in that directory into @htmls

my @htmls = readdir(DIR) or die "Unable to read current dir:$!\n";

closedir(DIR);

# directory contains .txt files w/ lines that match a html file
my $orders_dir = "I:/MSDSIN";
opendir (ORDERS, $orders_dir) or die "Can't open $orders_dir: $!";

# read all the item numbers(+html) in all the .txt files and
# load @ARGV for <> operator

@ARGV = map { "$orders_dir/$_" } grep { !/^\./ } readdir ORDERS;

while (<> ) {
chomp;
# email information
my $from_address = 'bvolk@bvolk.com' <mailto:'bvolk@bvolk.com'> ;
my $to_address = 'bvolk@hpproducts.com' <mailto:'bvolk@hpproducts.com'> ;
my $mail_host = 'smtp.bvolk.com';
my $message_body = "Attached is the msds for $ARGV";

foreach my $html (@htmls) {
if ($html =~ /^($_)\s*/) {
# if ($_ eq $html) {
my $msg = MIME::Lite->new (

From => $from_address,
To => $to_address,
Subject => $ARGV,
Type =>'multipart/mixed'
) or die "Error creating multipart container: $!\n";

$msg->attach (
Type => 'TEXT',
Data => $message_body,
) or die "Error adding the text message part: $!\n";

$msg->attach (
Type => 'application',
Path => "$html_dir/$html",
Disposition => 'attachment'
) or die "Error adding $html $!\n";

MIME::Lite->send('smtp', $mail_host, Timeout=>60);
$msg->send;
}
}
}

closedir (ORDERS);

___END

Any help would be greatly appreciated!  Thanks!

Brian Volk
HP Products
317.298.9950 x1245
<mailto:bvolk@hpproducts.com> bvolk@hpproducts.com




Report this thread to moderator Post Follow-up to this message
Old Post
Brian Volk
04-27-05 08:56 AM


Re: Binding Operator =~ Pattern Matching
Brian Volk wrote:
> Hi All.

Hello,

> I'm having trouble getting my program to work with the files that contain
> trailing white spaces...  I've been reading chapters 8 "More about Reg exp
"
> and 9 "Using Reg exp" and I think I'm close...  I can get the program to
> work if the txt files do not have trailing spaces but they are coming from
 a
> mini-frame that uses field length (30) and the files are right justified.
> For example:
>
> (my $orders_dir)
> File 121212.TXT ...contains
> 12345.html  <spaces> CR
> 12346.html  <spaces> CR
>
> Here is the piece I'm having trouble w/
>
>      foreach my $html (@htmls) {
>      if ($html =~ /^($_)\s*/) {
>      my $msg = MIME::Lite->new (
>
>
> This actually does the same thing as this piece of code...  which works on
ly
> if the files do not have trailing spaces...
>
>      foreach my $html (@htmls) {
>      if ($_ eq $html) {
>      my $msg = MIME::Lite->new (
>
> Here is the entire program..
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
> use MIME::Lite;
> use Net::SMTP;
>
> # directory contains html files
> my $html_dir = "M:";
>
> opendir(DIR, $html_dir) or die "Can't open the $html_dir: $!\n";
>
> # read file/directory names in that directory into @htmls
>
> my @htmls = readdir(DIR) or die "Unable to read current dir:$!\n";
>
> closedir(DIR);
>
> # directory contains .txt files w/ lines that match a html file
> my $orders_dir = "I:/MSDSIN";
>  opendir (ORDERS, $orders_dir) or die "Can't open $orders_dir: $!";
>
> # read all the item numbers(+html) in all the .txt files and
> # load @ARGV for <> operator
>
> @ARGV = map { "$orders_dir/$_" } grep { !/^\./ } readdir ORDERS;
>
> while (<> ) {
>      chomp;
> # email information
> my $from_address = 'bvolk@bvolk.com' <mailto:'bvolk@bvolk.com'> ;
> my $to_address = 'bvolk@hpproducts.com' <mailto:'bvolk@hpproducts.com'> ;
> my $mail_host = 'smtp.bvolk.com';
> my $message_body = "Attached is the msds for $ARGV";
>
>      foreach my $html (@htmls) {
>      if ($html =~ /^($_)\s*/) {
>      # if ($_ eq $html) {


foreach my $html (@htmls) {
$html =~ s/\s+\z//;
if ($_ eq $html) {



John
--
use Perl;
program
fulfillment

Report this thread to moderator Post Follow-up to this message
Old Post
John W. Krahn
04-27-05 08:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:33 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.