[32516] in Perl-Users-Digest
Perl-Users Digest, Issue: 3781 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Sep 22 09:09:19 2012
Date: Sat, 22 Sep 2012 06:09:04 -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 Sat, 22 Sep 2012 Volume: 11 Number: 3781
Today's topics:
Re: File::Path::remove_tree not working <arjenbax@googlemail.com>
Re: File::Path::remove_tree not working <allanherriman@hotmail.com>
Re: File::Path::remove_tree not working <arjenbax@googlemail.com>
Re: File::Path::remove_tree not working <ben@morrow.me.uk>
Re: File::Path::remove_tree not working <kaz@kylheku.com>
Re: https request failing <rvtol+usenet@xs4all.nl>
Re: Setting backreference inside of a string <rvtol+usenet@xs4all.nl>
slurp with pattern match <bjlockie@lockie.ca>
Re: slurp with pattern match <rweikusat@mssgmbh.com>
Re: slurp with pattern match <glex_no-spam@qwest-spam-no.invalid>
Re: slurp with pattern match <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 19 Sep 2012 23:27:55 -0700 (PDT)
From: ilovelinux <arjenbax@googlemail.com>
Subject: Re: File::Path::remove_tree not working
Message-Id: <351b7582-2b7c-4809-839f-2b7a4e0b1a82@googlegroups.com>
> my $tempdir =3D tempdir( CLEANUP =3D> 1 );
> remove_tree($tempdir, { safe =3D> 0 });
Smells like somethnig weird in the Cygwin layer. I once encountered a simil=
ar error: the Cygwin perl script removed some files but they stayed visible=
from an Explorer view in another window, until the perl script finished: o=
nly then the removed files disappeared.
Did you try removing the files by hand-crafted code? Something like this:
for (glob("$tempdir/*")) {
print "removing $_: ";
if (unlink($_)) {
print "OK\n";
} else {
print "ERR ($!)\n";
}
}
------------------------------
Date: 21 Sep 2012 11:44:11 GMT
From: Allan Herriman <allanherriman@hotmail.com>
Subject: Re: File::Path::remove_tree not working
Message-Id: <505c530b$0$11097$c3e8da3@news.astraweb.com>
On Wed, 19 Sep 2012 23:27:55 -0700, ilovelinux wrote:
>> my $tempdir = tempdir( CLEANUP => 1 );
>> remove_tree($tempdir, { safe => 0 });
>
> Smells like somethnig weird in the Cygwin layer. I once encountered a
> similar error: the Cygwin perl script removed some files but they stayed
> visible from an Explorer view in another window, until the perl script
> finished: only then the removed files disappeared.
>
> Did you try removing the files by hand-crafted code? Something like
> this:
>
> for (glob("$tempdir/*")) {
> print "removing $_: ";
> if (unlink($_)) {
> print "OK\n";
> } else {
> print "ERR ($!)\n";
> }
> }
I even tried rm -rf and that didn't work, which I found rather surprising.
> Smells like somethnig weird in the Cygwin layer.
It turns out that in Cygwin paths starting with /tmp/ get magically
redirected to c:/cygwin/tmp/
I cannot imagine a universe where that would be a good idea, but
apparently the Cygwin authors thought it was.
tempdir returns /tmp/something, and this gets interpreted as
c:/tmp/something by some parts of my script and as
c:/cygwin/tmp/something by other parts of my script (including tempdir
itself).
tempdir does in fact clean up its directory, but not the directory I
thought it was using.
My ugly, non-portable and fragile workaround is to chdir to c: then
prepend the temp directory name with c: before I use it.
Regards,
Allan
------------------------------
Date: Fri, 21 Sep 2012 07:18:34 -0700 (PDT)
From: ilovelinux <arjenbax@googlemail.com>
Subject: Re: File::Path::remove_tree not working
Message-Id: <4dcf6cfe-f6f1-4ec0-ac90-35dc50b3668c@googlegroups.com>
> It turns out that in Cygwin paths starting with /tmp/ get magically
> redirected to c:/cygwin/tmp/
Not if you mount it yourself. My /etc/fstab (Cygwin) contains
c:/temp /tmp some_fs binary 0 0
d:/Users /home some_fs binary 0 0
none / cygdrive binary,posix=0,user 0 0
The top line forces all accesses of /tmp to use the c:/temp directory.
HTH
------------------------------
Date: Fri, 21 Sep 2012 18:16:48 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: File::Path::remove_tree not working
Message-Id: <01kui9-08k2.ln1@anubis.morrow.me.uk>
Quoth Allan Herriman <allanherriman@hotmail.com>:
>
> It turns out that in Cygwin paths starting with /tmp/ get magically
> redirected to c:/cygwin/tmp/
> I cannot imagine a universe where that would be a good idea, but
> apparently the Cygwin authors thought it was.
This is usual Cygwin behaviour: in fact, it's one of the main reasons to
use Cygwin in the first place. If you don't like it, why aren't you just
using ordinary Win32 perl?
(Personally, I wouldn't touch Cygwin with a ten-foot pole.)
Ben
------------------------------
Date: Fri, 21 Sep 2012 19:29:10 +0000 (UTC)
From: Kaz Kylheku <kaz@kylheku.com>
Subject: Re: File::Path::remove_tree not working
Message-Id: <20120921122513.405@kylheku.com>
On 2012-09-21, Ben Morrow <ben@morrow.me.uk> wrote:
>
> Quoth Allan Herriman <allanherriman@hotmail.com>:
>>
>> It turns out that in Cygwin paths starting with /tmp/ get magically
>> redirected to c:/cygwin/tmp/
>> I cannot imagine a universe where that would be a good idea, but
>> apparently the Cygwin authors thought it was.
>
> This is usual Cygwin behaviour: in fact, it's one of the main reasons to
> use Cygwin in the first place.
One of the main reasons for using Cygwin is where it sticks /tmp?
------------------------------
Date: Wed, 19 Sep 2012 17:02:24 +0200
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: https request failing
Message-Id: <5059de80$0$6975$e4fe514c@news2.news.xs4all.nl>
On 2012-09-18 10:35, mike wrote:
> use LWP::UserAgent;
> use LWP::Debug qw(+);
>
> #create User-agent
> my $ua = LWP::UserAgent->new;
>
> $ua->no_proxy("<internalsite>.se");
>
>
> my $url = "http://<internalsite>.se/org.testng.eclipse/site.xml";
The cut lines can be replaced by:
my $res= $ua->get( $url );
> # check the outcome
> if ($res->is_success) {
> print $res->decoded_content;
> }
> else {
> print "Error: " . $res->status_line . "\n";
> }
Also print Dumper( $res ) for details.
--
Ruud
------------------------------
Date: Wed, 19 Sep 2012 17:05:45 +0200
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: Setting backreference inside of a string
Message-Id: <5059df49$0$6975$e4fe514c@news2.news.xs4all.nl>
On 2012-09-10 08:41, Jason C wrote:
> I'm doing a replace, like this:
>
> $text = "Yes dear!";
> $pattern = "(D|d)ear";
> $replace = "$1eer";
>
> $text =~ s/$pattern/$replace/gi;
>
> That's just an example, of course; the real $pattern and $replace come from a database list, and $text comes from form data.
>
> The problem I'm having is that the replace is replacing with a literal "$1eer", instead of setting the $1 to (D|d). Meaning, instead of printing:
>
> Yes deer!
>
> I'm printing:
>
> Yes $1eer!
>
> Any suggestions on how to make $1 in $replace refer to the first group in $pattern?
Check out Template::Toolkit. Etc.
--
Ruud
------------------------------
Date: Thu, 20 Sep 2012 12:56:43 -0700 (PDT)
From: bjlockie <bjlockie@lockie.ca>
Subject: slurp with pattern match
Message-Id: <9eb64fe0-daf4-4137-ad84-d8dadd304d11@googlegroups.com>
my @checkOutput = ();
if (open( FILE, $inputFilePath . '/checkOutput' )) {
@checkOutput = <FILE>;
close( FILE );
}
I want to slurp only lines that match a pattern.
Can I still slurp or do I need to loop each line?
------------------------------
Date: Thu, 20 Sep 2012 21:05:14 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: slurp with pattern match
Message-Id: <87mx0ka29x.fsf@sapphire.mobileactivedefense.com>
bjlockie <bjlockie@lockie.ca> writes:
> my @checkOutput = ();
Perl variables don't need to be initialized explicitly. In some pretty
accidental looking circumstances, perl might print warnings when an
automatic conversion of a scalar without a value to a string or an
integer occurs. But even this doesn't apply here because the value of
@checkOutput is an empty array. There's no point in emptying that by
assigning an empty list to it.
> if (open( FILE, $inputFilePath . '/checkOutput' )) {
> @checkOutput = <FILE>;
> close( FILE );
> }
>
> I want to slurp only lines that match a pattern.
> Can I still slurp or do I need to loop each line?
You could use grep here:
@checkOutput = grep { /pattern/ } <FILE>;
------------------------------
Date: Thu, 20 Sep 2012 17:06:34 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: slurp with pattern match
Message-Id: <505b936a$0$63195$815e3792@news.qwest.net>
On 09/20/12 14:56, bjlockie wrote:
> my @checkOutput = ();
> if (open( FILE, $inputFilePath . '/checkOutput' )) {
> @checkOutput =<FILE>;
> close( FILE );
> }
>
> I want to slurp only lines that match a pattern.
> Can I still slurp or do I need to loop each line?
Many ways..
Using File::Slurp.
use File::Slurp;
my $file = "$inputFilePath/checkOutput";
my @checkOutput = grep { /blah/ } read_file( $file );
or maybe the file is really large and you don't want to 'slurp'..
my $file = "$inputFilePath/checkOutput";
open( my $out, '<', $file ) || die "Can't open $file: $!";
my @checkOutput;
while( <$out> )
{
push( @checkOutput, $_ ) if /blah/;
}
close( $out );
or make that while a bit more compact..
my @checkOutput = grep { /blah/ } <$out>;
or if you're on a Unix machine and your pattern can be done
using grep from the OS.
open( FH, "/bin/grep 'blah' $inputFilePath/checkOutput |" )
|| die "Can't grep $file: $!";
my @checkOutput = <FH>;
close( FH );
------------------------------
Date: Fri, 21 Sep 2012 00:12:40 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: slurp with pattern match
Message-Id: <8gksi9-7f92.ln1@anubis.morrow.me.uk>
Quoth "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>:
> On 09/20/12 14:56, bjlockie wrote:
> >
> > I want to slurp only lines that match a pattern.
> > Can I still slurp or do I need to loop each line?
<snip>
>
> or maybe the file is really large and you don't want to 'slurp'..
>
> my $file = "$inputFilePath/checkOutput";
> open( my $out, '<', $file ) || die "Can't open $file: $!";
> my @checkOutput;
> while( <$out> )
> {
> push( @checkOutput, $_ ) if /blah/;
> }
> close( $out );
>
> or make that while a bit more compact..
>
> my @checkOutput = grep { /blah/ } <$out>;
This variant reads all the lines of the file into a list before passing
that list to grep, so it isn't suitable for huge files either.
The most memory-efficient option is
while (<$out>) {
/blah/ or next;
# process the line immediately, then throw it away
}
Ben
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 3781
***************************************