[32788] in Perl-Users-Digest
Perl-Users Digest, Issue: 4052 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 9 09:09:38 2013
Date: Wed, 9 Oct 2013 06:09:03 -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 Wed, 9 Oct 2013 Volume: 11 Number: 4052
Today's topics:
Re: mixed cmp operator for sorting <willem@turtle.stack.nl>
using File::Spec effectively <cal@example.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 9 Oct 2013 11:09:46 +0000 (UTC)
From: Willem <willem@turtle.stack.nl>
Subject: Re: mixed cmp operator for sorting
Message-Id: <slrnl5aebq.vkl.willem@turtle.stack.nl>
John W. Krahn wrote:
) Willem wrote:
)> Marc Girod wrote:
)> ) On Monday, 23 September 2013 08:30:46 UTC+1, John W. Krahn wrote:
)> )
)> )> my @t = $a =~ /\D+|\d+/g;
)> )> my @s = $b =~ /\D+|\d+/g;
)> )>
)> )> Avoids zero length strings.
)> )
)> ) Indeed, but it implies other changes in the following.
)>
)> my @t = split /(\d+)/, $a;
)> my @s = split /(\d+)/, $a;
)>
)> Avoids both issues.
)
) $ perl -le'use Data::Dumper; my $a = "12345"; my @t = split /(\d+)/, $a;
) print Dumper \@t'
) $VAR1 = [
) '',
) '12345'
) ];
)
)
) Not, it appears, zero length strings.
'12345' is not a zero length string.
The original code expects the numbers to always be in even positions,
so in fact it works exactly as required.
Which is what was meant by "it implies other changes in the following."
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
------------------------------
Date: Wed, 09 Oct 2013 03:32:54 -0700
From: Cal Dershowitz <cal@example.invalid>
Subject: using File::Spec effectively
Message-Id: <FcadnXwdPe1OrcjPnZ2dnUVZ_oGdnZ2d@supernews.com>
I'd like to be able to specify paths in a more platform-independent way
so as at least to be able to develop on windows and *nix and realized
that slashes for finding subdirectories would either be pointing the
right way or the wrong, where the "or" is exclusive. So it is that I've
tried to cobble together what a person might do.
This template is close to being complete for a limited case. Right now,
the captions don't match up to images, but that is not something that
will elude me for too long, since I got it before in a less-general context.
What one seems to have to do is build a path using catfile and append
the system's representation of root. Is that what a person is supposed
to do?
http://merrillpjensen.com/pages/keystone3.html
$ perl keystone2.pl
Net::FTP>>> Net::FTP(2.77)
...
Net::FTP=GLOB(0x9cc800c)<<< 226 Transfer complete
old num is 2
rootdir is /
path1 is template_stuff/
specifier is <img src="http://www.merrillpjensen.com/images/%s"/>
%s
Net::FTP=GLOB(0x9cc800c)>>> CWD /pages
...
Net::FTP=GLOB(0x9cc800c)<<< 226 Transfer complete
cur dir is .
word2 is .
dev null is /dev/null
new file is
keystone3.html
$ cat keystone2.pl
#!/usr/bin/perl -w
use strict;
use lib "template_stuff";
use MySubs1 qw(get_ftp_object get_html_filename print_hash);
use MySubs2 qw(create_html_file write_header
write_footer);
use MySubs3 qw( get_content );
use Cwd;
use File::Basename;
use Net::FTP;
use File::Spec;
use File::Slurp;
my $dir = cwd;
my ($volume,$directories,$current) =
File::Spec->splitpath( $dir );
my $rftp = get_ftp_object;
my $html_file = get_html_filename($rftp);
open( my $fh, ">:utf8", $html_file )
or die("Can't open $html_file for writing: $!");
# page params
my $template_dir = "template_stuff";
my $rootdir = File::Spec->rootdir();
print "rootdir is $rootdir\n";
my $path_patch = $template_dir.$rootdir;
print "path1 is $path_patch\n";
my %vars = (
title => $current,
headline => "A rebus template",
place => 'Oakland',
css_file => "${current}1.css",
header => $path_patch."hc_input2.txt",
footer => $path_patch."footer_center.txt",
css_local => "rad1.css",
body => $path_patch."rebus1.tmpl",
);
my $path1 = File::Spec->catfile( $directories, $current, $template_dir,
$vars{"css_local"});
#print "path is $path1\n";
my $rvars = \%vars;
my $rhdr = write_header($rvars);
print $fh $$rhdr;
#main control
my $specifier = read_file( $vars{"body"} ) ;
print "specifier is $specifier\n";
my $refc = get_content($template_dir);
#print_hash($refc);
my %content = %$refc;
#main control
foreach my $key (sort keys %content) {
my (undef,undef,$dummy) = File::Spec->splitpath( $key );
printf $fh $specifier, $dummy, $content{$key};
}
my $rftr = write_footer($rvars);
print $fh $$rftr;
close $fh;
#load to server
$rftp->cwd("/pages") or warn "cwd failed $@\n";
$rftp->put($html_file) or die "put failed $@\n";
$rftp->cwd("/css") or warn "cwd failed $@\n";
$rftp->put($path1, $vars{"css_file"}) or warn "put failed $@\n";
#load images
$rftp->binary();
$rftp->cwd("/images") or warn "cwd failed $@\n";
foreach my $key (keys %content) {
my (undef,undef,$remote_file) = File::Spec->splitpath( $key );
print "remote file is $remote_file\n";
$rftp->put($key, $remote_file) or warn "put failed $@\n";
}
# file spec stuff
my $curdir = File::Spec->curdir();
print "cur dir is $curdir\n";
my $word2 = basename($curdir);
print "word2 is $word2\n";
my $devnull = File::Spec->devnull();
print "dev null is $devnull\n";
print "new file is \n";
print "$html_file\n";
$
Anyways, I make a few extraneous calls with File::Spec methods just to
see what they look like on this linux machine. I was, for example, a
little surprised that curdir() returns a dot, but when you see it as
repeated output in your terminal, it's less-startling.
Fishing for comments in general from people who maybe have more than a
week's exposure to this. Tomorrow, I'll try running this on a windows
machine and see how badly it insults me.
Thanks for your comment,
--
Cal Dershowitz
------------------------------
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 4052
***************************************