[11169] in Perl-Users-Digest
Perl-Users Digest, Issue: 4769 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 28 15:07:28 1999
Date: Thu, 28 Jan 99 12:00:24 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 28 Jan 1999 Volume: 8 Number: 4769
Today's topics:
Re: Cannot evaluate $query->param('thing') (peter)
Re: Cannot evaluate $query->param('thing') (I R A Aggie)
Changing drives with ActiveState Perl on NT (Phil Tomson)
Re: Checking for flock (M.J.T. Guy)
Re: Checking for flock (M.J.T. Guy)
convert awk to perl Matching in Perl not like awk it se <charlesjourdan@worldnet.att.net>
Re: Difficult issues not suitable for this newsgroup? (Mark Leighton Fisher)
Good CGI Book <trenic@nortelnetworks.ca>
Re: Gosh, s// faster than m// (was Re: Counting charact (Brand Hilton)
Re: HELP with string parsing and scoring (Larry Rosler)
Re: HELP with string parsing and scoring <jeromeo@atrieva.com>
Re: HELP with string parsing and scoring <ludlow@us.ibm.com>
Re: HELP with string parsing and scoring (Larry Rosler)
Re: HELP with string parsing and scoring <jeromeo@atrieva.com>
Re: HELP with string parsing and scoring <dgris@moiraine.dimensional.com>
Re: HELP with string parsing and scoring <jeromeo@atrieva.com>
Re: HELP with string parsing and scoring <jeromeo@atrieva.com>
How do I add an attachment to an e-mail? <vpatricio@abrantina.pt>
Re: How do I add an attachment to an e-mail? (Dan Wilga)
Re: Jesus Rides a HOG(tm) : was :CONCLUSIVE PROOF: The (Ears)
Re: Learning perl (Larry Rosler)
Re: Learning perl <michael_mongeau@stratus.com>
Re: need a little socket help <bsmith@perf.zko.dec.com>
Re: pattern matching (Greg Ward)
Perl DLL <dcraig@ismd.ups.com>
Re: Perl Question (Larry Rosler)
Question Serial port programming kos@tdd.hbo.nec.com
Re: Reading headers & LWP (Bill Moseley)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 28 Jan 1999 18:25:09 GMT
From: pdroogma@netscape.net (peter)
Subject: Re: Cannot evaluate $query->param('thing')
Message-Id: <36b0ab46.39167379@192.168.0.1>
Hello,
Just don't use the quotes around $x and everything will just work as you expect.
Peter
On 28 Jan 1999 09:07:43 GMT, "Charles R. Thompson" <design@raincloud-studios.com> wrote:
>I swore I wouldn't come here until I had what I thought wasn't a
>dumb question. :) So...
>
>I've been converting a script that used cgi-lib.pl to CGI.pm and
>all was going well until one of my conversions created this...
>
>foreach $x(@form_vars){
> if ($query->param('$x') eq "" || $query->param('$x') =~ /\|/) {
> &NoValidValues();
> exit;
> }
>#<snip> other stuff unrelated
>}
>
>The loop fetches the values of params named in @form_vars. I
>have quadruple checked the values and they ARE there... However,
>the if line does not seem to be evaluating $query->param('$x')
>to anything valid. I realize I could put $query->param('$x')
>into a scalar then evaluate it...
>
>$test_val = $query->param('$x');
>
>but I think there is a better way in this case and I'm left I'm
>wondering 2 things..
>
>1) Why doesn't it work in the first place?
>2) Am I missing some clever way of handling this in the if
>statement other than using a scalar?
>
>Thanks..
>
>CT
>
------------------------------
Date: Thu, 28 Jan 1999 14:03:28 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Cannot evaluate $query->param('thing')
Message-Id: <fl_aggie-2801991403280001@aggie.coaps.fsu.edu>
In article <78p9cv$nqa@bgtnsc02.worldnet.att.net>, "Charles R. Thompson"
<design@raincloud-studios.com> wrote:
+ I've been converting a script that used cgi-lib.pl to CGI.pm and
That's very simple to do. Just add:
use CGI qw(:cgi-lib);
in place of the cgi-lib.pl, and you're done.
James
------------------------------
Date: 28 Jan 1999 11:44:09 -0800
From: ptkwt@user1.teleport.com (Phil Tomson)
Subject: Changing drives with ActiveState Perl on NT
Message-Id: <78qem9$lbc$1@user1.teleport.com>
This seems like it should be an easy thing to do, but as usual there seem
to be those things on Windows where you 'can't get there from here'...
I want a perl script that is running on NT to change to a different drive
and directory and then do stuff there. On unix this isn't a problems
since drives and directories are kind of the same thing...
chdir('F:\somedir') won't work if I'm running the script on drive c: - the
working directory is still going to be the one I'm in on drive c:. I
tried doing something like system('F:') in order to get F: to be the
current working drive, but it doesn't work either (not that I had a lot of
hope that it would). I suspect that there must be some simple way to do
this, any ideas?
Phil
--
Phil Tomson
FreeHDL Project
http://www.freehdl.seul.org/
------------------------------
Date: 28 Jan 1999 18:02:16 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Checking for flock
Message-Id: <78q8n8$dir$1@pegasus.csx.cam.ac.uk>
Jeff Zucker <jeff@vpservices.com> wrote:
>Is there a better way to check if flock is implemented on a machine than
>this subroutine?
Do you mean "has this platform got flock(2)" or "has this platform
some emulation of flock()" ? If the former, look at d_flock and d_lockf
in Config.pm. But I'll assume you mean the latter.
>sub has_flock {
> my $flock_status = 1;
> open(FH,$0) || die $!;
> undef $@;
> eval( "flock(FH,8)" );
> if ( $@ =~ /unimplemented/ ) { $flock_status = 0; }
> close(FH) || die $!;
> return $flock_status;
>}
All you need is to do a call of flock(). flock() should die only if it
isn't implemented. All other errors just give a false return value.
So this should be sufficient (untested - I don't have a platform without
flock):
sub has_flock {
eval { flock 0, 0 };
return ! $@;
};
(Note that it's almost always better to use eval{} rather than eval(""). )
Or you may wish to do the work at compile time:
use constant HAS_FLOCK => ! eval { flock 0, 0; 1 };
Mike Guy
------------------------------
Date: 28 Jan 1999 18:11:45 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Checking for flock
Message-Id: <78q991$dss$1@pegasus.csx.cam.ac.uk>
M.J.T. Guy <mjtg@cus.cam.ac.uk> wrote:
>
>use constant HAS_FLOCK => ! eval { flock 0, 0; 1 };
^
Oops. That's back to front. Cut the '!'.
Mike Guy
------------------------------
Date: 28 Jan 1999 18:29:46 GMT
From: "sysadmin" <charlesjourdan@worldnet.att.net>
Subject: convert awk to perl Matching in Perl not like awk it seems
Message-Id: <78qaaq$f2b@bgtnsc02.worldnet.att.net>
I am having a hell of a time getting a match for a block
I have thousands of lines in the format
C206130 002 1 C9BARON0 KIDGLASS TRUFFLE
1
C206130 002 2 040045050055060065070075080085090095100105110120000
990225990107 0102 0002842010
C206130 002 3 AA 000000000000000000000000000000000000000000000000000
C206130 002 4 B 000001002002003003003002001001000000000000000000000
C206130 002 5 000000000000000000000000000000000000000000000000000
C206130 002 6 000000000000000000000000000000000000000000000000000
C206130 002 7 000000000000000000000000000000000000000000000000000
C206130 003 1 C9BARON0 KIDGLASS ANTHRACITE
1
C206130 003 2 040045050055060065070075080085090095100105110120000
990225990107 0102 0002842012
C206130 003 3 AA 000000000000000000000000000000000000000000000000000
C206130 003 4 B 000000001002002002002001001001000000000000000000000
C206130 003 5 000000000000000000000000000000000000000000000000000
C206130 003 6 000000000000000000000000000000000000000000000000000
C206130 003 7 000000000000000000000000000000000000000000000000000
As can be seen, the block begins consistently with a regexp pattern that I
think could be
/[a-zA-Z][0-9]+ [0-9][0-9][0-9] [a-zA-Z][0-9]+[a-zA-Z][0-9]+ [a-zA-Z]+ */
I then want to identify the block number (arg2 '002' or '003'), read the
quantities below line 2 in the block, and then add to a sum and go to the
next block.
The math part is ok
But I am not mathcing every line containing quantities
I had an awk script and would like it now to run in Perl if it would be
better
The perl code I have so far for the match is
while (<$line>) {
#$3 =~ /\d/ ;
#if ($1 =~ /\b^C\d+/) {
#if ($1 =~ /\bC206\d+/) {
#if ($line =~ (/C206130/)) {
if($line =~ /C206130/) {
print $line;
}
}
--
===========================================
Opinions my own and not representative of my employer
Do not listen to me: I have brain damage
===========================================
------------------------------
Date: Thu, 28 Jan 1999 14:55:32 -0500
From: fisherm@tce.com (Mark Leighton Fisher)
Subject: Re: Difficult issues not suitable for this newsgroup?
Message-Id: <MPG.111a8ac0568a8e3e9896a4@news-indy.indy.tce.com>
In article <m1pv839h6h.fsf@halfdome.holdit.com>, merlyn@stonehenge.com
says...
> Bingo! I was wondering if that meme would trigger anyone else!
>
> "Send it to ZOOM! Zee Double-Oh Em, box three five oh, boston mass,
> ooooohhhh, two ooonnnnee, three FOUUUURRR!"
>
> Makes me wonder who has that box now, and if they still get Zoom-do
> suggestions twenty years later. :)
Better/worse yet, PBS just re-incarnated Zoom, even using the old theme
song:
"Come on and Zoom, come on and Zoom, come on and Zooma-Zooma-Zooma-Zoom!"
[our daughter doesn't mention it much, so it's not a favorite of one six-
year-old...]
==========================================================
Mark Leighton Fisher Thomson Consumer Electronics
fisherm@indy.tce.com Indianapolis, IN
"Browser Torture Specialist, First Class"
------------------------------
Date: Thu, 28 Jan 1999 13:41:41 -0500
From: Tom Renic <trenic@nortelnetworks.ca>
Subject: Good CGI Book
Message-Id: <36B0AF65.4276804C@nortelnetworks.ca>
Can anyone suggest a very good CGI Textbook that is a good
starting point for a beginner, yet can act as a good desk reference
for an experience programmer?
------------------------------
Date: 28 Jan 1999 18:59:49 GMT
From: bhilton@tsg.adc.com (Brand Hilton)
Subject: Re: Gosh, s// faster than m// (was Re: Counting characters with tr/// (in perl))
Message-Id: <78qc35$f1g1@mercury.adc.com>
In article <78odk5$j5m$1@mathserv.mps.ohio-state.edu>,
Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
>
>Though some systems have pretty good malloc()s. Say, Linux malloc()
>is reported to be only 50% slower and only 5% more wasteful than
>Perl's one.
Now I'm curious. Why is it that, when running Configure, the default
is to NOT use Perl's malloc?
--
_____
|/// | Brand Hilton bhilton@adc.com
| ADC| ADC Telecommunications, ATM Transport Division
|_____| Richardson, Texas
------------------------------
Date: Thu, 28 Jan 1999 09:54:43 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: HELP with string parsing and scoring
Message-Id: <MPG.111a4442ddf8701d9899d6@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <36B08F79.AC7E36A6@atrieva.com> on Thu, 28 Jan 1999 08:25:29
-0800, Jerome O'Neil <jeromeo@atrieva.com> says...
...
> #!/usr/local/bin/perl
> use Benchmark;
>
> my $string = 'TO SPLIT IS HUMAN, SUBSTR - DEVINE!';
>
> timethese(100000,{
>
> 'SP' => sub {my @array1 = split(//,$string);},
> 'WH' => sub{
my $i = 0;
my @array2;
> while($char = substr($string,$i++,1)){
> push @array2, $char;
> }
> }
> }
> );
>
> Benchmark: timing 100000 iterations of SP, WH...
> SP: 118 wallclock secs (70.38 usr + 0.02 sys = 70.40 CPU)
> WH: 8 wallclock secs ( 5.22 usr + 0.01 sys = 5.23 CPU)
>
> Using split is realy not the most efficient way to initialize an array
> in this manner. Without knowing what goes on under the hood as far as
> optimizations go, I'd wager that compiling the regex is what makes it
> more expensive.
Sorry, but you blew this one big-time! Even benchmarks should be run
with '-w', which would have told you right away what the problems were.
('use strict;' is a bit more problematic for benchmarks, though.)
When corrected for the fact that most of the substr accesses are out of
range, and avoiding pushing all the results onto the same array (see the
inserted lines above), I get this:
Benchmark: timing 100000 iterations of SP, WH...
SP: 27 wallclock secs (28.36 usr + 0.00 sys = 28.36 CPU)
WH: 36 wallclock secs (36.64 usr + 0.00 sys = 36.64 CPU)
That makes a whole lot more sense to me, because 'SP' does most of its
work in C code, while 'WH' does most of its work interpreting several
perl ops.
So simplicity and cleanliness triumph, for a change!
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 28 Jan 1999 09:56:39 -0800
From: Jerome O'Neil <jeromeo@atrieva.com>
To: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: HELP with string parsing and scoring
Message-Id: <36B0A4D7.742F9BAD@atrieva.com>
Jonathan Feinberg wrote:
>
> Jerome O'Neil <jeromeo@atrieva.com> writes:
>
> > 'WH' => sub{
> > while($char = substr($string,$i++,1)){
> > push @array2, $char;
> > }
>
> This will fail if there's a 0 in the string.
>
> while (defined $char = substr...
It's more an example of efficiency, but you're right. So, the "safe"
substr() benchmarks are...
Benchmark: timing 100000 iterations of SP, WH...
SP: 117 wallclock secs (69.69 usr + 0.03 sys = 69.72 CPU)
WH: 10 wallclock secs ( 5.57 usr + 0.00 sys = 5.57 CPU)
--
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947
The Atrieva Service: Safe and Easy Online Backup http://www.atrieva.com
------------------------------
Date: Thu, 28 Jan 1999 12:27:46 -0600
From: James Ludlow <ludlow@us.ibm.com>
Subject: Re: HELP with string parsing and scoring
Message-Id: <36B0AC22.61907DDD@us.ibm.com>
Jerome O'Neil wrote:
> Observe:
>
> #!/usr/local/bin/perl
> use Benchmark;
>
> my $string = 'TO SPLIT IS HUMAN, SUBSTR - DEVINE!';
>
> timethese(100000,{
>
> 'SP' => sub {my @array1 = split(//,$string);},
> 'WH' => sub{
> while($char = substr($string,$i++,1)){
> push @array2, $char;
> }
> }
> }
> );
If you were using -w, you'd see that your code doesn't work the way you
think it does. The reason your while loop seems to run so quickly is
that after the first iteration of timethese, $i is going to be out of
the range of the string length. The code inside your while loop will
not execute.
> Benchmark: timing 100000 iterations of SP, WH...
> SP: 118 wallclock secs (70.38 usr + 0.02 sys = 70.40 CPU)
> WH: 8 wallclock secs ( 5.22 usr + 0.01 sys = 5.23 CPU)
This should be 'split' vs 'failing a while loop condition 99999 times'
--
James Ludlow (ludlow@us.ibm.com)
(Any opinions expressed are my own, not necessarily those of IBM)
------------------------------
Date: Thu, 28 Jan 1999 10:34:49 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: HELP with string parsing and scoring
Message-Id: <MPG.111a4da2193840469899d8@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <36B0A4D7.742F9BAD@atrieva.com> on Thu, 28 Jan 1999 09:56:39
-0800, Jerome O'Neil <jeromeo@atrieva.com> says...
> Jonathan Feinberg wrote:
> >
> > Jerome O'Neil <jeromeo@atrieva.com> writes:
> >
> > > 'WH' => sub{
> > > while($char = substr($string,$i++,1)){
> > > push @array2, $char;
> > > }
> >
> > This will fail if there's a 0 in the string.
> >
> > while (defined $char = substr...
>
> It's more an example of efficiency, but you're right. So, the "safe"
> substr() benchmarks are...
>
> Benchmark: timing 100000 iterations of SP, WH...
> SP: 117 wallclock secs (69.69 usr + 0.03 sys = 69.72 CPU)
> WH: 10 wallclock secs ( 5.57 usr + 0.00 sys = 5.57 CPU)
No they're not. See my other post. I usually test benchmark code by
printing the output and running the benchmark once. In this case, the
error would have shown up only if you ran the benchmark twice or more.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 28 Jan 1999 10:32:54 -0800
From: Jerome O'Neil <jeromeo@atrieva.com>
To: Larry Rosler <lr@hpl.hp.com>
Subject: Re: HELP with string parsing and scoring
Message-Id: <36B0AD56.5F1897C8@atrieva.com>
Larry Rosler wrote:
>
> [Posted and a courtesy copy mailed.]
> > Using split is realy not the most efficient way to initialize an array
> > in this manner. Without knowing what goes on under the hood as far as
> > optimizations go, I'd wager that compiling the regex is what makes it
> > more expensive.
>
> Sorry, but you blew this one big-time! Even benchmarks should be run
> with '-w', which would have told you right away what the problems were.
> ('use strict;' is a bit more problematic for benchmarks, though.)
Sorry, Larry, but I'm right. The additional cycles in your benchmarks
are a result of the additional assignments. Here is a version that runs
clean with warnings, accounts for a '0' in the string, and still smokes
split() by an order of magnitude (I think that's the right term, but I'm
not a math guy.)
#!/usr/local/bin/perl -w
use Benchmark;
my $string = 'TO SPLIT IS HUMAN, SUBSTR - DEVINE!';
my $i = 0;
my($char, @array1, @array2) = ();
timethese(100000,{
'SP' => sub {my @array1 = split(//,$string);},
'WH' => sub{
while($i < length $string && defined( $char =
substr($string,$i++,1) )){
push @array2, $char;
}
}
}
);
Benchmark: timing 100000 iterations of SP, WH...
SP: 118 wallclock secs (70.06 usr + 0.04 sys = 70.10 CPU)
WH: 6 wallclock secs ( 3.52 usr + 0.00 sys = 3.52 CPU)
> So simplicity and cleanliness triumph, for a change!
Like the '72 Olympic Basketball Team!
--
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947
The Atrieva Service: Safe and Easy Online Backup http://www.atrieva.com
------------------------------
Date: 28 Jan 1999 12:06:56 -0700
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: HELP with string parsing and scoring
Message-Id: <m33e4vjjxr.fsf@moiraine.dimensional.com>
Jerome O'Neil <jeromeo@atrieva.com> writes:
> Sorry, Larry, but I'm right. The additional cycles in your benchmarks
> are a result of the additional assignments.
No, the additional cycles in Larry's example are the result of actually
doing some work in the while loop. Your benchmark is completely invalid.
> Here is a version that runs
> clean with warnings, accounts for a '0' in the string, and still smokes
> split() by an order of magnitude (I think that's the right term, but I'm
> not a math guy.)
Well, of course it smokes split. The split code is executed 100000
times while the while code is only executed once. Here's a version
that demonstrates exactly how your benchmark is broken (all I did was
add a print statement to your version, note that I've wrapped the long
output line to make it easier to read).
[dgris@moiraine dgris]$ perl
use Benchmark;
my $string = 'TO SPLIT IS HUMAN, SUBSTR - DEVINE!';
my $i = 0;
my($char, @array1, @array2) = ();
timethese(100000,{
'SP' => sub {my @array1 = split(//,$string);},
'WH' => sub {
while($i < length $string &&
defined( $char = substr ($string, $i++, 1) )) {
push @array2, $char;
print $i;
}
}
}
);
__END__
Benchmark: timing 100000 iterations of SP, WH...
SP: 82 wallclock secs (67.67 usr + 1.75 sys = 69.42 CPU)
1234567891011121314151617181920212223242526272829303132333435
WH: 5 wallclock secs ( 3.17 usr + 0.05 sys = 3.22 CPU)
[dgris@moiraine dgris]$
See, it only executes the code inside of WH once. After that your
global variable has already been incremented high enough that the
conditional always tests false. Split is very certainly faster than
while for this as other benchmarks have demonstrated.
dgris
--
Daniel Grisinger dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'
------------------------------
Date: Thu, 28 Jan 1999 10:56:23 -0800
From: Jerome O'Neil <jeromeo@atrieva.com>
To: Larry Rosler <lr@hpl.hp.com>
Subject: Re: HELP with string parsing and scoring
Message-Id: <36B0B2D7.266D8EC5@atrieva.com>
Larry Rosler wrote:
> > It's more an example of efficiency, but you're right. So, the "safe"
> > substr() benchmarks are...
> >
> > Benchmark: timing 100000 iterations of SP, WH...
> > SP: 117 wallclock secs (69.69 usr + 0.03 sys = 69.72 CPU)
> > WH: 10 wallclock secs ( 5.57 usr + 0.00 sys = 5.57 CPU)
>
> No they're not. See my other post. I usually test benchmark code by
> printing the output and running the benchmark once. In this case, the
> error would have shown up only if you ran the benchmark twice or more.
Yes, they are. See my response to your other post. I have run this
particular benchmark a number of times, mostly as another example of why
MTOWTDI is a Good Thing. Effiecincy vs. Readability & Development time.
I'll restate myself. There may be more efficent ways to do this, but
using split isn't one of them.
--
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947
The Atrieva Service: Safe and Easy Online Backup http://www.atrieva.com
------------------------------
Date: Thu, 28 Jan 1999 11:01:19 -0800
From: Jerome O'Neil <jeromeo@atrieva.com>
To: James Ludlow <ludlow@us.ibm.com>
Subject: Re: HELP with string parsing and scoring
Message-Id: <36B0B3FF.64BCE4B7@atrieva.com>
James Ludlow wrote:
>
> Jerome O'Neil wrote:
> If you were using -w, you'd see that your code doesn't work the way you
> think it does. The reason your while loop seems to run so quickly is
> that after the first iteration of timethese, $i is going to be out of
> the range of the string length. The code inside your while loop will
> not execute.
>
> > Benchmark: timing 100000 iterations of SP, WH...
> > SP: 118 wallclock secs (70.38 usr + 0.02 sys = 70.40 CPU)
> > WH: 8 wallclock secs ( 5.22 usr + 0.01 sys = 5.23 CPU)
>
I have posted a clean warning version that is still faster than using
split. Split is an expensive function compared to substr, even if you
have to convolute the methods for your offsets.
--
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947
The Atrieva Service: Safe and Easy Online Backup http://www.atrieva.com
------------------------------
Date: 28 Jan 1999 17:50:17 GMT
From: "Vasco Patrmcio" <vpatricio@abrantina.pt>
Subject: How do I add an attachment to an e-mail?
Message-Id: <01be4ae6$f0509920$3f0a0a0a@vpatricio2>
I'm trying to send an e-mail through a perl script with the following line:
`cat $tmpfile | mail -s "Status $hostname" $SYSADMIN `;
This would work fine, except that I don4t want the '$tmpfile' to be sent in
the body of the message. Instead, I'd rather send it on an attachment,
which I don't know how to do.
My question is: is there any "perl-way" of doing this?
I think there is probably a more eficient way using some perl function that
I don't know. If that "send-mail" function exists, how do I use it to send
an attachment?
Thank you very much,
Vasco Patrmcio
------------------------------
Date: Thu, 28 Jan 1999 14:11:48 -0500
From: dwilgaREMOVE@mtholyoke.edu (Dan Wilga)
Subject: Re: How do I add an attachment to an e-mail?
Message-Id: <dwilgaREMOVE-2801991411480001@wilga.mtholyoke.edu>
In article <01be4ae6$f0509920$3f0a0a0a@vpatricio2>, "Vasco Patrmcio"
<vpatricio@abrantina.pt> wrote:
> I'm trying to send an e-mail through a perl script with the following line:
>
> `cat $tmpfile | mail -s "Status $hostname" $SYSADMIN `;
>
> This would work fine, except that I don4t want the '$tmpfile' to be sent in
> the body of the message. Instead, I'd rather send it on an attachment,
> which I don't know how to do.
Take a look at the MIME::Lite module on CPAN.
Dan Wilga dwilgaREMOVE@mtholyoke.edu
** Remove the REMOVE in my address address to reply reply **
------------------------------
Date: Thu, 28 Jan 1999 18:15:32 GMT
From: ears@dania.dialisdn.com (Ears)
Subject: Re: Jesus Rides a HOG(tm) : was :CONCLUSIVE PROOF: The Beatles are bigger than Jesus!
Message-Id: <slrn7b00eq.1p8.ears@dania.dialisdn.com>
On Wed, 27 Jan 1999 16:20:30 -0600,
Olice (Oly) Certain <ocertain@webwide.net> wrote:
Absolutely nothing. But I'll bet he was smart enough to
snip his newsgroup himself.
--
*Ears* 98 XL 1200 Custom
kd4zkw@amsat.org
http://www.dialisdn.net/user/cdlevin
------------------------------
Date: Thu, 28 Jan 1999 10:29:37 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Learning perl
Message-Id: <MPG.111a4c69f19744ac9899d7@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <dd1s2.15$7y6.403@news.cwix.com> on Thu, 28 Jan 1999 17:35:05
GMT, Eric Gorely <eric.gorely@mci.com> says...
...
> $file=<~/bin/scripts/a>;
> open(INFO, $file);
> @lines=<INFO>;
> close(INFO);
> print "@lines";
>
> modify it so that the file is read in one line at a time and is output with
> a line number at the beginning. After that, make it so that the line numbers
> are printed as 001, 002, 003, etc...To format the numbers, I should only
> need to change one line by inserting an extra four characters (so it says).
...
> $file=<~/bin/scripts/a>;
> open(INFO, $file);
Always, yes always, test the result of an 'open'. Even in an exercise -
- it's a habit you will never regret forming.
open(INFO, $file) or die "Couldn't read $file. $!\n";
> $lines=<INFO>;
The line above reads and saves the first line from the file, but never
uses it. Can it!
> $i=1;
The four characters you want to add produce this:
$i = '001';
> while ($line=<INFO>) # as suggested by the tutorial
If you use perl 5.004, this will produce a misguided diagnostic, and you
will need:
while (defined($line = <INFO>)) # as suggested by the tutorial
> {
> print "$i $line";
> $i=$i+1;
Now you replace the above by this:
++$i;
The 'magic auto-increment' does the trick for you by preserving the
formatting. See perlop for details.
> }
> close(INFO);
You should also get used to using the '-w' flag, and 'use strict;' which
will force you to declare all your variables.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 28 Jan 1999 13:12:27 -0500
From: "Michael Mongeau" <michael_mongeau@stratus.com>
Subject: Re: Learning perl
Message-Id: <78q99f$sfr@transfer.stratus.com>
Eric Gorely <eric.gorely@mci.com> wrote in message
news:dd1s2.15$7y6.403@news.cwix.com...
>
>$file=<~/bin/scripts/a>;
>open(INFO, $file);
>$lines=<INFO>;
>$i=1;
>while ($line=<INFO>) # as suggested by the tutorial
>{
> print "$i $line";
> $i=$i+1;
>}
>close(INFO);
>
>This works, but I can't, for the life of me, figure out how to get the
>numbers formatted according to the second part of the exercise. Can anyone
>give some ways of doing this? And perhaps maybe a better way of doing the
>part I've already done? Thanks in advance for your help.
The printf statement works nicely for zero-padding:
$file=<~/bin/scripts/a>;
open INFO,$file;
$i=1;
while (<INFO>) {
printf "%03d %s",$i++,$_;
}
close INFO;
Michael Mongeau
------------------------------
Date: Thu, 28 Jan 1999 13:10:56 -0500
From: Ben Smith <bsmith@perf.zko.dec.com>
Subject: Re: need a little socket help
Message-Id: <36B0A830.BE27523F@perf.zko.dec.com>
I'm just guessing on this, but I think you may be having a problem with
buffering. To set SOCK to be unbuffered:
$oldFH=select(SOCK);$|=1;select($oldFH);
-ben
--
work: bsmith@perf.zko.dec.com = Ben Smith = ZKO2-3R55 = 603-884-2836
home: ben@roninhouse.com = 603-924-4131 = FAX: 603-924-3582
------------------------------
Date: 28 Jan 1999 18:34:14 GMT
From: gward@cnri.reston.va.us (Greg Ward)
Subject: Re: pattern matching
Message-Id: <78qaj6$7i5$2@news0-alterdial.uu.net>
Tyler Hutcheon <hutcheon@iaw.on.ca> wrote:
> I have quite a bit of experience with perl, but I'm about to write a
> script where I need some help with pattern matching, and I don't know all
> that much about it.
Have you read the fine book *Learning Perl* by Randal Schwartz and Tom
Christiansen? I haven't looked at it in quite a while, but I would
imagine it has a pretty good introduction to using regular expressions.
You could always read (many times!) the 'perlre' man page, but it's
quite dense -- as is the corresponding material in *Programming Perl*.
And you could always make use of the web's many fine search engines.
Just for grins, I popped over to Alta Vista and typed in "perl regular
expression tutorial". Whaddya know, a couple of Perl regular expression
tutorials popped up. Since they're on the web, they might well be total
garbage, but that's the price you pay for free information...
Greg
--
Greg Ward - software developer gward@cnri.reston.va.us
Corporation for National Research Initiatives
1895 Preston White Drive voice: +1-703-620-8990 x287
Reston, Virginia, USA 20191-5434 fax: +1-703-620-0913
------------------------------
Date: Thu, 28 Jan 1999 13:08:37 -0500
From: "Douglas N. Craig" <dcraig@ismd.ups.com>
Subject: Perl DLL
Message-Id: <78q8os$9u81@innsrv.ismd.ups.com>
You can make a Perl executable, can you make a Perl DLL which would export
the subroutines defined in it so that another application may load it?
More specifically, we are creating SQL calls to an Access database.which are
made using ODBC in Perl. These calls will be contained in a Perl file which
will act as an interface to our database. We have a seperate program which
can load an external DLL and use it's exported functions. We hope to utilize
the Perl interface from this application to access our database.
Has this ever been tried before? Is it worth trying?
Thanks in advance!
Doug
------------------------------
Date: Thu, 28 Jan 1999 10:57:01 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Perl Question
Message-Id: <MPG.111a52d95ebcb65b9899d9@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <36B09770.CDE21CAD@ngb.se> on Thu, 28 Jan 1999 17:59:28
+0100, Staffan Liljas <staffan@ngb.se> says...
> drooney@globaldirectmail.com wrote:
> > I have a file now the data in the file is a bunch of
> > single line entrys delimited with colons (:),
>
> open( IN, "data.dat" ) || die "Couldn't open: $!";
> while(<IN>){
> s/:/","/g;
> s/^|$/"/g;
> }
>
> and then output. There might be a better way, this might be a FAQ, but
> the above works.
#!/usr/local/bin/perl -w
use Benchmark;
my $string = 'TO:REGEX:IS:HUMAN,:SPLIT:-:DIVINE!';
timethese(1 << (shift || 0), {
Regex => sub {
$_ = $string;
s/:/","/g;
s/^|$/"/g;
$_
},
Split => sub { '"' . join('","', split /:/, $string) . '"' },
});
__END__
Benchmark: timing 65536 iterations of Regex, Split...
Regex: 8 wallclock secs ( 9.42 usr + 0.00 sys = 9.42 CPU)
Split: 4 wallclock secs ( 3.28 usr + 0.00 sys = 3.28 CPU)
Even if a much faster way were used to append the leading and trailing
quotes (as the Split code shows), the Regex would still be somewhat
slower (4.08 sec).
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 28 Jan 1999 19:04:12 GMT
From: kos@tdd.hbo.nec.com
Subject: Question Serial port programming
Message-Id: <78qcb5$n5s$1@nnrp1.dejanews.com>
While reading and writing from/to the serial port on Solaris, I found that
input from the serial port is echoed back to the other end of the serial
connection. Is there a way to disable this feature?
My code is something like this:
my $CommPort = new IO::File;
open ($CommPort, "<$/dev/ttya");
$buf = <$CommPort>; # This input is echoed back
Thanks in advance.
Shang Ko
eLuminant Technologies
kos@tdd.hbo.nec.com
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Thu, 28 Jan 1999 09:45:22 -0800
From: moseley@best.com (Bill Moseley)
Subject: Re: Reading headers & LWP
Message-Id: <MPG.111a41dba05a079d98968c@nntp1.ba.best.com>
Thanks. I did read that but it didn't sink in what it mean -- I haven't
written a sub-class before. Thanks very much for the example!
> -- MyAgent.pm --
> # subclass LWP::UserAgent and stop auto redirects
> package MyAgent;
> use strict;
> use LWP::UserAgent;
> use vars qw(@ISA);
> @ISA = qw(LWP::UserAgent);
> sub redirect_ok { 0; }
> 1;
--
Bill Moseley mailto:moseley@best.com
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 4769
**************************************