[29698] in Perl-Users-Digest
Perl-Users Digest, Issue: 942 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 16 21:10:34 2007
Date: Tue, 16 Oct 2007 18:09:12 -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 Tue, 16 Oct 2007 Volume: 11 Number: 942
Today's topics:
Re: "copy" from File::Copy fails but returns success <news@lawshouse.org>
Re: "copy" from File::Copy fails but returns success <spamtrap@dot-app.org>
Re: Inline regex <wahab@chemie.uni-halle.de>
Re: Inline regex <spamtrap@dot-app.org>
Re: Inline regex <uri@stemsystems.com>
Re: Inline regex <abigail@abigail.be>
Re: Inline regex <abigail@abigail.be>
Re: Inline regex <bik.mido@tiscalinet.it>
Re: Inline regex <bik.mido@tiscalinet.it>
Re: Inline regex <abigail@abigail.be>
Re: Inline regex <bik.mido@tiscalinet.it>
Re: Inline regex <bik.mido@tiscalinet.it>
Re: Inline regex <bik.mido@tiscalinet.it>
Re: Inline regex <noreply@gunnar.cc>
Re: Inline regex <tadmc@seesig.invalid>
Re: Inline regex <tadmc@seesig.invalid>
Re: jabba the tuh <bik.mido@tiscalinet.it>
Re: jabba the tuh <zaxfuuq@invalid.net>
Re: line 16 <jurgenex@hotmail.com>
Re: line 16 <zaxfuuq@invalid.net>
Re: Regular Expression $1? <Jeff.Stampes@xilinx.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 16 Oct 2007 20:15:10 +0100
From: Henry Law <news@lawshouse.org>
Subject: Re: "copy" from File::Copy fails but returns success
Message-Id: <1192562106.35927.0@demeter.uk.clara.net>
Josef Moellers wrote:
> Obviously, /tmp/nfb isn't a directory.
Danke sehr, Josef; and thanks to Brian, Paul and Ben for the same
observation and for the useful improvements.
Do you know how many times I've looked at that "ls" output, and
_completely_ failed to see that it had no "d" at the beginning? There's
none so blind as them that thinks they know what they see.
But that's the benefit of having other people help you with your problem.
--
Henry Law Manchester, England
------------------------------
Date: Tue, 16 Oct 2007 15:37:59 -0400
From: Sherman Pendley <spamtrap@dot-app.org>
Subject: Re: "copy" from File::Copy fails but returns success
Message-Id: <m17ilmrgtk.fsf@dot-app.org>
Henry Law <news@lawshouse.org> writes:
> The source file exists and is chmod 777. The result from the code above is
>
> Return code:1
> -rw-r--r-- 1 apache apache 5 Oct 16 09:34 /tmp/nfb
>
> ... which shows that the copy succeeded (return code 1) but the file
> is nevertheless not in the target directory /tmp/nfb. I'm baffled.
The above also shows that /tmp/nfb is not a directory - it's a file. The
last component of the destination path is only interpreted as a directory
if that directory already exists; otherwise it's treated as a filename.
> Any ideas?
Check for the existence of the /tmp/nfb directory before you do the copy,
and create it if necessary.
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Tue, 16 Oct 2007 20:12:30 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: Inline regex
Message-Id: <ff2uug$2hpt$1@nserver.hrz.tu-freiberg.de>
Christian Winter wrote:
> I tend to shun a map without use of its return values like
> the devil the holy water, as the same can be accomplished
> with a for loop, and the intention is clearer to whoever
> gets to maintain my code.
>
> s/\s+$// for @line;
Where the 'map' would (imho) make sense:
...
my @trimmed = map /\s+$/ ? substr($_,0,$-[0]) : $_, @line;
...
(anybody interested in banchmarking the
non-modifying varieties ;-)
Regards
Mirco
------------------------------
Date: Tue, 16 Oct 2007 15:40:31 -0400
From: Sherman Pendley <spamtrap@dot-app.org>
Subject: Re: Inline regex
Message-Id: <m13awargpc.fsf@dot-app.org>
steve <steve@nospamtoday.com> writes:
> I am currently working on a small script that parses text files and
> outputs them in a different format, to be used by another program. I
> am constantly removing trailing whitespace like so:
>
> $desc = $line[7]; # @line is an array derived from a line in a CSV file
> $desc =~ s/\s+$//g; # Trim trailing whitespace
>
> But this is in two lines. How can I copy the variable and remove
> whitespace in one line of code?
Why not simply chomp() the line before splitting it into fields?
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Tue, 16 Oct 2007 20:12:59 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Inline regex
Message-Id: <x78x626col.fsf@mail.sysarch.com>
>>>>> "MW" == Mirco Wahab <wahab@chemie.uni-halle.de> writes:
MW> Where the 'map' would (imho) make sense:
MW> ...
MW> my @trimmed = map /\s+$/ ? substr($_,0,$-[0]) : $_, @line;
MW> ...
why the extra code? just grab the text before the trailing spaces (untested):
my @trimmed = map /^(.*?)\s*$/, @line;
note the use of * in both parts as either can be empty. dunno if this
will run fast or slow due to the double use of *. but as i said in
another thread, trimming white space is so trivial in perl so why waste
effort on doing it in different ways.
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: 16 Oct 2007 22:11:51 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: Inline regex
Message-Id: <slrnfhadp7.21q.abigail@alexandra.abigail.be>
_
steve (steve@nospamtoday.com) wrote on VCLIX September MCMXCIII in
<URL:news:9v5Ri.161448$6L.155799@fe03.news.easynews.com>:
##
## Another quick question...
## I have a variable that is padded with leading zeros (e.g. "0001.125"). I
## want to be able to remove all leading zeros if the value >= 1 ("1.125"),
## but leave one leading zero if the value < 1 (e.g. "0000.125" should
## become "0.125" not ".125"). Can I do this with one regex?
Yes.
What have you tried so far?
Abigail
--
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'
------------------------------
Date: 16 Oct 2007 22:14:33 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: Inline regex
Message-Id: <slrnfhadu9.21q.abigail@alexandra.abigail.be>
_
Brian McCauley (nobull67@gmail.com) wrote on VCLIX September MCMXCIII in
<URL:news:1192554846.495504.129670@t8g2000prg.googlegroups.com>:
-: On Oct 16, 4:26 pm, Abigail <abig...@abigail.be> wrote:
-:
-: > Or, if I have to write it in one line, my first preference would be:
-: >
-: > $desc = $line [7]; $desc =~ s/\s+$//; # No need for /g.
-: >
-: > Second choice:
-: >
-: > ($desc = $line [7]) =~ s/\s+$//; # No need for /g.
-: >
-:
-: If you really don't like the above format I have some syntactic sugar
-: for you.
-:
-: use List::MoreUtils qw ( apply );
-: my $desc = apply { s/\s+$// } $line[7];
That's two lines!
my ($desc) = map {local $_ = $_; s/\s+$//; $_} $line [7];
Abigail
--
perl -wle'print"Êõóô áîïôèåò Ðåòì Èáãëåò"^"\x80"x24'
------------------------------
Date: Wed, 17 Oct 2007 00:17:24 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Inline regex
Message-Id: <8sdah3hlin5jfn24uqf55v6rfd18jopdqp@4ax.com>
On Tue, 16 Oct 2007 15:22:48 -0000, it_says_BALLS_on_your forehead
<simon.chao@fmr.com> wrote:
>my @trimmed = map { s/\s+$// } @line;
Nope!
my @trimmed map { (my $t=$_) =~ s/\s+$//; $t } @line;
We don't have the subst() method yet.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Wed, 17 Oct 2007 00:19:32 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Inline regex
Message-Id: <b4eah354mrsidlg6srj6fjdi2od32qc906@4ax.com>
On Tue, 16 Oct 2007 16:51:36 -0000, it_says_BALLS_on_your forehead
<simon.chao@fmr.com> wrote:
>stupid mistake :-(.
>
>my @trimmed = map { s/\s+$//; $_ } @line;
Stupid Mistake II the Revenge: you will modify @line too, which may be
what you want or not, but generally isn't. In that case you would just
s/\s+$// for @line;
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 16 Oct 2007 22:20:13 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: Inline regex
Message-Id: <slrnfhae8t.21q.abigail@alexandra.abigail.be>
_
Christian Winter (thepoet_nospam@arcor.de) wrote on VCLIX September
MCMXCIII in <URL:news:4714f98b$0$16113$9b4e6d93@newsspool1.arcor-online.net>:
&& it_says_BALLS_on_your forehead schrieb:
&& >
&& > OR, if you WANT to change the original @line:
&& >
&& > map { s/\s+$// } @line;
&& >
&& > (not sure, but i believe that map in void context is fine in >= 5.8.7,
&& > correct?)
&&
&& I tend to shun a map without use of its return values like
&& the devil the holy water, as the same can be accomplished
&& with a for loop,
What a Pythonesque argument!
Considering anything you can do with 'for' can be done with 'while'
as well, and anything you can do with 'while' can be done with 'for',
which of the two do you stay away from?
Of course, if you use both 'for' and 'while' I don't think this argument
carries any significant weight.
&& and the intention is clearer to whoever
&& gets to maintain my code.
That's in the eye of the beholder.
&& s/\s+$// for @line;
If the intention is write clear code for "whoever gets to maintain my code",
using the aliasing behaviour of 'for' in combination with the implicite
use of $_ twice, wouldn't be high on my list.
Abigail
--
BEGIN {$^H {q} = sub {pop and pop and print pop}; $^H = 2**4.2**12}
"Just "; "another "; "Perl "; "Hacker\n";
------------------------------
Date: Wed, 17 Oct 2007 00:20:36 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Inline regex
Message-Id: <e8eah3lfip2b0q2fek8l3f21h4rfsdspe6@4ax.com>
On Tue, 16 Oct 2007 17:32:21 -0000, it_says_BALLS_on_your forehead
<simon.chao@fmr.com> wrote:
>> my @trimmed = map { my $val = $_; $val =~ s/\s+$//; $val } @line;
>
>OR, if you WANT to change the original @line:
>
>map { s/\s+$// } @line;
>
>(not sure, but i believe that map in void context is fine in >= 5.8.7,
>correct?)
It is fine but considered bad, for good reasons. You would use C<for>
in that case, since that's exactly what it's... for!
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Wed, 17 Oct 2007 00:23:49 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Inline regex
Message-Id: <3feah35v7sfa9bp07uqmlh0dvp4ftt5881@4ax.com>
On Tue, 16 Oct 2007 16:17:50 GMT, steve <steve@nospamtoday.com> wrote:
>Wow, thanks for the quick response, that works nicely.
>
>Another quick question...
Then you'd probably better start a new thread...
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Wed, 17 Oct 2007 01:16:46 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Inline regex
Message-Id: <lchah3l08lpr7c5urm8587qregtumsm6su@4ax.com>
On 16 Oct 2007 22:14:33 GMT, Abigail <abigail@abigail.be> wrote:
>That's two lines!
>
> my ($desc) = map {local $_ = $_; s/\s+$//; $_} $line [7];
I often use C<local $_> myself, but I'm somewhat wary about it since
clpmisc informed me that it can be buggy with tied stuff, althoug I
doubt that $line [7] will contain any.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Wed, 17 Oct 2007 01:49:26 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Inline regex
Message-Id: <5nl10lFilc7fU1@mid.individual.net>
Michele Dondi wrote:
> On 16 Oct 2007 22:14:33 GMT, Abigail <abigail@abigail.be> wrote:
>
>> That's two lines!
>>
>> my ($desc) = map {local $_ = $_; s/\s+$//; $_} $line [7];
>
> I often use C<local $_> myself, but I'm somewhat wary about it since
> clpmisc informed me that it can be buggy with tied stuff,
Isn't that why it's better written
my ($desc) = map { local *_ = \$_; s/\s+$//; $_ } $line[7];
-----------------------------^----^
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 17 Oct 2007 00:36:37 GMT
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Inline regex
Message-Id: <slrnfhalie.miu.tadmc@tadmc30.sbcglobal.net>
steve <steve@nospamtoday.com> wrote:
> Christian Winter wrote:
>> steve wrote:
>>> am constantly removing trailing whitespace like so:
>> (my $desc = $line[7]) =~ s/\s+$//;
> Would the code you suggested remove the whitespace from $line[7] as well?
What happened when you tried it?
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Wed, 17 Oct 2007 00:36:37 GMT
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Inline regex
Message-Id: <slrnfhalsd.miu.tadmc@tadmc30.sbcglobal.net>
steve <steve@nospamtoday.com> wrote:
> Another quick question...
Then you should start a new thread.
> I have a variable that is padded with leading zeros (e.g. "0001.125"). I
> want to be able to remove all leading zeros if the value >= 1 ("1.125"),
> but leave one leading zero if the value < 1 (e.g. "0000.125" should
> become "0.125" not ".125"). Can I do this with one regex?
$num =~ s/^0+(\d)/$1/;
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Wed, 17 Oct 2007 00:10:25 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: jabba the tuh
Message-Id: <1mdah3lrvd71sgvojh0jp613hbc8b9h4k6@4ax.com>
On Tue, 16 Oct 2007 17:27:59 GMT, "Jürgen Exner"
<jurgenex@hotmail.com> wrote:
>No, not confusing at all. After all ppl is clearly the abbreviation for
>Private Pilot License. Although I have no idea what a PPL has possibly to do
>with this NG.
>
>Oh, and I believe in some baby talk it stands for 'people', too. Although
Yeah, kidiots use it in that acceptation.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Tue, 16 Oct 2007 17:39:11 -0700
From: "Wade Ward" <zaxfuuq@invalid.net>
Subject: Re: jabba the tuh
Message-Id: <lbednT0-WvEE1ojanZ2dnUVZ_jmdnZ2d@comcast.com>
"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:fC6Ri.4670$Oy1.936@trndny08...
> Wade Ward wrote:
> [...]
>> comment3) My output for this is:
> [...]
>> jabba the tuh from "Wade Ward" zaxfuuq@invalid.net
>
>> question 1) How do I use the ppl to get "jabba the hut" as output.
>
> I have no idea how to use either a Private Pilot License (PPL) or the
> people (ppl) to get that output.
> However in Perl you could just split() on the space and then reverse() the
> last substring to convert 'tuh' to 'hut'.
We meet at last.
I'll give the above a try. Thanks for your attention.
--
wade ward
"Nicht verzagen, Bruder Grinde fragen."
------------------------------
Date: Tue, 16 Oct 2007 19:46:11 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: line 16
Message-Id: <7y8Ri.1556$tX1.1216@trndny05>
Wade Ward wrote:
[...]
> die "Failed to retrieve message ids\n" unless @{$msg_ids_ref};
[...]
> q3) Why does perl.exe not like line 16? I've correceted this before
> but forget how. Thanks in advance.
Can't repro your problem.
C:\tmp>perl -c t.pl
t.pl syntax OK
What error message are you getting?
BTW: would have been nice to include the error message right away as well as
to point out which line is line 16.
jue
------------------------------
Date: Tue, 16 Oct 2007 17:27:06 -0700
From: "Wade Ward" <zaxfuuq@invalid.net>
Subject: Re: line 16
Message-Id: <HMydnR0FB7FY1YjanZ2dnUVZ_uuqnZ2d@comcast.com>
"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:7y8Ri.1556$tX1.1216@trndny05...
> Wade Ward wrote:
> [...]
>> die "Failed to retrieve message ids\n" unless @{$msg_ids_ref};
> [...]
>> q3) Why does perl.exe not like line 16? I've correceted this before
>> but forget how. Thanks in advance.
>
> Can't repro your problem.
> C:\tmp>perl -c t.pl
> t.pl syntax OK
> What error message are you getting?
>
> BTW: would have been nice to include the error message right away as well
> as to point out which line is line 16.
I got the upper hand on this one already. It was the use of the newnews
method that is unsupported by comcast.
--
wade ward
"Nicht verzagen, Bruder Grinde fragen."
------------------------------
Date: Tue, 16 Oct 2007 12:47:39 -0600
From: Jeff Stampes <Jeff.Stampes@xilinx.com>
Subject: Re: Regular Expression $1?
Message-Id: <ff310c$8p71@cnn.xilinx.com>
Yang wrote:
> I want to get everything between () in the file, say (5), (6), so I
> wrote the following:
Not exactly, the following doesn't compile.
> while(my $line = <FIN>){
> chomp $line;
> if($line =~ /\(\d*\)/{
> print $1;
> }
> }
>
> But it always returns error saying that $1 is uninitialized.
It would be helpful to provide an example of your data as well.
IAC, I won't give you any fish, but here's a line and a pole:
You get the capture variables ($1, $2, $3, etc) by capturing things in
sets of parentheses. Where are the parentheses in your regexp that
would be doing the capturing?
~Jeff
------------------------------
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 942
**************************************