[24797] in Perl-Users-Digest
Perl-Users Digest, Issue: 6950 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 3 00:06:59 2004
Date: Thu, 2 Sep 2004 21:05:07 -0700 (PDT)
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, 2 Sep 2004 Volume: 10 Number: 6950
Today's topics:
Benchmark::Timer 0.6 released <newspost@coppit.org>
Re: Custom web design and web site development (Rose)
new to perl (MES)
NEw to Perl (Shawn Melnic)
Re: NEw to Perl <cwilbur@mithril.chromatico.net>
Re: NEw to Perl <dwall@fastmail.fm>
Re: NEw to Perl <nospam@bigpond.com>
Re: New to perl <jurgenex@hotmail.com>
Re: new to perl <jurgenex@hotmail.com>
Re: NEw to Perl <jurgenex@hotmail.com>
Re: NEw to Perl <dwall@fastmail.fm>
Re: Newbie needs help on pattern matching <harris@zk3.dec.com>
Re: Newbie needs help on pattern matching <msdebian@yahoo.com>
Re: q about MIME:Lite and using Bcc (dan baker)
Simple question (PF)
Re: Simple question <noreply@gunnar.cc>
Split by length <me@myplace.com>
Re: Split by length <dwall@fastmail.fm>
travesty.pl (was: YOU ALL SUCK!) (J. Romano)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 2 Sep 2004 21:19:41 GMT
From: David Coppit <newspost@coppit.org>
Subject: Benchmark::Timer 0.6 released
Message-Id: <I3FrxK.1qv6@zorch.sf-bay.org>
Description:
- Benchmark::Timer allows you to time portions of code conveniently, as well
as benchmark code by allowing timings of repeated trials. It is perfect for
when you need more precise information about the running time of portions of
your code than the Benchmark module will give you, but don't want to go all
out and profile your code.
- This release adds statistical sampling functionality, answering the common
question "How many trials are enough?"
Download:
- You can download Benchmark::Timer from CPAN:
http://www.cpan.org/authors/id/D/DC/DCOPPIT/Benchmark-Timer-0.6.tar.gz
- Until the file propagates to the mirrors, you can use the following URL:
http://prdownloads.sourceforge.net/benchmark-timer/Benchmark-Timer-0.6.tar.gz
Changes:
- Maintenance of the module transferred to David Coppit
- License changed to GNU GPL.
- Improved reporting to support multiple tags
- Added statistical sampling, allowing the user to time code until a certain
confidence level is reached. (Added error() and confidence() to support this
functionality)
See the README for additional notes.
A complete change log is at:
- http://benchmark-timer.sourceforge.net/CHANGES
Regards,
David
------------------------------
Date: Thu, 02 Sep 2004 23:02:36 GMT
From: Roseb44170@aol.com (Rose)
Subject: Re: Custom web design and web site development
Message-Id: <4137a66d.10545127@cp-news.centix.net>
On 1 Sep 2004 11:35:50 -0700, krakle@visto.com (krakle) wrote:
>cna_pgroup@yahoo.com (CNA Programming Group) wrote in message news:<a03287ab.0408310501.529d7472@posting.google.com>...
>> I'm experienced PHP/Coldfusion developer from Russia with more than 5
>> years of experience in the field.
>>
>> I usually charge USD 7 per hour, but would rather like flat-rate
>> per-project prices.
>>
>
>huh? what? $7 an hour?
>Your work can't be "hi-quality".. Do yourself a favor and 1. stop
>spamming and 2. get a job at mcdonalds they will pay you more :)
I just KNEW that "$7 an hour" part would get some response!
(and not all of it good!)
Rose
http://members.aol.com/Roseb441702/consult.htm
"Can YOU Make Money on the Internet?-YES!"
------------------------------
Date: 2 Sep 2004 15:59:46 -0700
From: mesemailoffers@verizon.net (MES)
Subject: new to perl
Message-Id: <332aa15a.0409021459.493f5656@posting.google.com>
I have a quick question - I have a script that reads .txt files and
from the file creates a file that is emailed to the requestor. I
want the name of the file to be the name of the input file without the
.txt at the end. How can this be done?
Ex:
$file = text.txt
outputfile = "$file .html
My outputfile comes out - test.txt.html
I would like it to be test.html
Can anyone help?
Thanks!
------------------------------
Date: 2 Sep 2004 18:16:45 -0700
From: sham_x30@yahoo.com (Shawn Melnic)
Subject: NEw to Perl
Message-Id: <a365c2aa.0409021716.4dde5964@posting.google.com>
greetings,
how do I make while in perl do this:
while(&list) {
@line = ..
bla bla
bla
}
sub list {
print "line 1";
print "line 2" ;
print "line 3" ;
}
Basically, I want while to read the sub list into an array..
Thanks + +
------------------------------
Date: Fri, 03 Sep 2004 02:17:35 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: NEw to Perl
Message-Id: <873c206r6n.fsf@mithril.chromatico.net>
>>>>> "SM" == Shawn Melnic <sham_x30@yahoo.com> writes:
SM> greetings,
SM> how do I make while in perl do this:
SM> Basically, I want while to read the sub list into an array..
I recommend you start with _Beginning Perl_:
http://learn.perl.org/library/beginning_perl/
Good luck.
Charlton
--
cwilbur at chromatico dot net
cwilbur at mac dot com
------------------------------
Date: Fri, 03 Sep 2004 02:16:55 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: NEw to Perl
Message-Id: <Xns9558E2AB2DE8dkwwashere@216.168.3.30>
sham_x30@yahoo.com (Shawn Melnic) wrote:
> greetings,
Hello. Please put the subject of your post into the Subject of your post.
> how do I make while in perl do this:
>
> while(&list) {
> @line = ..
> bla bla
> bla
> }
>
> sub list {
> print "line 1";
> print "line 2" ;
> print "line 3" ;
> }
Do what?
> Basically, I want while to read the sub list into an array..
Whatever that means. Using PSI::ESP, I'd guess maybe you want to, um... I
think my copy of PSI::ESP is broken. What is it you wanted? Can you be more
explicit?
------------------------------
Date: Fri, 03 Sep 2004 12:18:55 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: NEw to Perl
Message-Id: <2pq2jcFn74tiU1@uni-berlin.de>
Three similar posts, all from google groups. Odd.
gtoomey
------------------------------
Date: Fri, 03 Sep 2004 02:43:55 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: New to perl
Message-Id: <LTQZc.571$H26.534@trnddc07>
Gus wrote:
> What would the syntax be for the follwing?
>
> I want to cat /admin/log/fileA,
I don't think so. Maybe you meant to say you want to read /admin/log/fileA?
If yes, then please see
perldoc -f open
including the examples.
If no, then you should ask in a group that deals with the tool "cat".
> and grep any lines that have the name
> "joe",
perldoc -f grep
> then send the output to /admin/log/fileB.
perldoc -f open
perldoc -f print
> Then I want to view
> /admin/log/fileB
perldoc -f open
perldoc -f print
> I want to cat /admin/log/fileA, and grep any lines that have today's
> dat in them, then send that output to /admin/log/fileC. Then I want to
> view that file.
Only new item in this list would be
perldoc -f time
perldoc -f localtime
jue
------------------------------
Date: Fri, 03 Sep 2004 02:44:49 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: new to perl
Message-Id: <BUQZc.572$H26.537@trnddc07>
MES wrote:
> I have a quick question - I have a script that reads .txt files and
> from the file creates a file that is emailed to the requestor. I
> want the name of the file to be the name of the input file without the
> .txt at the end. How can this be done?
>
> Ex:
>
> $file = text.txt
>
> outputfile = "$file .html
>
>
> My outputfile comes out - test.txt.html
>
> I would like it to be test.html
perldoc -f rename
jue
------------------------------
Date: Fri, 03 Sep 2004 02:49:57 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: NEw to Perl
Message-Id: <pZQZc.573$H26.469@trnddc07>
Shawn Melnic wrote:
> greetings,
>
> how do I make while in perl do this:
>
> while(&list) {
That's not the way to call a sub. Change that to
while (list()) {
> @line = ..
Why are you using an array for individual lines?
> bla bla
> bla
> }
>
> sub list {
> print "line 1";
> print "line 2" ;
> print "line 3" ;
Just add
return ("line1", "line2", "line3");
here.
jue
------------------------------
Date: Fri, 03 Sep 2004 03:21:18 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: NEw to Perl
Message-Id: <Xns9558ED95C681Fdkwwashere@216.168.3.30>
Gregory Toomey <nospam@bigpond.com> wrote:
> Three similar posts, all from google groups. Odd.
Must be in the same class. :-)
------------------------------
Date: Thu, 02 Sep 2004 22:53:46 GMT
From: Bob Harris <harris@zk3.dec.com>
Subject: Re: Newbie needs help on pattern matching
Message-Id: <harris-1BD7A4.18533002092004@cacnews.cac.cpqcorp.net>
In article <2ppejjFnj5lcU1@uni-berlin.de>,
Madhusudan Singh <msdebian@yahoo.com> wrote:
> Hi
>
> I am kind of new to perl (dabbled in it a little bit 4-5 years ago,
> but
> never needed it till now - I am writing an application).
>
> I need to extract some info from /sbin/iwconfig eth1 :
>
> $ /sbin/iwconfig eth1 | grep "Link"
>
> Link Quality:90/92 Signal level:-8 dBm Noise level:-148 dBm
> (updated)
>
> I want to extract 90/92 from the stuff above. How do I code it ?
>
> If it is possible to use awk to do the above ('{print $2}' yields
> "Quality:90/92", when I need to extract 90/92 or even better 90 and 92
> separately, that is also ok.
>
> How does one embed an awk command in perl ? I tried :
>
> $info=`/sbin/iwconfig eth1 | grep "Link" | awk '{print $2}'`; but it
> did
> not work (just reproduced o/p as if the second pipe were not even present).
>
> Thanks.
First, perl has excellent pattern matching and data manipulation
facilities, so I don't know why you are using awk to grab information.
But to answer the awk part of the question.
$info=`/sbin/iwconfig eth1 | awk '/Link/ {split(\$2,a,":"); print a[2]}`
Notice I backquoted the $, as perl might be gobbling it up looking to
substitute a perl variable.
Also watch out for a trailing Newline, unless you change the print a[2]
to a printf "%s",a[2]
But I think there are much more Perl'ish ways to capture this
information without using awk, I just do not happen to be a wiz at Perl
:-)
Good luck.
Bob Harris
------------------------------
Date: Thu, 02 Sep 2004 20:46:30 -0400
From: Madhusudan Singh <msdebian@yahoo.com>
Subject: Re: Newbie needs help on pattern matching
Message-Id: <2ppt6rFnkvlnU1@uni-berlin.de>
Tad McClellan wrote:
> Use a m// in list context instead of the above then:
>
> my($first, $second) = $_ =~ m!Link Quality:(\d+)/(\d+)!;
Thanks for the help :)
------------------------------
Date: 2 Sep 2004 19:18:13 -0700
From: botfood@yahoo.com (dan baker)
Subject: Re: q about MIME:Lite and using Bcc
Message-Id: <13685ef8.0409021818.754eddcc@posting.google.com>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message news:<2pp180Fngd54U1@uni-berlin.de>...
> dan baker wrote:
> > what happens is that the To recipient gets a message, and the Bcc
> > recipient gets nothing. I get no error, no bounceback, no
> > nothing....
>
> Can it possibly be another of Comcast's actions against spammers?
> Maybe they have simply disabled their mail servers' ability to relay
> to Bcc recipients.
--------------------------
I dont think so.... they allow up to 100 cc or bcc recipients per mail
composed other ways (like netscape, ms, mozilla, etc.)
d
------------------------------
Date: 2 Sep 2004 16:12:31 -0700
From: pauldfisk@hotmail.com (PF)
Subject: Simple question
Message-Id: <1c02bece.0409021512.639c5f20@posting.google.com>
I have a web page that posts its form data to a cgi script.
I have a request to modify the perl script to BCC the raw form data to
a separate email address. I thought I could just BCC the data as shown
below but the email that gets sent is parsed out into field names and
values. I do not need to change that part. I just need the raw form
data from the HTML post to get emailed to a second email address. I
know this should be easy but I have never programmed PERL and haven't
a clue.
Any resources that show how to do this.
Paul
There is a send mail function like this:
sub send_mail {
# Localize variables used in this subroutine.
#
local($print_config,$key,$sort_order,$sorted_field,$env_report);
# Open The Mail Program
open(MAIL,"|$mailprog -t");
print MAIL "To: webleads\@MyDomain.com\n";
print MAIL "From: $Config{'email'} ($Config{'Name'})\n";
print MAIL "cc: \n";
print MAIL "Bcc: demorequest\@MyDomain.net\n";
# Check for Message Subject
if ($Config{'subject'}) { print MAIL "Subject:
$Config{'subject'}\n\n" }
else { print MAIL "Subject: WWW Form
Submission\n\n" }
print MAIL "Demo Request\n";
print MAIL "$date at $time\n";
print MAIL "Host: $ENV{'REMOTE_ADDR'}\n";
print MAIL "-" x 55 . "\n\n";
print MAIL "Name: $Config{'Name'}\n\n";
print MAIL "Email: $Config{'email'}\n\n";
if (@Print_Config) {
foreach $print_config (@Print_Config) {
if ($Config{$print_config}) {
print MAIL "$print_config:
$Config{$print_config}\n\n";
}
}
}
# Sort alphabetically if specified:
#
if ($Config{'sort'} eq 'alphabetic') {
foreach $field (sort keys %Form) {
# If the field has a value or the print blank fields
option #
# is turned on, print out the form field and value.
#
if ($Config{'print_blank_fields'} || $Form{$field} ||
$Form{$field} eq '0') {
print MAIL "$field: $Form{$field}\n\n";
}
}
}
# If a sort order is specified, sort the form fields based on
that. #
elsif ($Config{'sort'} =~ /^order:.*,.*/) {
# Remove extraneous line breaks and spaces, remove the order:
#
# directive and split the sort fields into an array.
#
$Config{'sort'} =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
$Config{'sort'} =~ s/(\s+)?\n+(\s+)?//g;
$Config{'sort'} =~ s/order://;
@sorted_fields = split(/,/, $Config{'sort'});
# For each sorted field, if it has a value or the print blank
#
# fields option is turned on print the form field and value.
#
foreach $sorted_field (@sorted_fields) {
if ($Config{'print_blank_fields'} || $Form{$sorted_field}
||
$Form{$sorted_field} eq '0') {
print MAIL "$sorted_field: $Form{$sorted_field}\n\n";
}
}
}
# Otherwise, default to the order in which the fields were sent.
#
else {
# For each form field, if it has a value or the print blank
#
# fields option is turned on print the form field and value.
#
foreach $field (@Field_Order) {
if ($Config{'print_blank_fields'} || $Form{$field} ||
$Form{$field} eq '0') {
print MAIL "$field: $Form{$field}\n\n";
}
}
}
print MAIL "-" x 65 . "\n\n";
# Send any specified Environment Variables to recipient.
#
foreach $env_report (@Env_Report) {
if ($ENV{$env_report}) {
print MAIL "$env_report: $ENV{$env_report}\n";
}
}
close (MAIL);
}
------------------------------
Date: Fri, 03 Sep 2004 01:25:15 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Simple question
Message-Id: <2ppok5Fmv3d9U1@uni-berlin.de>
PF wrote:
> I have a web page that posts its form data to a cgi script. I have
> a request to modify the perl script to BCC the raw form data to a
> separate email address.
<snip>
> I know this should be easy but I have never programmed PERL and
> haven't a clue.
How can you know it should be easy, when you don't know any Perl?
> Any resources that show how to do this.
http://learn.perl.org/
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 2 Sep 2004 21:34:57 -0400
From: "Papago" <me@myplace.com>
Subject: Split by length
Message-Id: <IIidnc39bpemV6rcRVn-hg@golden.net>
Is there a single Perl command that will split a string into an array by
number of characters? For example, if I had the string:
$string = "monkey";
I could specify a lenght, such as 2, and it would put every pair of 2
characters into an array that looks something like this:
$array[0] = "mo";
$array[1] = "nk";
$array[3] = "ey";
Is that possible?
------------------------------
Date: Fri, 03 Sep 2004 02:11:09 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: Split by length
Message-Id: <Xns9558E1B0F634Cdkwwashere@216.168.3.30>
"Papago" <me@myplace.com> wrote:
> Is there a single Perl command that will split a string into an array by
> number of characters? For example, if I had the string:
>
> $string = "monkey";
>
> I could specify a lenght, such as 2, and it would put every pair of 2
> characters into an array that looks something like this:
>
> $array[0] = "mo";
> $array[1] = "nk";
> $array[3] = "ey";
>
> Is that possible?
Yes. You can do it the easy way by capturing stuff with a regex or you can do
it a longer way using substr(). I'm sure there are many other ways as well.
What way did your teacher want you to use?
------------------------------
Date: 2 Sep 2004 20:52:35 -0700
From: jl_post@hotmail.com (J. Romano)
Subject: travesty.pl (was: YOU ALL SUCK!)
Message-Id: <b893f5d4.0409021952.1afa1178@posting.google.com>
Eric Bohlman <ebohlman@omsdev.com> wrote in message news:<Xns9558DF032E46ebohlmanomsdevcom@130.133.1.4>...
> "Amanita, Love Ewe" <ladyamanita@aol.com> wrote in
> news:1bf5bcb9.15695836@aol.com:
>
> > Sharon expects the printer within hers and actually looks. Why will
> > you grasp the ugly worthwhile onions before Satam does? Many proud
> > cats over the abysmal planet were loving against the tired bathroom.
>
> This seems to be of somewhat better quality than the output of the typical
> random-text generator. Can anyone suggest something on CPAN useful for
> such?
Dear Eric,
The first edition of "Programming Perl" (back when it was the "Pink
Camel book", not the "Blue Camel book") had several real-world
programs, many of which are now found in the Perl Cookbook. One such
program (that never made it into the cookbook) was "travesty," a
program that spewed out somewhat random text based from standard
input.
It analyzed every two-word combination and stored off in a lookup
hash all the words that came next. When printing out text, it would
print out a new word based on the previous two words printed.
Even with this knowledge, it took me a long time to figure out how
the program worked. Once I figured it out, I took the liberty of
re-writing it in code that (I thought) was easier to understand.
I ran that program on a write-up I posted to comp.lang.perl.misc on
June 26, 2004 titled "Regarding copy constructors and mutators." I
don't know if anybody besides me ever read the write-up, but I found
that when I fed it to my travesty script, I got some bizarre (and
somewhat humorous) lines of output. If nobody will read my real
write-up, maybe they'll read the (more entertaining?) travesty output.
Here are a few samples:
Therefore, if a change is made from $b, which is why $a appeared
to lose it, while $b kept it. So now let's try a little more
than computers with limbs, and since computers aren't very
intelligent, neither is Person C. (That's why androids aren't
hired to be used as a reference to the first argument.
Now print $b. You'll see that only the value for $c would change
(the copy constructor to assign a copy constructor (and will not
call the copy constructor? This happened because, since '+=' was
not called. You may know by now that that won't get called until
you use $a or $b with its first mutator.
In case you're interested, you can read the original write up at:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=b893f5d4.0406261126.2e1e23ab%40posting.google.com
And if you're at all interested in my script, here it is:
#!/usr/bin/perl -w
use strict;
my $linesLeftToPrint = 0;
my @tokens = ('') x 2;
while (<>)
{
# Remove any non-word chars at the start of the line:
s/^\W+//;
push @tokens, split;
$linesLeftToPrint++;
}
# Now populate %lookup (the keys are all two-word
# sequences, and the values are a list of the word
# that follows:
my %lookup;
for (my $i = 2; $i <= $#tokens; $i++)
{
$lookup{"$tokens[$i-2] $tokens[$i-1]"}->{$tokens[$i]}++;
}
# Uncomment this next line to see the contents of %lookup;
# use Data::Dumper; print Dumper \%lookup; # debug line
# Now populate $text by starting out with the first word
# and then adding new words, one at a time:
my @usedWords = ('') x 2;
my $col = 0;
while (1)
{
# Find the next word to use:
my $word;
if (exists $lookup{"$usedWords[-2] $usedWords[-1]"})
{
my @wordList = keys %{$lookup{"$usedWords[-2] $usedWords[-1]"}};
$word = $wordList[int(rand @wordList)];
}
else
{
# Choose a random word from the original tokens:
$word = $tokens[int(rand @tokens)];
}
# Print $word (and make sure it fits on the line):
if ($col + length($word) + 1 <= 65)
{
print "$word ";
$col += length($word) + 1;
}
else
{
print "\n$word ";
$col = length($word) + 1;
$linesLeftToPrint--;
}
# Record $word for the next time through the loop:
push @usedWords, $word;
# Does $word end with a '.', '?', or '!'?
# If so, either add a space or start a new paragraph:
if ($word =~ /(\.|\?|!)$/)
{
# Start a new paragraph every five lines or so:
if (rand() < 0.2)
{
print "\n\n";
$col = 0;
last if $linesLeftToPrint <= 0;
}
else
{
print " ";
}
}
}
__END__
Note: You can change both occurrences of "x 2" to "x 3" (and
change the counter in the "for" loop to start at 3) if you want to
build the lookup hash based on the last three words instead of just
the last two.
Feel free to use and modify this script. After all, it's based on
a program printed in the first edition of the "Programming Perl" book,
so it wouldn't make sense for me to restrict its use.
Happy Perling!
-- Jean-Luc
------------------------------
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 V10 Issue 6950
***************************************