[29941] in Perl-Users-Digest
Perl-Users Digest, Issue: 1184 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 10 00:09:40 2008
Date: Wed, 9 Jan 2008 21:09:05 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 9 Jan 2008 Volume: 11 Number: 1184
Today's topics:
Re: Active State perl for windows not working. <kcom@fusemail.com>
Re: Active State perl for windows not working. <john@castleamber.com>
Re: Active State perl for windows not working. <jurgenex@hotmail.com>
Re: every($key, $interval) function <No_4@dsl.pipex.com>
Re: every($key, $interval) function <uri@stemsystems.com>
Re: every($key, $interval) function <rvtol+news@isolution.nl>
Re: Help with a Reg Ex <tadmc@seesig.invalid>
Re: HELP! File Copy, Move and Rename will not work in m <karinwalike@comcast.net>
Re: HELP! File Copy, Move and Rename will not work in m <tadmc@seesig.invalid>
Re: Search/Replace text in XML file <tadmc@seesig.invalid>
Re: Search/Replace text in XML file <tadmc@seesig.invalid>
Sending HTML (MIME) email with Net::SMTP ? <wheeledBobNOSPAM@yahoo.com>
Re: Sending HTML (MIME) email with Net::SMTP ? <wheeledBobNOSPAM@yahoo.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 09 Jan 2008 20:53:19 -0400
From: Caduceus <kcom@fusemail.com>
Subject: Re: Active State perl for windows not working.
Message-Id: <h1rao3p7j3lslub8h9ma8l5ful2qd5ehv5@4ax.com>
On Wed, 09 Jan 2008 17:48:44 GMT, Jürgen Exner <jurgenex@hotmail.com>
wrote:
>
>Any reason why not simply adding the perl bin directory to the path
>permanently?
>Control Panel -> System -> Advanced -> Environment Variables
>
>jue
What do I change the Variables ?
------------------------------
Date: 10 Jan 2008 03:04:04 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Active State perl for windows not working.
Message-Id: <Xns9A20D6511ECF0castleamber@130.133.1.4>
Caduceus <kcom@fusemail.com> wrote:
> On Wed, 09 Jan 2008 17:48:44 GMT, Jürgen Exner <jurgenex@hotmail.com>
> wrote:
>
>
>>
>>Any reason why not simply adding the perl bin directory to the path
>>permanently?
>>Control Panel -> System -> Advanced -> Environment Variables
>>
>>jue
>
> What do I change the Variables ?
Personally, I would recommend to uninstall Active Perl, and reinstall it.
It /should/ set up your environment etc. correctly. It has done so for me
for years AFAIK.
--
John
http://johnbokma.com/mexit/
------------------------------
Date: Thu, 10 Jan 2008 04:03:16 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Active State perl for windows not working.
Message-Id: <916bo3dh7chvil96p57abf2jee0t7mv28e@4ax.com>
Caduceus <kcom@fusemail.com> wrote:
>On Wed, 09 Jan 2008 17:48:44 GMT, Jürgen Exner <jurgenex@hotmail.com>
>>Any reason why not simply adding the perl bin directory to the path
>>permanently?
>>Control Panel -> System -> Advanced -> Environment Variables
>
>What do I change the Variables ?
If you don't know how to add a directory to the path variable after going to
the dialog I pointed out above, then probably you are better of to
re-installing ActiveState Perl and let the setup program set the path
correctly for you.
It _REALLY_ is not rocket science, but your knowledge of computers doesn't
seem to be that deep.
jue
------------------------------
Date: Wed, 09 Jan 2008 23:36:30 +0000
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: every($key, $interval) function
Message-Id: <YuCdnY6f35zixxjanZ2dnUVZ8vCdnZ2d@pipex.net>
Uri Guttman wrote:
> BaB> "our %counters" works.
>
> and that declares and uses a global which can be modified by outside
> code. not a better solution.
I'd thought that to - so I tested it by trying to access %counters at
the end of the script:
==========
#!/usr/bin/perl
use strict;
use warnings;
sub every{
# my %counters if 0;
our %counters;
(++$counters{ \$_[1] } % $_[0]) or $_[1] and print $_[1], "\n";
}
for my $i (1..13) {
every(7, my $ev0);
every(3, my $ev1 = "A:$i");
every(3, my $ev2 = "B:$i");
every(5, my $ev3 = "C:$i");
}
print keys %counters, "\n";
==========
The result?
[mysys]: /usr/bin/perl -wc x.pl
Variable "%counters" is not imported at x.pl line 18.
Global symbol "%counters" requires explicit package name at x.pl line 18.
x.pl had compilation errors.
So it actually seems to work (removing line 18 lets the script run, and it
produces the same results as the "my %counters" version).
--
Just because I've written it doesn't mean that
either you or I have to believe it.
------------------------------
Date: Thu, 10 Jan 2008 00:04:31 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: every($key, $interval) function
Message-Id: <x7odbu5ywg.fsf@mail.sysarch.com>
>>>>> "BaB" == Big and Blue <No_4@dsl.pipex.com> writes:
BaB> Uri Guttman wrote:
BaB> "our %counters" works.
>> and that declares and uses a global which can be modified by outside
>> code. not a better solution.
BaB> I'd thought that to - so I tested it by trying to access %counters
BaB> at the end of the script:
BaB> sub every{
BaB> # my %counters if 0;
BaB> our %counters;
BaB> (++$counters{ \$_[1] } % $_[0]) or $_[1] and print $_[1], "\n";
BaB> }
BaB> for my $i (1..13) {
BaB> every(7, my $ev0);
BaB> every(3, my $ev1 = "A:$i");
BaB> every(3, my $ev2 = "B:$i");
BaB> every(5, my $ev3 = "C:$i");
BaB> }
BaB> print keys %counters, "\n";
BaB> [mysys]: /usr/bin/perl -wc x.pl
BaB> Variable "%counters" is not imported at x.pl line 18.
BaB> Global symbol "%counters" requires explicit package name at x.pl line 18.
BaB> x.pl had compilation errors.
try it with %main::counters.
you don't understand how our works. it declares a lexically scoped name
(really an alias) to a global in the current namespace. so with strict
you need to fully qualify the name to access it. but it is still a
global and accessible from anywhere.
BaB> So it actually seems to work (removing line 18 lets the script run,
BaB> and it produces the same results as the "my %counters" version).
no, as i said it still is a global and doesn't hide the counter hash at
all.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Architecture, Development, Training, Support, Code Review ------
----------- Search or Offer Perl Jobs ----- http://jobs.perl.org ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Thu, 10 Jan 2008 01:19:06 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: every($key, $interval) function
Message-Id: <fm3s0h.1fo.1@news.isolution.nl>
Ted Zlatanov schreef:
> The goal is to do
>
> warn "five or six" if (every(5) || every(6));
Use (any variant of) my second approach:
#!/usr/bin/perl
use strict;
use warnings;
sub every{
my %counters if 0;
my ($div, @id) = @_;
return !(++$counters{ caller(), $div, @id } % $div);
}
for my $i (1..32) {
print "five or six:\t$i\n" if every(5) | every(6);
}
__END__
five or six: 5
five or six: 6
five or six: 10
five or six: 12
five or six: 15
five or six: 18
five or six: 20
five or six: 24
five or six: 25
five or six: 30
You just can't use the shortcutting "||", because the rightside every()
would not be called when the leftside every() already is true. (So you
had an xy-problem.)
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Wed, 9 Jan 2008 21:18:10 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Help with a Reg Ex
Message-Id: <slrnfob3ji.ndu.tadmc@tadmc30.sbcglobal.net>
amerar@iwc.net <amerar@iwc.net> wrote:
>
> I have the following expression in my Perl script:
^^
^^
> if (/^"([^\,].+)"\,"$/)
>
> Although I know that it is checking to see if the string starts with
> some characters, it is not working for my input file.
>
> Can someone explain to me in english what it is doing???
Since you wrote it, you should be able to do that yourself.
Or did you mean "in someone else's Perl script" instead?
:-)
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Wed, 9 Jan 2008 16:19:04 -0800 (PST)
From: kwalike57 <karinwalike@comcast.net>
Subject: Re: HELP! File Copy, Move and Rename will not work in my script!
Message-Id: <799b1f6e-78bd-4212-a765-ffd9e75ce1c3@v67g2000hse.googlegroups.com>
On Jan 8, 9:04=A0pm, "John W. Krahn" <some...@example.com> wrote:
> kwalike57 wrote:
> > On Jan 8, 3:33 pm, "John W. Krahn" <some...@example.com> wrote:
>
> >> Your second posting of the same problem and you still have not posted
> >> any code.
>
> >> My crystal ball seems to think that you may have a problem with
> >> directories, either incorrect names or missing completely? =A0Possibly =
on
> >> line 42?
>
> It looks like my crystal ball is batting .500, correct problem, wrong
> line number.
>
> > Here is the code...
>
> > #!/perl/bin/perl
>
> You should start off with the two pragmas:
>
> use warnings;
> use strict;
>
> > #
> > #NewAutoConDir.pl
> > #Karin Walike
> > #12.01.07
> > #
> > #Connect:Direct process automation for server PKSW1714
> > #The script sleeps and wakes up to check and see if there is a file
> > #has been loaded to the server for Connect:Direct to customer.
> > #
> > #
> > #We currently have XX customers sending/receiving data to this node.
> > #
> > #Product list: =A0xx, xx, xx, xx, xx,
>
> > use MIME::Lite;
> > use Cwd;
> > use File::Copy;
>
> You don't appear to be using either Cwd or File::Copy?
>
> > my $date=3Dlocaltime();
>
> > my $dirVM=3D"D:\\Prod_D\\BOP\\Data\\SMSDATA\\PCSWHSLE\\CD\\VM\\";
> > my $doneDir=3D"D:\\Prod_D\\BOP\\Data\\SMSDATA\\PCSWHSLE\\CD\\VM\\DONE\
> > \";
>
> > my $FILE;
> > my @FILES;
>
> These should be declared inside the loop instead of here.
>
> > my $doneExt =3D ".done";
>
> > my $ConDir1=3D"D:\\tools\\'Sterling Commerce'\\'CONNECT Direct v4.1'\
> > \'Common Utilities'";
> > my $ConDir2=3D"D:\\Prod_D\\BOP\\Scripts\\temp";
> > my $ConDir3=3D"D:\\Prod_D\\BOP\\scripts\\triggerDir";
>
> > my $LOG=3D"D:\\Prod_D\\BOP\\Logs\\ConDirLogVM_1.txt";
> > my $LOG2=3D"D:\\Prod_D\\BOP\\Logs\\ConDirLogVM_2.txt";
>
> > my $LOG3=3D"D:\\Prod_D\\BOP\\Logs\\ConDirLogVM_3.txt";
> > my $LOG4=3D"D:\\Prod_D\\BOP\\Logs\\ConDirLogVM_4.txt";
>
> > my $EXCONDIR=3D"D:\\Prod_D\\BOP\\Scripts\\temp\\ConDirVM.cmd";
>
> You should use the forward slash (/) instead of the backslash (\) for
> path separators.
>
> > open (OUT,">>$LOG");
>
> You should *always* verify the success of open(). =A0You should probably
> use a different name for the filehandle.
>
> > while(1) {
>
> > =A0 =A0# Open the directory VM
>
> > =A0 =A0if( -d $dirVM ) {
> > =A0 =A0 =A0 =A0 =A0 =A0opendir( VMDIR, $dirVM ) || die "Cannot open dire=
ctory $dirVM $!";
> > =A0 =A0}else{
> > =A0 =A0 =A0 =A0 =A0 =A0print "Directory $dirVM does not exist. Exiting..=
.\n";
> > =A0 =A0exit;
> > =A0 =A0}
>
> > =A0 =A0# Iterate through the directory VM
>
> > =A0 =A0opendir(VMDIR, $dirVM) || die "Cannot open directory $dirVM $!";
>
> Why open the directory twice. =A0The whole if-else block is superfluous.
>
> > =A0 =A0#open(VMDIR,"D:\\Prod_D\\BOP\\Data\\SMSDATA\\PCSWHSLE\\VM") || di=
e
> > "Cannot open directory $dirVM $!";
> > =A0 =A0#open(VMDIR,'dir "D:\Prod_D\BOP\Data\SMSDATA\PCSWHSLE\VM" |') || =
die;
>
> > =A0 =A0 =A0 =A0 =A0 =A0@FILES =3D readdir(VMDIR);
>
> > =A0 =A0#closedir(VMDIR);
>
> > =A0 =A0 =A0 =A0 =A0 =A0chomp (@FILES);
>
> chomp() is superfluous and *may* damage valid file names.
>
> > =A0 =A0 =A0 =A0 =A0 =A0print "\n@FILES\n";
>
> > =A0 =A0foreach $FILE ( @FILES ) {
>
> > =A0 =A0 =A0 =A0 =A0 =A0if ($FILE !~ /^RU_VIRGIN_MOBILE_[0-9]_[0-9][0-9][=
0-9][0-9][0-9][0-9]
> > [0-9][0-9].*\.gz$/) {
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0#print "$FILE is not an EMBARQ pr=
oduct...\n";
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto sleeplabel;
>
> You don't need to use goto, you should use next and a continue block
> instead.
>
> > =A0 =A0 =A0 =A0 =A0 =A0}else{
>
> > =A0 =A0 =A0 =A0 =A0 =A0chomp($FILE);
>
> Why chomp the same variable a second time? =A0chomp() is superfluous and
> *may* damage valid file names.
>
> > =A0 =A0 =A0 =A0 =A0 =A0print "\nFile is $FILE\n";
>
> > =A0 =A0 =A0 =A0 =A0 =A0print "\nBeginning Connect:Direct processing for =
VIRGIN MOBILE
> > customer file...\n";
>
> > =A0 =A0 =A0 =A0 =A0 =A0print OUT "\n$date $FILE\n";
>
> > =A0 =A0 =A0 =A0 =A0 =A0goto sleeplabel if (!$FILE);
>
> You don't need to use goto, you should use next and a continue block
> instead. =A0How did $FILE get modified so that it became '0' or ''?
>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (file_transfer_complete($FILE)=
) {
>
> One of the classic beginner mistakes. =A0Your subroutine
> file_transfer_complete is using stat() on the file names but you need
> the complete path to properly stat() the file.
>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0print "\nFound file $FILE\n";
>
> > =A0 =A0open(IN, "$ConDir3\\send_triggerVM.pl");
> > =A0 =A0open(OUT, ">$ConDir2\\tmp_sendVM.cdp");
>
> Why are you reusing the same filehandle name that you used for the log fil=
e?
>
> > =A0 =A0while (<IN>) {
> > =A0 =A0 =A0 =A0 =A0 =A0if (/ConDirFile/) {
> > =A0 =A0 =A0 =A0 =A0 =A0s/ConDirFile/$dirVM$FILE/;
>
> You don't have to use the same regular expression twice.
>
> > =A0 =A0 =A0 =A0 =A0 =A0}
> > =A0 =A0 =A0 =A0 =A0 =A0print OUT $_;
> > =A0 =A0 =A0 =A0 =A0 =A0}
> > =A0 =A0 =A0 =A0 =A0 =A0close(OUT);
> > =A0 =A0 =A0 =A0 =A0 =A0close(IN);
>
> > =A0 =A0print "First Connect:Direct pre-processing step passed...\n";
>
> > =A0 =A0"$ConDir2\\tmp_sendVM.cdp > D:\\Prod_D\\BOP\\scripts\\temp\\file"=
;
>
> If you had warnings enabled you would have received a warning about a
> constant in void context here.
>
> > sleep 10;
>
> > =A0 =A0print "Second Connect:Direct pre-processing step passed...\n";
>
> > =A0 =A0system =A0$EXCONDIR || errorexit(2, "\nConnect:Direct process fai=
led");
>
> Because of the relatively high precedence of the || operator the
> errorexit() sub will never be called. =A0If you fixed the precedence then
> errorexit() will only be called when system() succeeded.
>
> > =A0 =A0print "\nConnect:Direct processing for VIRGIN MOBILE customer fil=
e
> > completed...\n";
>
> > =A0 =A0print OUT "\nConnect:Direct Processed for $date $FILE\n";
>
> > =A0 =A0# Send email to notify file has been C:D to mainframe
>
> > =A0 =A0my $machine =3D "PKSW1714";
>
> > =A0 =A0my $email =3D 'IOP-ITSupp...@sprint.com';
>
> > =A0 =A0my $email2 =3D 'CD....@sprint.com';
>
> > =A0 =A0my $subject =3D "Connect:Direct Processing VIRGIN MOBILE: $FILE h=
as
> > been sent to VIRGIN MOBILE node VSCPFTP01";
>
> > =A0 =A0my $body =3D " Hello, \n\n $FILE has been moved from $machine to
> > VSCPFTP01. \n\n Please contact $email2 with questions. \n\n Thanks, \n
> > \n IOP Connect:Direct Team\n\n";
>
> > =A0 =A0my $server =3D "10.214.13.55";
>
> $machine, $email, $email2 and $server are constants so why are they
> inside the loop?
>
> > =A0 =A0my $msg =3D MIME::Lite->new(
> > =A0 =A0 =A0 =A0 =A0 =A0From =3D> 'CD....@sprint.com',
> > =A0 =A0 =A0 =A0 =A0 =A0To =3D> 'IOP-ITSupp...@sprint.com',
>
> Why define variables for those strings and then not use them?
>
> > =A0 =A0 =A0 =A0 =A0 =A0Subject =3D> $subject,
> > =A0 =A0 =A0 =A0 =A0 =A0Type =3D> 'TEXT',
> > =A0 =A0 =A0 =A0 =A0 =A0Data =3D> $body
> > =A0 =A0);
>
> > =A0 =A0#Use SMTP to send
> > =A0 =A0MIME::Lite->send('smtp', $server, Timeout=3D>60);
> > =A0 =A0sleep 30;
> > =A0 =A0$msg->send;
> > =A0 =A0open(OUT, ">>$LOG"); #reopen closed LOG
>
> If you had used a different name for the filehandle then you wouldn't
> have to do this.
>
> > =A0 =A0print "\nEmail notification of Connect:Direct transfer sent...\n"=
;
>
> > =A0 =A0#sleeplabel2:
> > =A0 =A0print"\n\n*******Waiting for VIRGIN MOBILE file processing to
> > complete*******\n\n";
> > =A0 =A0sleep 50;
>
> > =A0 =A0# Rename the current process to done
>
> > =A0 =A0chomp($FILE);
>
> Why chomp the same variable a third time? =A0chomp() is superfluous and
> *may* damage valid file names.
>
> > =A0 =A0print "File is writable\n" if -w $FILE;
>
> You are using the file name only not the complete path so -w will not
> find the file you want.
>
> > =A0 =A0$FILEDONE =3D $FILE . $doneExt;
>
> > =A0 =A0chomp($FILEDONE);
>
> Again, why are you chomp()ing the file name? =A0Do you know what chomp() d=
oes?
>
> > =A0 =A0print "filedone=3D$FILEDONE\n";
>
> > =A0 =A0#rename ("D:\\Prod_D\\BOP\\Data\\SMSDATA\\PCSWHSLE\\CD\\VM\
> > \RU_VIRGIN_MOBILE_1_20071130.007.gz", "D:\\Prod_D\\BOP\\Data\\SMSDATA\
> > \PCSWHSLE\\CD\\VM\\RU_VIRGIN_MOBILE_1_20071130.007.gz.done");
> > =A0 =A0rename ($FILE, $FILEDONE);
>
> You are using the file name only not the complete path so rename() will
> not find the file you want.
>
> > =A0 =A0#if (renamefiles($FILE)) {
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0print "\nFile successfully rename=
d: $FILEDONE\n" || errorexit(14,
> > "Could not rename $FILE");
> > =A0 =A0#}
>
> > =A0 =A0#move ($FILE,$FILEDONE) || errorexit(9, "Unable to move $FILE");
>
> > =A0 =A0#copy ($FILE,$FILEDONE) || errorexit(12, "Unable to copy $FILE to=
> > $FILEDONE");
>
> > =A0 =A0sleeplabel:
>
> You don't need to use goto, you should use next and a continue block
> instead.
>
> > =A0 =A0print"\n\n*******Waiting for VIRGIN MOBILE Connect:Direct file***=
****
> > \n\n";
> > =A0 =A0sleep 10;
>
> > #
> > # Begin Subroutines
> > #
>
> Why are you defining your subroutines *inside* the loop?
>
> > #
> > # Sub file_transfer_complete
> > #
> > # monitor a file for size changes over a brief period
> > #
> > # parm1 - file name
> > # parm2 - delay in seconds (optional)
> > #
> > sub file_transfer_complete {
>
> > my $filename =3D shift;
> > my $waitTime =3D shift || 20;
>
> > my $sizefirst =3D -s $filename; =A0 =A0 =A0# initial file size
> > sleep $waitTime; =A0 =A0 =A0 =A0 =A0 # wait a while
>
> > my $sizeDelta =3D -s $filename; =A0 =A0 =A0#file size after wait
>
> You are using the file name only not the complete path so -s will not
> find the file you want.
>
> > if( $sizeDelta =3D=3D $sizefirst ) {
> > =A0 =A0print "transfer complete $filename 1: $sizefirst\t2: $sizeDelta" =
;
> > =A0 =A0return 1;
> > } else {
> > =A0 =A0print "transfer incomplete $filename 1: $sizefirst\t2: $sizeDelta=
" ;
> > =A0 =A0return 0;
> > =A0 =A0}
> > }
>
> > # Sub errorexit print error message to the log and return an error
> > code
> > #
> > sub errorexit {
> > =A0 =A0my $returncode =3D shift;
> > =A0 =A0my $message =3D shift;
> > =A0 =A0open (OUT, ">>$LOG");
>
> If you had used a different name for the filehandle then you wouldn't
> have to do this.
>
> > =A0 =A0print OUT "\n### ERROR $returncode ### $message";
> > =A0 =A0exit ($returncode);
> > }
>
> > # Sub Rename files to .done extension
> > #
> > sub renamefiles {
>
> > =A0 =A0my $file1 =3D shift;
>
> > =A0 =A0my $done =3D ".done";
>
> Why not use the $doneExt variable?
>
> > =A0 =A0my $file2 =3D $file1 . $done;
>
> > =A0 =A0rename ($file1, $file2) || die "Cannot rename $file1\n";
>
> You are using the file name only not the complete path so rename() will
> not find the file you want.
>
> > }
> > }
> > }
> > }
> > }
>
> To sum up, here is the code with modifications that should work better
> (*UNTESTED*):
>
> #!/perl/bin/perl
> use warnings;
> use strict;
> #
> #NewAutoConDir.pl
> #Karin Walike
> #12.01.07
> #
> #Connect:Direct process automation for server PKSW1714
> #The script sleeps and wakes up to check and see if there is a file
> #has been loaded to the server for Connect:Direct to customer.
> #
> #
> #We currently have XX customers sending/receiving data to this node.
> #
> #Product list: =A0xx, xx, xx, xx, xx,
>
> use MIME::Lite;
>
> my $dirVM =A0 =A0=3D 'D:/Prod_D/BOP/Data/SMSDATA/PCSWHSLE/CD/VM';
> my $doneDir =A0=3D 'D:/Prod_D/BOP/Data/SMSDATA/PCSWHSLE/CD/VM/DONE';
> my $ConDir2 =A0=3D 'D:/Prod_D/BOP/Scripts/temp';
> my $ConDir3 =A0=3D 'D:/Prod_D/BOP/scripts/triggerDir';
> my $LOG =A0 =A0 =A0=3D 'D:/Prod_D/BOP/Logs/ConDirLogVM_1.txt';
>
> my $EXCONDIR =3D 'D:/Prod_D/BOP/Scripts/temp/ConDirVM.cmd';
>
> my $date =A0 =A0 =3D localtime;
> my $doneExt =A0=3D '.done';
> my $machine =A0=3D 'PKSW1714';
> my $email =A0 =A0=3D 'IOP-ITSupp...@sprint.com';
> my $email2 =A0 =3D 'CD....@sprint.com';
> my $server =A0 =3D '10.214.13.55';
>
> open my $LOGFH, '>>', $LOG or die "Cannot open '$LOG' $!";
>
> while ( 1 ) {
> =A0 =A0 =A0# Open the directory VM
> =A0 =A0 =A0# Iterate through the directory VM
> =A0 =A0 =A0opendir my $VMDIR, $dirVM or die "Cannot open directory $dirVM =
$!";
> =A0 =A0 =A0my @FILES =3D readdir $VMDIR;
> =A0 =A0 =A0closedir $VMDIR;
> =A0 =A0 =A0print "\n@FILES\n";
> =A0 =A0 =A0for my $FILE ( @FILES ) {
> =A0 =A0 =A0 =A0 =A0if ( $FILE !~ /^RU_VIRGIN_MOBILE_[0-9]_[0-9]{8}.*\.gz$/=
) {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0#print "$FILE is not an EMBARQ product...\n";
> =A0 =A0 =A0 =A0 =A0 =A0 =A0next;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0 =A0 =A0print "\nFile is $FILE\n";
> =A0 =A0 =A0 =A0 =A0print "\nBeginning Connect:Direct processing for VIRGIN=
MOBILE
> customer file...\n";
> =A0 =A0 =A0 =A0 =A0print $LOGFH "\n$date $FILE\n";
> =A0 =A0 =A0 =A0 =A0next unless file_transfer_complete( "$dirVM/$FILE" );
> =A0 =A0 =A0 =A0 =A0print "\nFound file $FILE\n";
> =A0 =A0 =A0 =A0 =A0open my $IN, =A0'<', "$ConDir3/send_triggerVM.pl" or di=
e "Cannot
> open '$ConDir3/send_triggerVM.pl' $!";
> =A0 =A0 =A0 =A0 =A0open my $OUT, '>', "$ConDir2/tmp_sendVM.cdp" =A0 =A0or =
die "Cannot
> open '$ConDir2/tmp_sendVM.cdp' $!";
> =A0 =A0 =A0 =A0 =A0while ( <$IN> ) {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0s/ConDirFile/$dirVM$FILE/;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0print $OUT $_;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0 =A0 =A0close $OUT;
> =A0 =A0 =A0 =A0 =A0close $IN;
> =A0 =A0 =A0 =A0 =A0print "First Connect:Direct pre-processing step passed.=
..\n";
> =A0 =A0 =A0 =A0 =A0sleep 10;
> =A0 =A0 =A0 =A0 =A0print "Second Connect:Direct pre-processing step passed=
...\n";
> =A0 =A0 =A0 =A0 =A0system( $EXCONDIR ) =3D=3D 0 or errorexit( 2, "\nConnec=
t:Direct
> process failed" );
> =A0 =A0 =A0 =A0 =A0print "\nConnect:Direct processing for VIRGIN MOBILE cu=
stomer
> file completed...\n";
> =A0 =A0 =A0 =A0 =A0print $LOGFH "\nConnect:Direct Processed for $date $FIL=
E\n";
> =A0 =A0 =A0 =A0 =A0# Send email to notify file has been C:D to mainframe
> =A0 =A0 =A0 =A0 =A0my $subject =3D "Connect:Direct Processing VIRGIN MOBIL=
E: $FILE
> has been sent to VIRGIN MOBILE node VSCPFTP01";
> =A0 =A0 =A0 =A0 =A0my $body =3D <<BODY;
> =A0 Hello,
>
> =A0 $FILE has been moved from $machine to VSCPFTP01.
>
> =A0 Please contact $email2 with questions.
>
> =A0 Thanks,
>
> =A0 IOP Connect:Direct Team
>
> BODY
> =A0 =A0 =A0 =A0 =A0my $msg =3D MIME::Lite->new(
> =A0 =A0 =A0 =A0 =A0 =A0 =A0From =A0 =A0=3D> $email2,
> =A0 =A0 =A0 =A0 =A0 =A0 =A0To =A0 =A0 =A0=3D> $email,
> =A0 =A0 =A0 =A0 =A0 =A0 =A0Subject =3D> $subject,
> =A0 =A0 =A0 =A0 =A0 =A0 =A0Type =A0 =A0=3D> 'TEXT',
> =A0 =A0 =A0 =A0 =A0 =A0 =A0Data =A0 =A0=3D> $body,
> =A0 =A0 =A0 =A0 =A0 =A0 =A0);
> =A0 =A0 =A0 =A0 =A0#Use SMTP to send
> =A0 =A0 =A0 =A0 =A0MIME::Lite->send( 'smtp', $server, Timeout =3D> 60 );
> =A0 =A0 =A0 =A0 =A0sleep 30;
> =A0 =A0 =A0 =A0 =A0$msg->send;
> =A0 =A0 =A0 =A0 =A0print "\nEmail notification of Connect:Direct transfer =
sent...\n";
> =A0 =A0 =A0 =A0 =A0print "\n\n*******Waiting for VIRGIN MOBILE file proces=
sing to
> complete*******\n\n";
> =A0 =A0 =A0 =A0 =A0sleep 50;
> =A0 =A0 =A0 =A0 =A0# Rename the current process to done
> =A0 =A0 =A0 =A0 =A0print "File is writable\n" if -w "$dirVM/$FILE";
> =A0 =A0 =A0 =A0 =A0my $FILEDONE =3D $FILE . $doneExt;
> =A0 =A0 =A0 =A0 =A0print "filedone=3D$FILEDONE\n";
> =A0 =A0 =A0 =A0 =A0rename "$dirVM/$FILE", "$dirVM/$FILEDONE" or die "Canno=
t rename
> '$dirVM/$FILE' to '$dirVM/$FILEDONE' $!";
> =A0 =A0 =A0 =A0 =A0print "\nFile successfully renamed: $FILEDONE\n" or err=
orexit(
> 14, "Could not rename $FILE" );
> =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0continue {
> =A0 =A0 =A0 =A0 =A0print "\n\n*******Waiting for VIRGIN MOBILE Connect:Dir=
ect
> file*******\n\n";
> =A0 =A0 =A0 =A0 =A0sleep 10;
> =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0}
>
> #
> # Begin Subroutines
> #
>
> # Sub file_transfer_complete
> #
> # monitor a file for size changes over a brief period
> #
> # parm1 - file name
> # parm2 - delay in seconds (optional)
> #
> sub file_transfer_complete {
> =A0 =A0 =A0my $filename =3D shift;
> =A0 =A0 =A0my $waitTime =3D shift || 20;
> =A0 =A0 =A0my $sizefirst =3D -s $filename; =A0 =A0# initial file size
> =A0 =A0 =A0sleep $waitTime; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 # wait a while=
> =A0 =A0 =A0my $sizeDelta =3D -s $filename; =A0 =A0#file size after wait
> =A0 =A0 =A0if ( $sizeDelta =3D=3D $sizefirst ) {
> =A0 =A0 =A0 =A0 =A0print "transfer complete $filename 1: $sizefirst\t2: $s=
izeDelta";
> =A0 =A0 =A0 =A0 =A0return 1;
> =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0else {
> =A0 =A0 =A0 =A0 =A0print "transfer incomplete $filename 1: $sizefirst\t2: =
$sizeDelta";
> =A0 =A0 =A0 =A0 =A0return 0;
> =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0}
>
> # Sub errorexit print error message to the log and return an error code
> #
> sub errorexit {
> =A0 =A0 =A0my $returncode =3D shift;
> =A0 =A0 =A0my $message =A0 =A0=3D shift;
> =A0 =A0 =A0print $LOGFH "\n### ERROR $returncode ### $message";
> =A0 =A0 =A0exit $returncode;
> =A0 =A0 =A0}
>
> __END__
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where you
> can special-order certain sorts of tools at low cost and
> in short order. =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-- =
Larry Wall
Thanks for all of the thought and advice you have put into this
response. I will give it a try and see if I get anywhere. Since this
posting I have been testing with a number of different changes, all no
good so far.
Thanks again,
Karin Walike
------------------------------
Date: Wed, 9 Jan 2008 21:38:29 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: HELP! File Copy, Move and Rename will not work in my script!
Message-Id: <slrnfob4pl.ndu.tadmc@tadmc30.sbcglobal.net>
kwalike57 <karinwalike@comcast.net> wrote:
> Subject: HELP! File Copy, Move and Rename will not work in my script!
[ snip over 500 lines of quoted text ]
> Thanks for all of the thought and advice you have put into this
> response. I will give it a try and see if I get anywhere. Since this
> posting I have been testing with a number of different changes, all no
> good so far.
Did we really need to see the 500 lines that your 4 lines of new text
were referring to?
Have you seen the Posting Guidelines that are posted here frequently?
You should do that soon before your posts become widely invisible...
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Wed, 9 Jan 2008 20:47:54 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Search/Replace text in XML file
Message-Id: <slrnfob1qq.ndu.tadmc@tadmc30.sbcglobal.net>
Lax <lax_reddy@hotmail.com> wrote:
> #!/usr/local/bin/perl
>
> use strict ;
You should always enable warnings when developing Perl code:
use warnings;
> die "Usage: replace.pl <xml file>!\n" unless ( $#ARGV == 0 ) ;
That is more clearly written as:
die "Usage: replace.pl <xml file>!\n" unless @ARGV == 1;
> my $file = shift ;
>
> open(IN,"$file") or die "Cant open file: $!\n" ;
perldoc -q vars
What's wrong with always quoting "$vars"?
open(IN, $file) or die "Cant open file: $!\n" ;
(and nowadays you should use the 3-argument form of open() instead.)
> chomp(my @arr = <IN> ) ;
Here you remove the newline from every line, and below you add a
newline to every line.
Why remove them only to put them back?
> foreach my $line ( @arr )
If you are going to process the file line-by-line anyway, then why
bother reading the entire file into memory when one line at a time
in memory will work?
while ( my $line = <IN> )
> if ( $line =~ /^\s*\<(\/)?project/ )
The parenthesis in that pattern serve no purpose, so why include them?
Angle brackets are not special in regular expressions, so they
do not need backslashing.
If you choose some other delimiter for your match operator, then
the slash will not need backslashing either:
if ( $line =~ m#^\s*</?project# )
> I
> cant get this working when its extended over multiple-lines.
Then don't process the file line-by-line.
> Could anyone give me some pointers, please?
perldoc -q match
I'm having trouble matching over more than one line. What's wrong?
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Wed, 9 Jan 2008 20:35:34 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Search/Replace text in XML file
Message-Id: <slrnfob13m.ndu.tadmc@tadmc30.sbcglobal.net>
Lax <lax_reddy@hotmail.com> wrote:
> I'm trying to search and replace the value of a tag in an xml file.
No you're not.
You are trying to search and replace the value of an element in an xml file.
See the XML FAQ:
http://xml.silmaril.ie/authors/makeup/
> Sample xml file:
> -------------------------
>
><project xmlns="xml:header">
>
> <version>1.0.0</version>
>
> <SomeTag>
> <version>invalid version</version>
> </SomeTag>
>
>
> <SomeAnotherTagNested1>
> <SomeAnotherTagNested2>
> <SomeAnotherTagNested3>
> <version>invalid version</version>
> </SomeAnotherTagNested3>
> </SomeAnotherTagNested2>
> </SomeAnotherTagNested1>
>
> <version>stand-alone, but not valid either</version>
>
></project>
>
> -------------------------
>
> I only want the version tag when they're not enclosed in any other
> tags.
It is not legal in XML for a tag to enclose any other tag.
(tags start with a '<' and end with a '>')
You must have meant "element" where you said "tag".
In that case, there ARE NO version elements that are not enclosed
in any other elements!
> I want to replace the 1.0.0 (an example value) with 2.0.0
That element is enclosed in the project element.
> on an stand-
> alone "version"'s first occurence.
You want to replace the 1.0.0 with 2.0.0 on the first version element
that is a child of the document element (the project element in this case).
(in which case you have a poor example input, as a solution that
operates on the first <version> anywhere in the file will work
for that input...
)
> The above script works, and a "diff bak <xml-file>" gives me the
> expected result when the stand-alone <version> is all on one line, I
> cant get this working when its extended over multiple-lines.
Extended over multiple lines in what manner? Like this:
<version
>1.0.0</version>
or like
<version>
1.0.0</version>
or like
<version>
1.0.0
</version>
??
Those all are legal XML, but none of them are equivalent, they each
have different content.
> Could anyone give me some pointers, please?
If I could unambiguously figure out what you really want I probably could...
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Thu, 10 Jan 2008 04:39:10 GMT
From: still just me <wheeledBobNOSPAM@yahoo.com>
Subject: Sending HTML (MIME) email with Net::SMTP ?
Message-Id: <ir7bo3tkca6r77ku7ocnspk1cvqgvq0q2h@4ax.com>
I'm trying to send HTML email (email with a MIME header) using
Net::SMTP in my code. (Hopefully eventually sending multipart
text/plain and text/HTML).
I've been sending plain text email with the code below in quite a few
programs... works fine. But, I am having trouble figuring out how to
send MIME email. I thought that if the headers appeared first in the
body section that it would work but that was a flop - it all shows up
as the body of the message.
I could use some help, or pointers. I could not find anything specific
in perldoc on this... perhaps I need to use another module to generate
MIME headers? I'd like to avoid changing modules if I can since
Net::SMTP seems to work well otherwise.
Thanks,
------------------------------
Date: Thu, 10 Jan 2008 04:48:41 GMT
From: still just me <wheeledBobNOSPAM@yahoo.com>
Subject: Re: Sending HTML (MIME) email with Net::SMTP ?
Message-Id: <sr8bo3loedia3q46e2g7dgtheve2638upr@4ax.com>
Forgot the snippet. Here's the code I normally use:
my $smtp = Net::SMTP->new('localhost');
die "Could not open connection: $!" if (! defined $smtp);
$smtp->mail($from);
$smtp->to($to);
$smtp->data();
$smtp->datasend("To: $to\n");
$smtp->datasend("From: $from\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("\n");
$smtp->datasend("$body\n");
$smtp->dataend();
$smtp->quit;
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 1184
***************************************