[32782] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4046 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Sep 28 16:09:31 2013

Date: Sat, 28 Sep 2013 13:09:02 -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, 28 Sep 2013     Volume: 11 Number: 4046

Today's topics:
    Re: perl hash utilities <ben@morrow.me.uk>
    Re: utilities in perl <cal@example.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sat, 28 Sep 2013 00:34:23 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: perl hash utilities
Message-Id: <v8hhha-1s81.ln1@anubis.morrow.me.uk>


Quoth Cal Dershowitz <cal@example.invalid>:
> On 09/26/2013 03:45 PM, Uri Guttman wrote:
> 
> > use File::Slurp ;
> > my %domain = %{ eval read_file( \*DATA ) } ;
> >
> > even better, drop the outer {} in DATA as it is not needed. then you
> > don't need the %{} dereference.
> 
[...]
> {
>       my_ftp =  {
>             domain   =>  'fakename',
>             username =>  'fakeuser',
>             password =>  'fakepass',
>            },
> 
>      yoursky = {
>             domain   =>  'http://www.fourmilab.ch/yoursky/',
>             language =>  'russian',
>             word =>  'north',
>            },
> }
> 
> $
> 
> If I drop the braces, I get a syntax error.  If I replace them with 
> parens, I get a syntax error.

There's a syntax error there anyway. (Well, perl thinks it's a bad
assignment rather than a syntax error.)

> Looked at file;;slurp stuff on cpan.  I think I call with references 
> correctly, but this is fresh from a reading it.  Do you have a 
> suggestion for a good way to google for file::slurp examples or find 
> them on the web by some other means?  (I like using usenet because it's 
> public, but it's not like there isn't the rest of net now.)

RTF perldoc? In simple cases like this it's not exactly a complicated
module to use: that's the whole point.

Ben



------------------------------

Date: Fri, 27 Sep 2013 19:15:42 -0700
From: Cal Dershowitz <cal@example.invalid>
Subject: Re: utilities in perl
Message-Id: <5ridna19zqBWptvPnZ2dnUVZ_vydnZ2d@supernews.com>

On 09/22/2013 04:22 AM, $Bill wrote:
> On 9/22/2013 00:58, Cal Dershowitz wrote:
>>
>> Cool, cool, $Bill I believe we're new to each other.  I like that you
>> identified yourself with an 'S' which is how some people describe the
>> dollar sign thingy.  Perl makes for a very interesting program
>> language for people who aren't afraid to talk about "s underscore" in
>> public. Some people say "sigil."
>
> The $ actually stands for a '1' and an 'S' superimposed (from my days
> as a computer operator many decades ago - meaning '1st shift' - and
> used to initial run requests in the tiny little initials box).

Are you pulling my leg?
>
>> I took your script and will fire it up once I get wireless
>> connectivity for my linux box again.  I'm not at that level of
>> maturity where I can be dancing around on the terminal and downloading
>> cpan where I simply cannot.
>
> Should work on UNIX or Windows.

$ perl get_file10.pl
subroutine says this is your hash:
key: 
/home/fred/Documents/root/pages/moxie/template_stuff/images/130721_0004.jpg, 
value: <p class="hft-paras">These are commands I constantly us but can 
never remember when I want to.</p>

<p class="hft-paras">Paras set to one now.</p>

key: 
/home/fred/Documents/root/pages/moxie/template_stuff/images/130721_0003.jpg, 
value: <p class="hft-paras">This shows three different ways to get lines 
35 to 38 in a file called bc1.pl.  This script is new and is supposed to 
take the hyperlink I post right here, and expand it properly to html: <a 
href="http://www.youtube.com/watch?v=6qBwCmhIHq0" 
class="hft-urls">http://www.youtube.com/watch?v=6qBwCmhIHq0</a> . 
Everywhere we hear the sounds of revolution; we just don&#39;t see any. </p>

<p class="hft-paras">The square root of 3 is  Washington&#39;s birthday: 
1732.</p>

$ cat get_file10.pl
#!/usr/bin/perl -w
use strict;
use File::Basename;
use Cwd;
use HTML::FromText;
use File::Slurp;
use Data::Dumper;
my $path_to_caps = 'template_stuff/captions/';
my $path_to_images = 'template_stuff/images/';
my $base = getcwd;
my $path = "$base\/$path_to_caps";
my $path2 = "$base\/$path_to_images";
my @files = <$path*>;
my @matching;
my $ref_to_matching = \@matching;
while ($_ = pop @files) {
next if /~$/;
next if -d;
next unless -T;
push(@matching, $_);
}
#important to sort
@matching = sort @matching;
my %hash1 = map {$_ => 1 } @matching;
my $ref_to_caps = \%hash1;
my @filetypes = qw/jpg gif png/;
my @images = <$path2*>;
my $pattern = join '|', map "($_)", @filetypes;
my @matching2;
while ($_ = pop @images) {
if ($_ =~ /($pattern)$/i) {
    push(@matching2, $_);
    }
}
#important to sort
@matching2 = sort @matching2;
my %hash2 = map {$_ => 1 } @matching2;
while ( (my $key,my $value) = each %hash1 )
{
    my $string = read_file($key);
    my $kludge = text2html(
       $string,
       urls  => 1,
       email => 1,
       paras => 1,
    );
    $hash1{$key} = $kludge;
}
sub print_hash{
    print "subroutine says this is your hash: \n";
    my $hash_ref = shift;
    my %hash = %$hash_ref;
    while ( (my $key,my $value) = each %hash )
    {
       print "key: $key, value: $hash{$key}\n";
    }
}

my %rebus;
my @values1 = values %hash1;
#print "values are @values1";
my @keys2 = keys %hash2;
@rebus{@keys2} = @values1;
print_hash(\%rebus);

$

This is looking pretty good now.  Thx all for comment. Since there's 
supposed to be a bijection between image and comment, I'm convinced that 
"throwing my data into a hash" is gonna bear fruit.  I hope I "zippered" 
it right, under the assumption of lexicographical order.
>
>> My contention is that I'm guaranteed to be on topic by tuesday.  Until
>> then I'd like to consider the question of what perl environment works
>> best on a windows 8 laptop, which is at best a shoulder issue as far
>> as topicality goes.  I ask it, because it has directly to do with my
>> pursuit of laziness.
>
> I prefer Windows 7 which I have on my desktop (8 on laptop).
> I use Vim for an editor, tcsh for my shell (doesn't work as
> well on 8 as it does on 7) and ActiveState Perl which is
> easy to install and add modules to using PPM.  I try to use
> native Windows ported UNIX utilities (rather than emulated
> ones as in CygWin).  I don't do much, if any, compiling - just
> never managed to properly set up a decent compiler/development
> environment (and not about to pay for Windoze MSVC) - so I just
> use pre-compiled AS Perl for everything.
>

Ok.  Can you say a few more words about the last sentence?
-- 
Cal



------------------------------

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 4046
***************************************


home help back first fref pref prev next nref lref last post