[29239] in Perl-Users-Digest
Perl-Users Digest, Issue: 483 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 5 00:10:15 2007
Date: Mon, 4 Jun 2007 21:09:13 -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 Mon, 4 Jun 2007 Volume: 11 Number: 483
Today's topics:
[META] Re: perl hash - data processing <rvtol+news@isolution.nl>
Re: [newbie] XML::Simple install fails? <cohagan@nospam.nospam>
Best error handling mechanism? <hoelz@wisc.edu>
Can't modify constant item in scalar assignment <dksleung@hotmail.com>
Re: Can't modify constant item in scalar assignment <uri@stemsystems.com>
Re: Can't modify constant item in scalar assignment <dksleung@hotmail.com>
Re: Can't modify constant item in scalar assignment <kkeller-usenet@wombat.san-francisco.ca.us>
Re: Can't modify constant item in scalar assignment <dksleung@hotmail.com>
Re: FAQ 8.47 How do I keep my own module/library direct <tzz@lifelogs.com>
Help With Placeholders <mburgoon@gmail.com>
How do I get the data out of this array? <gimme_this_gimme_that@yahoo.com>
Re: How to erase Hex value 0D from string? <wblock@wonkity.com>
How to get "Monthly Stats" program? (Carl Hopkins)
Re: How to get "Monthly Stats" program? <mritty@gmail.com>
Re: How to get "Monthly Stats" program? <mritty@gmail.com>
merging two files <vahid.moghaddasi@gmail.com>
Re: Need suggestions on a good locking module <desas2@gmail.com>
Re: perl hash - data processing <rvtol+news@isolution.nl>
Re: question about socket and scalar. <jgibson@mail.arc.nasa.gov>
Re: Returning substring of regex match <wahab-mail@gmx.de>
Re: Returning substring of regex match <noreply@gunnar.cc>
Re: Returning substring of regex match <wahab-mail@gmx.de>
Re: Returning substring of regex match <rvtol+news@isolution.nl>
Sending RTF email with Perl? (J.D. Baldwin)
Re: Sending RTF email with Perl? <spamtrap@dot-app.org>
Re: Sending RTF email with Perl? (J.D. Baldwin)
Re: Spawning other processes but continue script <see.sig@rochester.rr.com>
using LWP::UserAgent Get method <paul.pettus@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 4 Jun 2007 20:36:27 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: [META] Re: perl hash - data processing
Message-Id: <f41tca.1gs.1@news.isolution.nl>
shree schreef:
> Hello Dr.Ruud,
> Can you show how to quote for future?
No problem. I would attribute and quote like the first nine lines inside
the --- below.
------------------------------------------
shree wrote:
> [input as in the DATA-section below]
> [desired output:]
> yyyy-mm|members added|cumulative total|% increase
> 2007-01|3|3|-
> 2007-02|1|4|33.33%
> 2007-03|2|6|50.00%
#!/usr/bin/perl
use strict;
use warnings;
[more code]
__DATA__
2007-01|member1
2007-01|member2
2007-01|member3
2007-02|member4
2007-03|member5
2007-03|member6
------------------------------------------
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Mon, 4 Jun 2007 16:18:10 -0500
From: "Bill Cohagan" <cohagan@nospam.nospam>
Subject: Re: [newbie] XML::Simple install fails?
Message-Id: <f420gr01j8t@enews4.newsguy.com>
Thanks, I'll give that a try if I can't isolate the problem. I've done the
install on a couple of other machines without problems, so it's something
peculiar to this machine. I'm going to try a fresh install of (cygwin) perl
itself as a first step.
Regards,
Bill
"Sisyphus" <sisyphus1@nomail.afraid.org> wrote in message
news:46640e60$0$14719$afc38c87@news.optusnet.com.au...
>
> "Bill Cohagan" <bill@teraXNOSPAMXquest.com> wrote in message
> news:46640b4d$0$9011$4c368faf@roadrunner.com...
>> Rob
>> Thanks for the response; however that appears not to be the case; i.e.,
>>
>>>>>>>>>>>>>>>>>>
>> C:\>perl -MXML::Simple -e "print $XML::Simple::VERSION"
>> Can't locate XML/Simple.pm in @INC (@INC contains:
>> /usr/lib/perl5/5.8/cygwin
>
> Aaah ... sorry. You're earlier post mentioned "Windows" ... but you're
> using Cygwin. (I was thinking *native* windows and, hence, ActivePerl -
> *my* mistake :-)
>
> Sorry - I don't make any attempt to diagnose problems with CPAN.pm
> installations (as I never use it).
>
> You could perhaps circumvent your problems with CPAN.pm/Cygwin by
> downloading
> http://search.cpan.org/CPAN/authors/id/G/GR/GRANTM/XML-Simple-2.16.tar.gz
> , extracting it to some location, cd'ing to that location and running, in
> succession:
>
> perl Makefile.PL
> make test
> make install
>
> Cheers,
> Rob
------------------------------
Date: Mon, 4 Jun 2007 20:13:12 -0500
From: Rob Hoelz <hoelz@wisc.edu>
Subject: Best error handling mechanism?
Message-Id: <20070604201312.5291aa85@TheRing>
I've read numerous articles on the internet, and I haven't come to a
clear conclusion yet: What form of error handling is best in Perl?
I've seen try/catch with Error.pm, eval/die with Exception.pm, and just
plain old eval/die. What's the best way to go about creating a robust
error handler?
Thanks,
Rob
------------------------------
Date: Mon, 04 Jun 2007 19:16:05 -0700
From: emrefan <dksleung@hotmail.com>
Subject: Can't modify constant item in scalar assignment
Message-Id: <1181009765.902913.246520@r19g2000prf.googlegroups.com>
I have the follow script for printing out the Last Modification Time
of a file and it has been working on Solaris with Perl 5.6.1 and on
Redhat with Perl 5.8.0 without any problems.
fileLastModTm = localtime( (stat shift)[9] );
$fileLastModTm[4]++; # month no. was zero-based, change that
$fileLastModTm[5] += 1900; # year no. was 1900-based, change that
fileLastModTm[ 5, 4, 3 ]; # spit it out, in yyyymmdd format
But somebody who needed the script could not use it, getting an error
such as follows:
Can't modify constant item in scalar assignment at flmtime.pl line 1,
near ");"
Can't use subscript on constant item at flmtime.pl line 4, near "3 ]"
Execution of flmtime.pl aborted due to compilation errors.
So, what went wrong? Now, I am asking the person to give me her perl's
version, but meanwhile, I think you clever bunch can still spot the
error for me? :) Thanks.
------------------------------
Date: Tue, 05 Jun 2007 02:30:28 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Can't modify constant item in scalar assignment
Message-Id: <x7hcpnw2td.fsf@mail.sysarch.com>
>>>>> "e" == emrefan <dksleung@hotmail.com> writes:
e> I have the follow script for printing out the Last Modification Time
e> of a file and it has been working on Solaris with Perl 5.6.1 and on
e> Redhat with Perl 5.8.0 without any problems.
e> fileLastModTm = localtime( (stat shift)[9] );
that isn't a perl variable. where is @?
e> $fileLastModTm[4]++; # month no. was zero-based, change that
e> $fileLastModTm[5] += 1900; # year no. was 1900-based, change that
e> fileLastModTm[ 5, 4, 3 ]; # spit it out, in yyyymmdd format
that isn't a perl variable. where is @?
e> So, what went wrong? Now, I am asking the person to give me her perl's
e> version, but meanwhile, I think you clever bunch can still spot the
e> error for me? :) Thanks.
the code was butchered somehow as neither of those lines has a proper
perl variable.
besides that it would be better done with strftime.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Mon, 04 Jun 2007 20:03:31 -0700
From: emrefan <dksleung@hotmail.com>
Subject: Re: Can't modify constant item in scalar assignment
Message-Id: <1181012611.467755.177620@j4g2000prf.googlegroups.com>
On Jun 5, 10:30 am, Uri Guttman <u...@stemsystems.com> wrote:
> >>>>> "e" == emrefan <dksle...@hotmail.com> writes:
>
> e> I have the follow script for printing out the Last Modification Time
> e> of a file and it has been working on Solaris with Perl 5.6.1 and on
> e> Redhat with Perl 5.8.0 without any problems.
>
> e> fileLastModTm = localtime( (stat shift)[9] );
>
> that isn't a perl variable. where is @?
>
> e> $fileLastModTm[4]++; # month no. was zero-based, change that
> e> $fileLastModTm[5] += 1900; # year no. was 1900-based, change that
> e> fileLastModTm[ 5, 4, 3 ]; # spit it out, in yyyymmdd format
>
> that isn't a perl variable. where is @?
>
> e> So, what went wrong? Now, I am asking the person to give me her perl's
> e> version, but meanwhile, I think you clever bunch can still spot the
> e> error for me? :) Thanks.
>
> the code was butchered somehow as neither of those lines has a proper
> perl variable.
>
> besides that it would be better done with strftime.
>
> uri
>
> --
> Uri Guttman ------ u...@stemsystems.com --------http://www.stemsystems.com
> --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
> Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
I asure you that the whole script was quoted and nothing was butchered
off. I have not been an active perl programmer but I guess @_ (i.e.
@ARGV) was implied to the shift command? As I said, the script does
run fine on two platforms, that's why I am puzzled.
------------------------------
Date: Mon, 4 Jun 2007 20:19:03 -0700
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Can't modify constant item in scalar assignment
Message-Id: <7a1fj4xhm.ln2@goaway.wombat.san-francisco.ca.us>
On 2007-06-05, emrefan <dksleung@hotmail.com> wrote:
> On Jun 5, 10:30 am, Uri Guttman <u...@stemsystems.com> wrote:
>> >>>>> "e" == emrefan <dksle...@hotmail.com> writes:
>>
>> e> fileLastModTm = localtime( (stat shift)[9] );
>>
>> that isn't a perl variable. where is @?
>>
>> e> fileLastModTm[ 5, 4, 3 ]; # spit it out, in yyyymmdd format
>>
>> that isn't a perl variable. where is @?
>>
> I asure you that the whole script was quoted and nothing was butchered
> off.
Then the script is broken. Fix it. Your script should include
use strict;
use warnings;
which would have pointed out these obvious errors for you.
> I have not been an active perl programmer but I guess @_ (i.e.
> @ARGV) was implied to the shift command?
Irrelevant, as fileLastModTm is not a Perl variable, which is where both
your problems lie.
> As I said, the script does
> run fine on two platforms, that's why I am puzzled.
I'm skeptical, but it still doesn't matter, as the script as you posted
it is wrong (or at the very least poorly written).
You should consider reading the Posting Guidelines, which help you write
a post which is likely to get you a helpful response.
--keith
--
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information
------------------------------
Date: Mon, 04 Jun 2007 20:21:26 -0700
From: emrefan <dksleung@hotmail.com>
Subject: Re: Can't modify constant item in scalar assignment
Message-Id: <1181013686.022922.286460@o11g2000prd.googlegroups.com>
On Jun 5, 10:30 am, Uri Guttman <u...@stemsystems.com> wrote:
> >>>>> "e" == emrefan <dksle...@hotmail.com> writes:
>
> e> I have the follow script for printing out the Last Modification Time
> e> of a file and it has been working on Solaris with Perl 5.6.1 and on
> e> Redhat with Perl 5.8.0 without any problems.
>
> e> fileLastModTm = localtime( (stat shift)[9] );
>
> that isn't a perl variable. where is @?
>
> e> $fileLastModTm[4]++; # month no. was zero-based, change that
> e> $fileLastModTm[5] += 1900; # year no. was 1900-based, change that
> e> fileLastModTm[ 5, 4, 3 ]; # spit it out, in yyyymmdd format
>
> that isn't a perl variable. where is @?
>
> e> So, what went wrong? Now, I am asking the person to give me her perl's
> e> version, but meanwhile, I think you clever bunch can still spot the
> e> error for me? :) Thanks.
>
> the code was butchered somehow as neither of those lines has a proper
> perl variable.
>
> besides that it would be better done with strftime.
>
> uri
>
> --
> Uri Guttman ------ u...@stemsystems.com --------http://www.stemsystems.com
> --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
> Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Ah, I looked at the thing closely just now and boy what blunder did I
make! So a @ was missing from the 1st line and "print $" was missing
from the last line. Gosh, I never imagined a cut-n-paste job could be
messed up like that. But I was to blame too, I didn't look before I
jump, er, ask. Sorry for wasting the bandwidth and your time. I've
learnt something from this though, if that's any comfort - I will not
make such a silly mistake, in public especially, again.
------------------------------
Date: Mon, 04 Jun 2007 15:41:00 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: FAQ 8.47 How do I keep my own module/library directory?
Message-Id: <m2ira3ecdv.fsf@lifelogs.com>
On Mon, 04 Jun 2007 10:01:21 -0700 Jim Gibson <jgibson@mail.arc.nasa.gov> wrote:
JG> How about adding something for CPAN shell users? Something like:
JG> If you use the CPAN module for building and installing modules,
JG> start the shell and enter the following:
cpan> o conf makepl_arg PREFIX=/mydir/perl,LIB=/mydir/perl/lib
cpan> o conf commit
Seconded, that's very useful.
Ted
------------------------------
Date: Tue, 05 Jun 2007 00:14:15 -0000
From: PerlGoon <mburgoon@gmail.com>
Subject: Help With Placeholders
Message-Id: <1181002455.321781.308760@q66g2000hsg.googlegroups.com>
This question pertains to using DBI with a MySQL database.....
I use placeholders for all my queries (mainly for security). The
problem I have is that I need to be able to print the actual queries
my code runs into a log.... with the placeholders replaced.
For example, consider the following:
my $id = "example";
my $sql = "UPDATE Customers SET ID=?";
my $query = $db->prepare($sql);
$query->execute($id);
How do I print the ACTUAL query that was run into a log file.... with
the placeholders replaced???
For example, when I do the following:
print $sql;
It prints:
UPDATE Customers SET ID=?
When I need it to print:
UPDATE Customers SET ID='example'
I know that I could replace the placeholders myself... but then
again... I need to log the ACTUAL query that was just executed... or
attempted to be executed.
Any help is appreciated... and thank you in advance.
------------------------------
Date: Mon, 04 Jun 2007 20:11:14 -0700
From: "gimme_this_gimme_that@yahoo.com" <gimme_this_gimme_that@yahoo.com>
Subject: How do I get the data out of this array?
Message-Id: <1181013074.532249.260540@g37g2000prf.googlegroups.com>
In the Perl Debugger a variable $vc looks like this:
DB<1> p $vc
ARRAY(0x19d1f9c)
DB<2> x $vc
0 ARRAY(0x19d1f9c)
0 ARRAY(0x19e0694)
0 2.0
1 3.0
1 ARRAY(0x19e064c)
0 7.0
1 6.0
2 ARRAY(0x19e067c)
0 8.0
1 12.0
How to I get :
2 3
7 6
8 12
Thanks.
------------------------------
Date: Mon, 04 Jun 2007 19:08:40 -0000
From: Warren Block <wblock@wonkity.com>
Subject: Re: How to erase Hex value 0D from string?
Message-Id: <slrnf68opo.9q7.wblock@speedy.wonkity.com>
Taomica <tomica@vvv.xls> wrote:
> Hex value is 0D, decimnal value is 13
>
>> How to erase Hex value 13 from string?
>>
>> Perl line : $b =~ tr/\013//;
>> dont work?!
\013 is octal. 0x0D = 13 = \015. Better to use \r if you mean carriage
return, though. And as Gunnar said, you need the d modifier:
$b =~ tr/\r//d;
--
Warren Block * Rapid City, South Dakota * USA
------------------------------
Date: Mon, 04 Jun 2007 19:14:10 GMT
From: carlh@nojunk.org (Carl Hopkins)
Subject: How to get "Monthly Stats" program?
Message-Id: <466463cb.1013471187@news.easynews.com>
Hello,
Where can I get the program that prints the "Monthly Stats" similar to
that shown below?
Thanks!
-----------------------------------------------------------------------------------------------------------
Newsgroup 'alt.tv.survivor' - Monthly Stats 31-Oct-04
Generated by Roarmeister (ebnezrvfg...@argfpncr.arg)
Results are based on the messages I get from my news server and filled
in with a public news server.
Total Posts this period: 3591
Total Bytes this period: 3187335
------------------------START SECTION 'POSTERS'-----------------------
Number of posts by Person (386 people posted during this period)
TT = This Time
-1M = Last Time
-2M = Last Last Time
-3M = Last Last Last Time
AML = Average Message Lines
QP = Average Message Quoted Percent
PGM = Percentage of Group in Messages
PGB = Percentage of Group in Bytes
TT -1M -2M Person # AML QP PGM PGB
--- --- --- ------ ---- --- ----- ----- -----
1 1 2 Obveeus................... 345 28 33.2% 9.6% 10.0%
2 6 4 The Horny Goat............ 271 18 33.7% 7.5% 5.7%
3 3 9 Ed Stasiak................ 231 28 37.6% 6.4% 7.3%
4 --- --- Steven Litvintchouk....... 117 36 33.4% 3.3% 3.8%
5 8 --- AWF President Quayle...... 110 30 57.4% 3.1% 3.3%
6 12 84 Brandons of mass destructi 109 31 43.9% 3.0% 3.5%
6 7 26 AbstractSeqentia.......... 109 17 10.9% 3.0% 2.4%
6 4 39 Roarmeister............... 109 35 30.5% 3.0% 4.7%
9 16 --- Rue-nu-atu................ 75 18 37.6% 2.1% 1.1%
9 148 5 Jay....................... 75 24 58.2% 2.1% 2.0%
11 2 19 Tinas49ers................ 68 21 43.5% 1.9% 1.1%
12 26 88 Jeff Russell.............. 66 16 37.1% 1.8% 1.1%
------------------------------
Date: Mon, 04 Jun 2007 12:32:56 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: How to get "Monthly Stats" program?
Message-Id: <1180985576.463299.123590@k79g2000hse.googlegroups.com>
On Jun 4, 3:14 pm, c...@nojunk.org (Carl Hopkins) wrote:
> Where can I get the program that prints the "Monthly Stats" similar to
> that shown below?
I don't know if there's an actual existing program available anywhere,
but you can certainly use Greg Bacon's News::Scan module to write one
pretty quickly...
http://search.cpan.org/~gbacon/News-Scan-0.53/News/Scan.pm
Paul Lalli
------------------------------
Date: Mon, 04 Jun 2007 12:34:35 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: How to get "Monthly Stats" program?
Message-Id: <1180985675.731952.65580@o5g2000hsb.googlegroups.com>
On Jun 4, 3:32 pm, Paul Lalli <mri...@gmail.com> wrote:
> On Jun 4, 3:14 pm, c...@nojunk.org (Carl Hopkins) wrote:
>
> > Where can I get the program that prints the "Monthly Stats" similar to
> > that shown below?
>
> I don't know if there's an actual existing program available anywhere,
> but you can certainly use Greg Bacon's News::Scan module to write one
> pretty quickly...
>
> http://search.cpan.org/~gbacon/News-Scan-0.53/News/Scan.pm
Ah, here we are. Greg actually included a program with that
distrobution, the eg/ directory: http://search.cpan.org/src/GBACON/News-Scan-0.53/eg/news-scan
Paul Lalli
------------------------------
Date: Mon, 04 Jun 2007 19:55:05 -0700
From: Vahid <vahid.moghaddasi@gmail.com>
Subject: merging two files
Message-Id: <1181012105.746963.9320@p77g2000hsh.googlegroups.com>
Hi all,
Is it possible to parse two colon delimited files and merge one field
from one of the files with the other file? For example if I want to
merge the second field (b) of the first file with the contents of
a:b:c:d with the third field of the second file with the contents of
e:f:g:h, I would get e:f:b:h. I came up with the following but don't
know where to add the parser for the second file?
sub mkShadow() {
open (SHADOWfh, "<$SHADOW") || die "Can not open the file:
$SHADOW. $!\n";
open (PASSWDfh, "<$PASSWD") || die "Can not open the file:
$PASSWD. $!\n";
open (XSHADOWfh, ">$XSHADOW") || die "Can not open the file:
$XSHADOW. $!\n";
@lines = <SHADOWfh> ;
### @linesX = <XSHADOWfh> # this is what I want
foreach $line (@lines) {
## what goes here?
# Skip comments
next if (m/^#/);
# Skip blank lines
next if (m/^\s*$/);
($username,$pass,$lastchange) = split /:/, $line;
## what goes here?
$x_lastupdate = ($lastchange*86400);
#
print $XSHADOWfh ("username: %s password: %s lastupdate: %d
\n", \
$username,$pass,$x_lastupdate) ;
} # for each
close $SHADOWfh;
close $XSHADOWfh;
close $PASSWDfh;
@args = ("pwdck", "-y", "ALL");
system(@args) == 0 or warn "System @args failed: $?";
}
Thank you very much,
------------------------------
Date: Mon, 04 Jun 2007 20:03:53 -0700
From: "desas2@gmail.com" <desas2@gmail.com>
Subject: Re: Need suggestions on a good locking module
Message-Id: <1181012633.108540.324600@q66g2000hsg.googlegroups.com>
On Jun 4, 8:33 am, Ignoramus27175 <ignoramus27...@NOSPAM.
27175.invalid> wrote:
> I have a script that I want to run, but only one instance. So I want
> to set up crontab to start it every minute, but if it is already
> running, I would exit.
>
> I looked at LockFile::Simple but I do not like it. I want to find a
> module that opens a file with O_EXCL and uses that for locking. (local
> hard drive filesystem only)
>
At the start of the program create a file if it does not exist and at
the end delete a file. If the file exists, then exit program.
HTH
Dinakar Desai
------------------------------
Date: Mon, 4 Jun 2007 20:14:39 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: perl hash - data processing
Message-Id: <f41rta.108.1@news.isolution.nl>
Paul Lalli schreef:
> I quoted what was necessary.
Not.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Mon, 04 Jun 2007 16:26:16 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: question about socket and scalar.
Message-Id: <040620071626164579%jgibson@mail.arc.nasa.gov>
In article <040620070927246688%jgibson@mail.arc.nasa.gov>, Jim Gibson
<jgibson@mail.arc.nasa.gov> wrote:
> See 'perldoc ipc' and search for 'Internet TCP Clients and Servers'
Sorry, but that is 'perldoc perlipc'.
--
Jim Gibson
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
------------------------------
Date: Mon, 04 Jun 2007 21:43:01 +0200
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Returning substring of regex match
Message-Id: <f41qbi$o2r$1@mlucom4.urz.uni-halle.de>
Taras_96 wrote:
> Is it possible to ask for a substring, or substrings, of a regular
> expression match to be returned in a regular expression?
> Say you want a list of the days in the dates for some input with some
> defined prefix:
> eg: Give me the days of all dates that are prefixed with the word DATE
>
> DATE22/5/07
> 1/5/07
> DATE25/5/07
> DATENO 26/5/07
>
> Would return 22 and 25, but not 1 or 26.
You may "literally" put your question into a
regular expression, like:
...
my @input = qw'
DATE22/5/07
1/5/07
DATE25/5/07
DATENO 26/5/07
';
print map /(?<=^DATE)\d+/g, @input;
...
The regular expression asks
for a numerical value (the day)
when encountering the \d+ thing, *if*
it was preceded by the letters DATE,
the (?<= ... ) is called "positive
lookbehind assertion".
The /g modifier in list context (map)
extracts the matched expression \d+,
(which is the day) - without capturing
parentheses.
The result of the above expression would
then be an "array of the extracted hits
(days)", which is printed instantaneously
here.
Regards
M.
------------------------------
Date: Mon, 04 Jun 2007 22:03:55 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Returning substring of regex match
Message-Id: <5cj9mcF310fbcU1@mid.individual.net>
Mirco Wahab wrote:
>
> ...
> my @input = qw'
> DATE22/5/07
> 1/5/07
> DATE25/5/07
> DATENO 26/5/07
> ';
>
> print map /(?<=^DATE)\d+/g, @input;
> ...
The qw() operator puts 'DATENO' and '26/5/07' in two separate elements.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 04 Jun 2007 22:20:03 +0200
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Returning substring of regex match
Message-Id: <f41sh0$oo8$1@mlucom4.urz.uni-halle.de>
Gunnar Hjalmarsson wrote:
> Mirco Wahab wrote:
>>
>> ...
>> my @input = qw'
>> DATE22/5/07
>> 1/5/07
>> DATE25/5/07
>> DATENO░26/5/07 <-- !!
>> ';
>>
>> print map /(?<=^DATE)\d+/g, @input;
>> ...
>
> The qw() operator puts 'DATENO' and '26/5/07' in two separate elements.
Oh yea, you are right.
First, I thought of using _DATA_ but
abstained from it because I didn't
want to replicate Pauls code parts ...
For the OP, the input data needs
to be written like:
...
my @input = (
'DATE22/5/07',
'1/5/07',
'DATE25/5/07',
'DATENO 26/5/07',
);
...
Sorry,
M.
------------------------------
Date: Mon, 4 Jun 2007 23:25:29 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Returning substring of regex match
Message-Id: <f42769.13c.1@news.isolution.nl>
Mirco Wahab schreef:
> the input data needs
> to be written like:
>
> ...
> my @input = (
> 'DATE22/5/07',
> '1/5/07',
> 'DATE25/5/07',
> 'DATENO 26/5/07',
> );
Alternative:
my @input = split /\n/, <<'-- ';
DATE22/5/07
1/5/07
DATE25/5/07
DATENO 26/5/07
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Mon, 4 Jun 2007 21:37:01 +0000 (UTC)
From: INVALID_SEE_SIG@example.com.invalid (J.D. Baldwin)
Subject: Sending RTF email with Perl?
Message-Id: <f420lt$4le$1@reader2.panix.com>
I am trying to use a module to send an RTF email (because I need to
use color codes) from Perl. I have been using MIME::Lite to send
email attachments, but am unable to get it to send the mail itself as
RTF. I found a FAQ (not a newsgroup one) on sending HTML email:
http://www.cyberciti.biz/faq/how-do-i-send-html-email-from-perl/
and that works OK, but extrapolating their method to RTF fails. Here
is their suggestion for HTML email:
#!/usr/bin/perl -w
use strict;
use MIME::Lite;
# SendTo email id
my $email = 'user@somewhere.com';
# create a new MIME Lite based email
my $msg = MIME::Lite->new
(
Subject => 'HTML email test',
From => 'YOU@somewhere.com',
To => $email,
Type => 'text/html',
Data => '<H1>Hello</H1><br>This is a test email.
Please visit our site <a href="http://cyberciti.biz/">online</a><hr>'
);
$msg->send();
As noted, this works fine. If I change this to
#!/usr/bin/perl -w
use strict;
use MIME::Lite;
use RTF::Writer;
my $rtfstring;
my $rtf = RTF::Writer->new_to_string(\$rtfstring);
$rtf->prolog;
$rtf->printf( \'{\pard\cf1');
$rtf->printf( \'Hello, World');
$rtf->printf( \'\par}');
$rtf->close;
my $msg = MIME::Lite->new(
Subject => 'TEST RTF MESSAGE',
From => 'YOU@somewhere.com',
To => $email,
Type => 'text/rtf',
Data => $rtfstring
);
$msg->send;
... it simply doesn't work. The "raw" RTF shows up as plain text in
the email.
If anyone has any ideas along these lines, I would appreciate hearing them.
--
_+_ From the catapult of |If anyone disagrees with any statement I make, I
_|70|___:)=}- J.D. Baldwin |am quite prepared not only to retract it, but also
\ / baldwin@panix.com|to deny under oath that I ever made it. -T. Lehrer
***~~~~-----------------------------------------------------------------------
------------------------------
Date: Mon, 04 Jun 2007 19:54:17 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Sending RTF email with Perl?
Message-Id: <m2myzfuvh2.fsf@local.wv-www.com>
INVALID_SEE_SIG@example.com.invalid (J.D. Baldwin) writes:
> I am trying to use a module to send an RTF email (because I need to
> use color codes) from Perl. I have been using MIME::Lite to send
> email attachments, but am unable to get it to send the mail itself as
> RTF. I found a FAQ (not a newsgroup one) on sending HTML email:
>
> http://www.cyberciti.biz/faq/how-do-i-send-html-email-from-perl/
>
> and that works OK, but extrapolating their method to RTF fails.
...
> my $msg = MIME::Lite->new(
> Subject => 'TEST RTF MESSAGE',
> From => 'YOU@somewhere.com',
> To => $email,
> Type => 'text/rtf',
> Data => $rtfstring
> );
> $msg->send;
>
> ... it simply doesn't work. The "raw" RTF shows up as plain text in
> the email.
The MIME type for RTF isn't "text/rtf", it's "application/rtf".
> If anyone has any ideas along these lines, I would appreciate hearing them.
You may be better off sending HTML anyway - I'd expect more email clients to
understand HTML than RTF.
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Tue, 5 Jun 2007 02:26:03 +0000 (UTC)
From: INVALID_SEE_SIG@example.com.invalid (J.D. Baldwin)
Subject: Re: Sending RTF email with Perl?
Message-Id: <f42hjq$p75$1@reader2.panix.com>
In the previous article, Sherm Pendley <spamtrap@dot-app.org> wrote:
> The MIME type for RTF isn't "text/rtf", it's "application/rtf".
I tried application/rtf first, then changed it to text/rtf out of
desperation; the latter version got posted. But good catch.
> > If anyone has any ideas along these lines, I would appreciate hearing them.
>
> You may be better off sending HTML anyway - I'd expect more email clients to
> understand HTML than RTF.
The project spec is RTF.
On the other hand, I wrote the spec, and I can change it unilaterally ...
I guess I'd prefer RTF, but I can live with going to HTML if there's no
good alternative.
Thanks for the response.
--
_+_ From the catapult of |If anyone disagrees with any statement I make, I
_|70|___:)=}- J.D. Baldwin |am quite prepared not only to retract it, but also
\ / baldwin@panix.com|to deny under oath that I ever made it. -T. Lehrer
***~~~~-----------------------------------------------------------------------
------------------------------
Date: Mon, 04 Jun 2007 18:09:38 -0400
From: Bob Walton <see.sig@rochester.rr.com>
Subject: Re: Spawning other processes but continue script
Message-Id: <46648da2$0$19526$4c368faf@roadrunner.com>
SimonH wrote:
...
> What id like help with is the following....
>
> If I comment out the line..
> print `notepad`;
> Execution proceeds as expected.
> When I leave this in, it opens notepad, while the command prompt waits.
> Is there any way to spawn other processes, but continue execution of your
> original script?
Since you are running on Windows, you could use Window's own facility
for doing this:
system 'start notepad';
I'm not sure, though, what you expect nodepad to return for print() to
print?? Whatever that is, I'm sure you will find the output from
"start" to be less edifying, particularly since the backticks appear to
force print() to wait for the output despite the presence of 'start'
(tested on XP Home sp2 with Activestate Perl 5.8.8 build 819).
...
> Simon
>
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Mon, 04 Jun 2007 23:49:22 -0000
From: Paul <paul.pettus@gmail.com>
Subject: using LWP::UserAgent Get method
Message-Id: <1181000962.374723.274620@p47g2000hsd.googlegroups.com>
hi, there,
I am learning to use Perl to grab some useful information from
internet. For example to get specified web page.
I tested several web sites and the code works well. But when I tried
on www.officedepot.com, the code does not work any more. the returned
error message is always "Error1: when get http://www.officedepot.com:
500 Can't connect to www.officedepot.com:80 (connect: Unknown error)"
I have no idea what is going wrong. please help me on this
regards
paul
////
use LWP 5.64;
use LWP::UserAgent;
use HTTP::Headers;
use HTTP::Cookies;
$browser = LWP::UserAgent->new;
$browser->timeout(5);
$url ='http://www.officedepot.com';
@ns_headers = (
'Accept'=>'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, application/vnd.ms-excel, application/
vnd.ms-powerpoint, application/msword, */*',
'Accept-Language'=>'en-us',
'Accept-Encoding'=>'gzip, deflate',
'User-Agent'=>'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
SV1; .NET CLR 2.0.50727)',
'Proxy-Connection'=>'Keep-Alive',
);
$browser->cookie_jar( HTTP::Cookies->new(
'file' => 'odcookies.lwp',
# where to read/write cookies
'autosave' => 1,
# save it to disk when done
));
$response = $browser->get($url, @ns_headers);
if ($response->is_success)
{
print "Connected with server\n";
}
else
{
print "Error1: when get $url:\t" . $response->status_line . "\n";
}
------------------------------
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 483
**************************************