[25860] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8095 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 19 09:05:28 2005

Date: Thu, 19 May 2005 06:05:06 -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           Thu, 19 May 2005     Volume: 10 Number: 8095

Today's topics:
    Re: Bareword mystery in Perl 5.6.1 (fixed in 5.8.3) <joe@inwap.com>
        Bareword mystery in Perl 5.6.1 <jean-louis.leroy@eurocontrol.int>
    Re: DBI: adding columns to table <someone@somewhere.com>
    Re: getting IP address of remote host from socket (stdi <news@mutare.noc.clara.net>
    Re: no such file or directory? <joe@inwap.com>
    Re: Perl generated navigation menu <joe@inwap.com>
    Re: semi-opacity with GD <sisyphus1@nomail.afraid.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 19 May 2005 01:56:57 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: Bareword mystery in Perl 5.6.1 (fixed in 5.8.3)
Message-Id: <Lq-dnYmsEv5oyRHfRVn-1Q@comcast.com>

Jean-Louis Leroy wrote:
> Somebody here managed to build a Perl 5.6.1 that is strangely tolerant 
> to barewords and accepts scoped names as bare ids. For example, it
> runs the following program:
> 
>   use strict;
>   use warnings;
>   
>   my %h = ( Foo::Bar => 666, this => _tests );
>   $h{Foo::Bar} = 666;
> 
> I have built Perl 5.6.1 myself and indeed mine refuses the code
> above. I ran a diff on the strict.pm files and found no
> differences. What's going on?

linux% ls -lG /usr/lib/perl5/*/strict.pm
-r--r--r--  1 root   2806 Aug 13  2003 /usr/lib/perl5/5.8.0/strict.pm
-r--r--r--  1 root   3292 Feb 17  2004 /usr/lib/perl5/5.8.3/strict.pm
linux% diff /usr/lib/perl5/*/strict.pm
3c3
< $strict::VERSION = "1.02";
---
 > $strict::VERSION = "1.03";
 ...
124a125,135
 > =head1 HISTORY
 >
 > C<strict 'subs'>, with Perl 5.6.1, erroneously permitted to use
 > an unquoted compound identifier (e.g. C<Foo::Bar>) as a hash key
 > (before C<< => >> or inside curlies), but without forcing it
 > always to a literal string.
 >
 > Starting with Perl 5.8.1 strict is strict about its restrictions:
 > if unknown restrictions are used, the strict pragma will abort with
 >
 >     Unknown 'strict' tag(s) '...'
 >


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

Date: 19 May 2005 09:59:36 +0200
From: Jean-Louis Leroy <jean-louis.leroy@eurocontrol.int>
Subject: Bareword mystery in Perl 5.6.1
Message-Id: <sdmzqrmys7.fsf@wagtail.cfmu.corp.eurocontrol.int>

Somebody here managed to build a Perl 5.6.1 that is strangely tolerant 
to barewords and accepts scoped names as bare ids. For example, it
runs the following program:

  use strict;
  use warnings;
  
  my %h = ( Foo::Bar => 666, this => _tests );
  $h{Foo::Bar} = 666;
  
  our @ISA = Foo::Bar;
  
  sub foo { }
  
  foo(tqueuespace_hdr);

I have built Perl 5.6.1 myself and indeed mine refuses the code
above. I ran a diff on the strict.pm files and found no
differences. What's going on?

Here's my friend's `perl -V`:

Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
  Platform:
    osname=hpux, osvers=11.00, archname=PA-RISC2.0
    uname='hp-ux orca b.11.00 e 9000899 1681491342 8-user license '
    config_args='-Aprepend:ccflags=+z +DAportable -Adefine:libs=-lcl -lpthread -lnsl -lnm -lndbm -ldld -lm -lc -lndir -lcrypt -lsec -Dmydomain=.cfmu.eurocontrol.int -Dcf_email=perl@cfmu.eurocontrol.int -Dperladmin=perl@cfmu.eurocontrol.int -Dmksymlinks -Dprefix=/opt/contrib/perl/5.6.1.1 -Uinstallusrbinperl -des'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
  Compiler:
    cc='cc', ccflags =' +z +DAportable -D_HPUX_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64  -Ae',
    optimize='-O',
    cppflags='+z +DAportable -D_HPUX_SOURCE -Aa'
    ccversion='A.11.01.03', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, usemymalloc=y, prototype=define
  Linker and Libraries:
    ld='ld', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib /usr/ccs/lib
    libs=-lcl -lpthread -lnsl -lnm -lndbm -ldld -lm -lc -lndir -lcrypt -lsec
    perllibs=-lcl -lpthread -lnsl -lnm -ldld -lm -lc -lndir -lcrypt -lsec
    libc=/lib/libc.sl, so=sl, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_hpux.xs, dlext=sl, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-B,deferred '
    cccdlflags='+z', lddlflags='-b +vnocompatwarnings -L/usr/local/lib'


Characteristics of this binary (from libperl): 
  Compile-time options: USE_LARGE_FILES
  Built under hpux
  Compiled at Dec 21 2001 12:31:46
  %ENV:
    PERL5LIB="CcB:/cm/ot/CMA/CC_TOOL!2.1.93/build_G!50.IP.11/pm/perl/lib/wle/interface:/cm/ot/CMA/CC_TOOL!2.1.93/build_G!50.IP.11/pm/perl/lib:/cm/ot/CMA/CC_TOOL!2.1.93/build_G!50.IP.11/pm/external_perl_lib/PA-RISC2.0:/cm/ot/CMA/CC_TOOL!2.1.93/build_G!50.IP.11/pm:/cm/ot/CMA/CM_TOOL!2.1.35/build_G!50.IP.11/pm/perl/lib:/cm/ot/CMA/CM_TOOL!2.1.35/build_G!50.IP.11/pm:/cm/ot/TOOL/COMMON_UTILS!11.77/build_G!50.IP.11/pm/ftps:/cm/ot/TOOL/COMMON_UTILS!11.77/build_G!50.IP.11/pm/external_perl_lib/PA-RISC2.0:/cm/ot/TOOL/COMMON_UTILS!11.77/build_G!50.IP.11/pm/external_perl_lib:/cm/ot/TOOL/COMMON_UTILS!11.77/build_G!50.IP.11/pm/perl/lib:/cm/ot/TOOL/COMMON_UTILS!11.77/build_G!50.IP.11/pm:/cm/ot/TOOL/GNU!11.18/build_G!50.IP.11/pm:CcE"
  @INC:
    CcB
    /cm/ot/CMA/CC_TOOL!2.1.93/build_G!50.IP.11/pm/perl/lib/wle/interface
    /cm/ot/CMA/CC_TOOL!2.1.93/build_G!50.IP.11/pm/perl/lib
    /cm/ot/CMA/CC_TOOL!2.1.93/build_G!50.IP.11/pm/external_perl_lib/PA-RISC2.0
    /cm/ot/CMA/CC_TOOL!2.1.93/build_G!50.IP.11/pm
    /cm/ot/CMA/CM_TOOL!2.1.35/build_G!50.IP.11/pm/perl/lib
    /cm/ot/CMA/CM_TOOL!2.1.35/build_G!50.IP.11/pm
    /cm/ot/TOOL/COMMON_UTILS!11.77/build_G!50.IP.11/pm/ftps/PA-RISC2.0
    /cm/ot/TOOL/COMMON_UTILS!11.77/build_G!50.IP.11/pm/ftps
    /cm/ot/TOOL/COMMON_UTILS!11.77/build_G!50.IP.11/pm/external_perl_lib/PA-RISC2.0
    /cm/ot/TOOL/COMMON_UTILS!11.77/build_G!50.IP.11/pm/external_perl_lib/PA-RISC2.0
    /cm/ot/TOOL/COMMON_UTILS!11.77/build_G!50.IP.11/pm/external_perl_lib
    /cm/ot/TOOL/COMMON_UTILS!11.77/build_G!50.IP.11/pm/perl/lib
    /cm/ot/TOOL/COMMON_UTILS!11.77/build_G!50.IP.11/pm
    /cm/ot/TOOL/GNU!11.18/build_G!50.IP.11/pm
    CcE
    /opt/contrib/perl/5.6.1.1/lib/5.6.1/PA-RISC2.0
    /opt/contrib/perl/5.6.1.1/lib/5.6.1
    /opt/contrib/perl/5.6.1.1/lib/site_perl/5.6.1/PA-RISC2.0
    /opt/contrib/perl/5.6.1.1/lib/site_perl/5.6.1
    /opt/contrib/perl/5.6.1.1/lib/site_perl
    .
-- 
Jean-Louis Leroy


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

Date: Thu, 19 May 2005 09:35:15 +0100
From: "Bigus" <someone@somewhere.com>
Subject: Re: DBI: adding columns to table
Message-Id: <d6hj43$mjn$1@blackmamba.itd.rl.ac.uk>


<xhoster@gmail.com> wrote in message 
news:20050518132317.407$bK@newsreader.com...
> "Bigus" <someone@somewhere.com> wrote:
> ...
>> That's where $k = "owner". If I remove the single quotes round $k in teh
>> ALTER TABLE line then the owner column is created fine, but of course it
>> then falls over when $k = "reply-to" because of the hyphen.
>>
>> When I use PHPMyadmin to create the owner column it works fine and tells
>> me it's used the syntax:
>>
>>     ALTER TABLE `list_headers` ADD `owner` TEXT
>
> If PHPMyadmin told you that it used backticks, and that seemed to work,
> then I would suggest that you try using backticks in your Perl program.

It must have registered at a subconscious level and sown the seed. I didn't 
notice PHPmyadmin using backticks until you just pointed it out.. still, the 
DBI prepare method is supposed to deal with quoting automatically but when I 
tried that and it didn't work.

Bigus 




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

Date: Thu, 19 May 2005 10:04:45 +0100
From: Ollie Cook <news@mutare.noc.clara.net>
Subject: Re: getting IP address of remote host from socket (stdin)
Message-Id: <slrnd8olld.1ed7.news@mutare.noc.clara.net>

On 18 May 2005 21:27:59 GMT, Anno Siegel wrote:
> Try this:
> 
>     use IO::Socket::INET;
> 
>     my $sock = IO::Socket::INET->new;
>     $sock->fdopen( fileno STDIN, 'r') or die "dup: $!";
>     my $peerhost = $sock->peerhost or die "peerhost: $!";
>     print "peerhost is $peerhost\n";

Hi Anno,

That does just the trick. Thank you for your assistance.

Yours,

Ollie


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

Date: Thu, 19 May 2005 02:36:10 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: no such file or directory?
Message-Id: <TOSdnSnkcumxwxHfRVn-rA@comcast.com>

Geoff Cox wrote:
> I am using File::Find and wish to use the following but get error
> open OUT, ">>assets/i-$name" or die "cannot open assets/$name : $!" ; 

Another way would be to populate an array with just the names
of the files, and then process them after File::Find is done.

my @files;
find(sub {push @files,$File::Find::name if -f $_}, '.');
foreach my $file (@files) {
    ...
}

	-Joe


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

Date: Thu, 19 May 2005 00:11:06 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: Perl generated navigation menu
Message-Id: <3vadncRx8caEoRHfRVn-ow@comcast.com>

michael wrote:

> As a non-perl scripter I have some likely basic questions:
> How can a current URL or filename portion be accessed in Perl?

There is no need to access either when your perl script is creating
both the URLs and the files.  The process of creating simple HTML
files does not require the use of a web server and browser.

> Are there any modules that may be useful in this example, or would it
> perhaps be easier to write a script for the purpose?

Various of the html template modules are suitable.

I know what you are trying to accomplish; I did something like that
ten years ago.  I created a script that would take one specific html
file as input data, then use that data to update the "prev", "next",
and and "up" links on all the other html files (and change the
"page N of NNN" text at the bottom of each page).
http://www.inwap.com/mf/reboot/TheEnd.html is the data file.

> In which ways could all be easily done?
> 
> Any ideas including code snippets (or chunks) would be greatly appreciated,
> especially with regards to transforming the above arrays into the
> examplified html structure, perhaps by using a for loop?

OK, so you're asking how a for(){} loop could be used for this purpose.

If the items in an array are independent, use

    foreach my $element (@array) {
	... $element ...
    }

But when handling consecutive elements, index into the array.

    foreach my $i (0 .. $#array) {
       print "Previous = $array[$i-1]\n" unless $i == 0;
       print "Current  = $array[$i]\n";
       print "Next     = $array[$i+1]\n" unless $i == $#array;
    }

Here is an example of the latter using your data.
	-Joe


linux% cat michael.pl
#!/usr/bin/perl
# In reference to Message-ID: <d63cj5$7qh$02$1@news.t-online.com>
use strict;
use warnings;

my %links = (
   'flora_and_fauna'   => [
         [ 'z0.html', 'Flora &amp; Fauna'  ],
         [ 'z1.html', 'Pretty Flowers' ],
         [ 'z2.html', 'Deadly Vines'   ],
                          ],
   'aquatic_creatures' => [
         [ 'z3.html', 'Aquatic Creatures' ],
         [ 'z4.html', 'Pretty Fish'       ],
         [ 'z5.html', "Don't Eat"         ],
                          ],
);

foreach my $title (sort keys %links) {
   print "Creating pages for '$title'\n";
   write_group($title, @{$links{$title}});
}

sub write_group {
   my ($name,@links) = @_;

   foreach my $i1 (0 .. $#links) {
     my ($file,$text) = @{$links[$i1]};
     open my $htm,'>',$file or warn "Unable to create $file: $!\n" and next;
     print "  Creating $file for '$text'\n";
     print $htm "START OF HTML\n";

     foreach my $i2 (0 .. $#links) {
       my ($file2,$text2) = @{$links[$i2]};
       if ($i2 < $i1) {
         print $htm qq(PREV <a href="$file2">$text2</a>\n);
       } elsif ($i2 > $i1) {
         print $htm qq(NEXT <a href="$file2">$text2</a>\n);
       } else {
         print $htm qq(THIS is href="$file2" $text2\n);
       }
     }

     print $htm "END OF HTML\n";
     close $htm or warn "Possible truncation on $file: $!\n";
   }
}

linux% perl michael.pl
Creating pages for 'aquatic_creatures'
   Creating z3.html for 'Aquatic Creatures'
   Creating z4.html for 'Pretty Fish'
   Creating z5.html for 'Don't Eat'
Creating pages for 'flora_and_fauna'
   Creating z0.html for 'Flora &amp; Fauna'
   Creating z1.html for 'Pretty Flowers'
   Creating z2.html for 'Deadly Vines'
linux% head z?.html
==> z0.html <==
START OF HTML
THIS is href="z0.html" Flora &amp; Fauna
NEXT <a href="z1.html">Pretty Flowers</a>
NEXT <a href="z2.html">Deadly Vines</a>
END OF HTML

==> z1.html <==
START OF HTML
PREV <a href="z0.html">Flora &amp; Fauna</a>
THIS is href="z1.html" Pretty Flowers
NEXT <a href="z2.html">Deadly Vines</a>
END OF HTML

==> z2.html <==
START OF HTML
PREV <a href="z0.html">Flora &amp; Fauna</a>
PREV <a href="z1.html">Pretty Flowers</a>
THIS is href="z2.html" Deadly Vines
END OF HTML

==> z3.html <==
START OF HTML
THIS is href="z3.html" Aquatic Creatures
NEXT <a href="z4.html">Pretty Fish</a>
NEXT <a href="z5.html">Don't Eat</a>
END OF HTML

==> z4.html <==
START OF HTML
PREV <a href="z3.html">Aquatic Creatures</a>
THIS is href="z4.html" Pretty Fish
NEXT <a href="z5.html">Don't Eat</a>
END OF HTML

==> z5.html <==
START OF HTML
PREV <a href="z3.html">Aquatic Creatures</a>
PREV <a href="z4.html">Pretty Fish</a>
THIS is href="z5.html" Don't Eat
END OF HTML
linux%


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

Date: Thu, 19 May 2005 21:21:30 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: semi-opacity with GD
Message-Id: <428c76b7$0$4655$afc38c87@news.optusnet.com.au>


"Richard Bennett" <richard.bennett@nospam.skynet.be> wrote

>
> I can make an image which does the right thing when I create a new image
> like this:
>
> #!/usr/bin/perl -w
> use GD;
> my $im;    # The Image object
> my $xsize = 160; my $ysize = 160;
> my $bgcol = colourARGB( 70, 100, 255, 255 );
> $im = new GD::Image->newTrueColor( $xsize, $ysize )
>         || die "$0: Failed to create image -- $!\n";
> $im->saveAlpha(1);
> $im->alphaBlending(0);
> $im->filledRectangle( 0, 0, $xsize - 1, $ysize - 1, $bgcol );
> $im->alphaBlending(1);
>
> binmode STDOUT;
> print "Content-type: image/png\n\n";
> print $im->png;
>
> sub colourARGB($$$$)  {
>      my $alpha = shift; my $red   = shift;
>      my $green = shift; my $blue  = shift;
>     # Alpha is in range 0 (opaque) to 127 (fully transparent),
>      # R, G, B in range 0 .. 255. Force values into range.
>      $alpha &= 0x7f; $red   &= 0xff;
>      $green &= 0xff; $blue  &= 0xff;
>     return $alpha << 24 | $red << 16 | $green << 8 | $blue;
> }
>
>
> But I cannot seem to find out how to manipulate an existing image to make
it
> semi-opaic. I tried like this:
>
> #!/usr/bin/perl -w
> use GD;
> my $im;    # The Image object
> my $bgcol = colourARGB( 50, 200, 200, 200 );
> $im = newFromPng GD::Image('top.png');
> $im->saveAlpha(1);
> $im->alphaBlending(0);
> binmode STDOUT;
> print "Content-type: image/png\n\n";
> print $im->png;
>
> sub colourARGB($$$$)  {
>      my $alpha = shift; my $red   = shift; my $green = shift; my $blue  =
> shift;
>     # Alpha is in range 0 (opaque) to 127 (fully transparent),
>     # R, G, B in range 0 .. 255. Force values into range.
>     $alpha &= 0x7f; $red   &= 0xff; $green &= 0xff; $blue  &= 0xff;
>     return $alpha << 24 | $red << 16 | $green << 8 | $blue;
> }
>

In the second script you set $bgcol to a value ...... but then, afaict,
$bgcol doesn't get used. Why is that variable (and the subroutine that sets
its value) included in the script ? Didn't you get a warning that $bgcol was
used only once in the script ?

I don't know much about GD and opacity - perhaps those questions are totally
irrelevant to the problem. I wondered about that when I saw your post on
c.l.p.modules .... and I'm still wondering :-)

Do you have a demo script that demonstrates the effect you're after - only
it prints the result to a png file rather than to stdout ? (I really don't
want to be stuffing around with demos that require a web server to view -
which is another reason that I didn't look too hard at your c.l.p.modules
post.) I tried modifying the first of the 2 scripts that you provided so
that it printed to a png file, but all I see is a pale blue square - and
that doesn't tell me much about the effect that you're seeking.

Cheers,
Rob




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

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 V10 Issue 8095
***************************************


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