For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > April 2005 > Binding Operator =~ Pattern Matching









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Binding Operator =~ Pattern Matching
Brian Volk

2005-04-27, 3:56 am

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



John W. Krahn

2005-04-27, 3:56 am

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 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) {



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



John
--
use Perl;
program
fulfillment
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com