Send Perl-Win32-Users mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
or, via email, send a message with subject or body 'help' to
[EMAIL PROTECTED]
You can reach the person managing the list at
[EMAIL PROTECTED]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Perl-Win32-Users digest..."
Today's Topics:
1. Re: How to best replace one string with another in a text
file (Lyle Kopnicky)
2. Re: How to best replace one string with another in a text
file (Lyle Kopnicky)
3. Re: Document flow (Alejandro Santillan)
4. PPM object interface? (Lyle Kopnicky)
5. [PMX:VIRUS] Re: (liberall2004)
6. Fw: How to best replace one string with another in a text
file (D D Allen)
7. Net::SMTP::Multipart and multiple recipients (Erich Beyrent)
8. [PMX:VIRUS] Re: Net::FTP capture Debug output (liberall2004)
9. Re: Fw: How to best replace one string with another in a text
file (Lyle Kopnicky)
----------------------------------------------------------------------
Message: 1
Date: Tue, 28 Feb 2006 11:54:26 -0800
From: Lyle Kopnicky <[EMAIL PROTECTED]>
Subject: Re: How to best replace one string with another in a text
file
To: Paul Rousseau <[EMAIL PROTECTED]>
Cc: [email protected]
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Paul,
Here's an even more frighteningly succinct version of your loop, without
the intermediate variable:
print OUTFILE map { s/$oldnodename/$currnodename/g; $_ } <INFILE>;
--
Lyle Kopnicky
Software Project Engineer
Veicon Technology, Inc.
------------------------------
Message: 2
Date: Tue, 28 Feb 2006 12:23:34 -0800
From: Lyle Kopnicky <[EMAIL PROTECTED]>
Subject: Re: How to best replace one string with another in a text
file
To: Paul Rousseau <[EMAIL PROTECTED]>
Cc: [email protected]
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Another option which occurred to me - there's no reason to replace text
line-by-line here. You could write:
$text = <INFILE>;
$text ~- s/$oldnodename/$curnodename/g;
print OUTFILE $text;
Although I agree with Alejandro... if your file is gigabyte-sized, you
will probably want to go back to the while loop. But that' s more of a
limitation of the operating system than of your program. I mean, it's
supposed to be caching reads and writes, no?
--
Lyle Kopnicky
Software Project Engineer
Veicon Technology, Inc.
------------------------------
Message: 3
Date: Tue, 28 Feb 2006 17:57:08 -0300
From: "Alejandro Santillan" <[EMAIL PROTECTED]>
Subject: Re: Document flow
To: <[email protected]>, "Johan Lindstrom"
<[EMAIL PROTECTED]>
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset="iso-8859-1"
I mean a workflow that involves the treatment of a document, i.e. a system
that can register
the reception of a document and a register the sucessive changes and logs
the depts where it suffered the changes.
Maybe Workflow-0.17 could help.
Thank you
Alejandro
----- Original Message -----
From: "Johan Lindstrom" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Tuesday, February 28, 2006 4:17 PM
Subject: Re: Document flow
At 19:31 2006-02-28, Alejandro Santillan Iturres wrote:
Anyone know about a perl module for document flow management?
Not sure what you mean by _document_ flow, but perhaps this?
http://search.cpan.org/~cwinters/Workflow-0.17/
/J
-------- ------ ---- --- -- -- -- - - - - -
Johan Lindström Sourcerer @ Boss Casinos johanl AT DarSerMan.com
Latest bookmark: "TCP Connection Passing"
http://tcpcp.sourceforge.net/
dmoz: /Computers/Programming/Languages/JavaScript/ 12
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
------------------------------
Message: 4
Date: Tue, 28 Feb 2006 19:00:22 -0800
From: Lyle Kopnicky <[EMAIL PROTECTED]>
Subject: PPM object interface?
To: perl-win32-users <[email protected]>
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Hi folks,
I know how to use PPM from the command line, but I want to call it from
Perl, preferably without spawning separate processes. There seems to be
a PPM3 module installed in ActivePerl, but how do I access it? E.g., I
would like to write something like:
use PPM;
my $ppm = new PPM;
$ppm->install('http://blahblah.net/Package.ppd') or die "Failed to
install package.";
my @search_packages = $ppm->search('FunPackage');
print (map "$_->name\n", @search_packages);
--
Lyle Kopnicky
Software Project Engineer
Veicon Technology, Inc.
------------------------------
Message: 5
Date: Wed, 1 Mar 2006 05:51:19 -0800 (PST)
From: "liberall2004" <[EMAIL PROTECTED]>
Subject: [PMX:VIRUS] Re:
To: <[email protected]>
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset="utf-8"
An HTML attachment was scrubbed...
URL:
http://ASPN.ActiveState.com/ASPN/Mail/Browse/Threaded/perl-win32-users/attachments/20060301/5bd17347/attachment-0001.htm
-------------- next part --------------
The original content of this message part has been replaced
by this text because it tested positive for the following
virus(es):
W32/Nyxem-D, W32/Nyxem-D
The original message has been quarantined pending further
action by the mail administrator. For further information
about the message and its delivery status, please contact
the undersigned, and include the full content of this
message. The identifier for this message is
'k21DpPGO010748'.
This notification is being sent to you and any other
original envelope recipient(s). To avoid creating a
nuisance and to keep mail traffic under control, the
original sender of the message has NOT been notified.
However, you may want to notify the sender at your
discretion.
The Management
PureMessage Admin <[EMAIL PROTECTED]>
------------------------------
Message: 6
Date: Wed, 1 Mar 2006 08:11:25 -0500
From: D D Allen <[EMAIL PROTECTED]>
Subject: Fw: How to best replace one string with another in a text
file
To: Paul Rousseau <[EMAIL PROTECTED]>
Cc: [email protected]
Message-ID:
<[EMAIL PROTECTED]>
Content-Type: text/plain; charset="us-ascii"
For yucks, I tested three variations (in separate scripts) of replacing
one string with another in a text file -- that contained ~16,100 lines --
replacing 190 occurrences of the target string. The three variations are
shown below. Time::HiRes ( gettimeofday tv_interval ) was used in the
body of each script to time each run -- and each script was run 5 times
intermixed with the others. Run on a laptop running MS Windows XP and
ActiveState Perl 5.8.7 build 815.
I think what's going on is that for variations 1 and 3, Perl is "slurping"
the input file into an array, performing the substitutions on the array
elements, and then writing out the array elements. For variation 2,
there's no array involved. It's simply "read a line, perform the
substitution on that line, write a line". And I think the explanation
for the time differences between 1 and 3 is that there is a certain amount
of overhead associated with the map function -- that's not present with
the for loop.
And looking at this from the perspective of "Perl Best Practices" by
Damian Conway (well worth reading)...
(1) Note the use of indirect file handle variables instead of bareword
file handles (page 202 :-).
(2) Not shown in the variation examples but used in the test scripts is
the 3 argument form of open (page 207) as in the following.
open (my $outfile, '>', 'testout.txt') or die "could not open outfile $!";
(3) Shown in variation 2 is avoid modification of "$_" (page 85).
(4) Demonstrated by the slight time advantage of variation 2 over
variation 3, "use while (<>), not for (<>)" for input loops (page 211).
So other than the problematic "chomp", your original while loop is best
from both a runtime and a Perl Best Practices perspective.
Regards,
... Dewey
Variation 1 - map - in one statement
print {$outfile} map { s/$oldval/$newval/g; $_ } <$infile>;
Variation 2 - while loop "line at a time"
while (my $line = <$infile>) {
$line =~ s/$oldval/$newval/g;
print {$outfile} $line;
}
Variation 3 - for loop - with no intermediate variable
for (<$infile>) {
$_ =~ s/$oldval/$newval/g;
print {$outfile} $_;
}
The elapsed times are as follows.
Variation 1 - map - in one statement
Elapsed time: 0.186486
Elapsed time: 0.192088
Elapsed time: 0.180844
Elapsed time: 0.179598
Elapsed time: 0.214627
Variation 2 - while loop "line at a time"
Elapsed time: 0.077885
Elapsed time: 0.078739
Elapsed time: 0.073292
Elapsed time: 0.076311
Elapsed time: 0.085483
Variation 3 - for loop - with no intermediate variable
Elapsed time: 0.109979
Elapsed time: 0.119098
Elapsed time: 0.110375
Elapsed time: 0.111947
Elapsed time: 0.117261
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://ASPN.ActiveState.com/ASPN/Mail/Browse/Threaded/perl-win32-users/attachments/20060301/1c43a5b6/attachment-0001.htm
------------------------------
Message: 7
Date: Wed, 01 Mar 2006 10:20:15 -0500
From: Erich Beyrent <[EMAIL PROTECTED]>
Subject: Net::SMTP::Multipart and multiple recipients
To: [email protected]
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
I am trying to use Net::SMTP::Multipart to send email to multiple
recipients, and per the module documentation, I am specifying multiple
addresses in an anonymous array:
$smtp->Header(To => ["[EMAIL PROTECTED]", "[EMAIL PROTECTED],"],
Subj => "Test Message",
From => "[EMAIL PROTECTED]");
I get the following error though:
Can't coerce array into hash at /perl/lib/Net/SMTP.pm line 364
Any advice?
--
Erich Beyrent
--------------------------
http://www.beyrent.net
------------------------------
Message: 8
Date: Wed, 1 Mar 2006 08:18:40 -0800 (PST)
From: "liberall2004" <[EMAIL PROTECTED]>
Subject: [PMX:VIRUS] Re: Net::FTP capture Debug output
To: <[email protected]>
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset="utf-8"
An HTML attachment was scrubbed...
URL:
http://ASPN.ActiveState.com/ASPN/Mail/Browse/Threaded/perl-win32-users/attachments/20060301/9a5972e0/attachment-0001.htm
-------------- next part --------------
The original content of this message part has been replaced
by this text because it tested positive for the following
virus(es):
W32/Nyxem-D, W32/Nyxem-D
The original message has been quarantined pending further
action by the mail administrator. For further information
about the message and its delivery status, please contact
the undersigned, and include the full content of this
message. The identifier for this message is
'k21GIj5I026831'.
This notification is being sent to you and any other
original envelope recipient(s). To avoid creating a
nuisance and to keep mail traffic under control, the
original sender of the message has NOT been notified.
However, you may want to notify the sender at your
discretion.
The Management
PureMessage Admin <[EMAIL PROTECTED]>
------------------------------
Message: 9
Date: Wed, 01 Mar 2006 10:46:30 -0800
From: Lyle Kopnicky <[EMAIL PROTECTED]>
Subject: Re: Fw: How to best replace one string with another in a text
file
To: D D Allen <[EMAIL PROTECTED]>
Cc: [email protected]
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset="iso-8859-1"
D D Allen wrote:
I think what's going on is that for variations 1 and 3, Perl is
"slurping" the input file into an array, performing the substitutions
on the array elements, and then writing out the array elements. For
variation 2, there's no array involved. It's simply "read a line,
perform the substitution on that line, write a line". And I think
the explanation for the time differences between 1 and 3 is that there
is a certain amount of overhead associated with the map function --
that's not present with the for loop.
Thanks for your informative test. When we make decisions about how to
code something, it is important to consider what factors are most
important in our situation. Sometimes, speed will be critical. At
other times, conceptual clarity of the code, for ease of maintenance,
will be of highest concern. Most of the time we choose a balance.
Personally, I find that if speed is not critical (and if it is, you
should be using something faster than current Perl implementations), I
want to emphasize conceptual clarity.
I feel that in the long run, it is best to write clearer code, unless
the performance penalty is overwhelming. Understand that future
versions of Perl may be optimized to handle some things more
efficiently, e.g. map. If more people used it, there would be more
incentive for Wall et al to optimize for it.
One issue that arises in designing for clarity in the code is that
different developers are used to different idioms. So, what is clear
and simple to me may seem obtuse to a future maintainer, and
vice-versa. Many of the practices in the Best Practices book seem
strange to many Perl developers, but Conway suggests that if we would
all get used to them, we'd be happier in the long run. It is in that
spirit that I prefer the three-line map solution to the while loop:
my @lines = <$infile>;
map { s/$oldval/$newval/g; $_ } @lines;
print {$outfile} @lines;
It conceptually separates I/O from computations. It is also more
declarative - saying what you want rather than how to do it. Some
programmers may find it less familiar than while loops, but I think that
is only because they have been taught to use while loops. If you start
a new programmer from scratch, my bet is they'll find the map solution
conceptually simpler. Granted, I have a functional programming
background, so I'm apt to say such things.
Anyway, despite the fact that the map solution is simpler than the while
loop, there is yet a simpler solution to this problem, which I mentioned
earlier. It involves sucking in the entire file and doing substitutions
on it. There is no need to impose the conceptual framework of
line-based processing. It might even be faster. I'm eager to find out.
Here is the variant I suggest you test:
use File::Slurp;
...
my $text = read_file($input_file, binmode => ':raw');
$text =~ s/$oldval/$newval/g;
print {$outfile} $text;
(I know Conway suggests using Perl6::Slurp, but I couldn't find a PPM
for it, so I used File::Slurp. Admittedly, the binmode => ':raw' is a
bit obtuse, and could be left out. I do think it will boost performance
slightly, which I am curious about in the context of this discussion.)
--
Lyle Kopnicky
Software Project Engineer
Veicon Technology, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://ASPN.ActiveState.com/ASPN/Mail/Browse/Threaded/perl-win32-users/attachments/20060301/c5df1224/attachment-0001.htm
------------------------------
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
End of Perl-Win32-Users Digest, Vol 26, Issue 1
***********************************************