[28741] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 10105 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 30 14:05:51 2006

Date: Sat, 30 Dec 2006 11:05:05 -0800 (PST)
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, 30 Dec 2006     Volume: 10 Number: 10105

Today's topics:
        Assigning pattern matches to an array <graham@letsgouk.com>
    Re: Assigning pattern matches to an array <someone@example.com>
    Re: Assigning pattern matches to an array <uri@stemsystems.com>
    Re: Assigning pattern matches to an array <graham@letsgouk.com>
    Re: Assigning pattern matches to an array <graham@letsgouk.com>
    Re: CPAN install difficulties on CentOS 4.4 <mtbr0228AT@sbcglobalDOT.net>
        Disable functionality thru commenting out a use <robert.nicholson@gmail.com>
        new CPAN modules on Sat Dec 30 2006 (Randal Schwartz)
        perl -V in 5.8.8 doesn't add architecture dependent dir <robert.nicholson@gmail.com>
        Problem with subroutine Variable "$file" will not stay  pod69@gmx.net
    Re: Problem with subroutine Variable "$file" will not s pod69@gmx.net
    Re: Problem with subroutine Variable "$file" will not s <someone@example.com>
    Re: running ppm on XP 64 <sisyphus1@nomail.afraid.org>
    Re: Superformula with Perl? <guba@vi-anec.de>
    Re: Superformula with Perl? <zentara@highstream.net>
        Why is this dup failing under BSD? <robert.nicholson@gmail.com>
    Re: Why is this dup failing under BSD? <someone@example.com>
    Re: Why would I use Perl in place of C/C++? <bik.mido@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 30 Dec 2006 12:58:59 -0000
From: "Graham Stow" <graham@letsgouk.com>
Subject: Assigning pattern matches to an array
Message-Id: <45966825.0@entanet>

The following is a crude attempt at matching occurrences of email addresses 
within files in a directory. However, I can't figure out why line 15 doesn't 
assign the pattern matches to the @matches array. Any ideas gang, or have I 
been eating too much turkey?

#!/usr/local/bin/perl
use File::Find;
@directories = ("c:/email2");
find (\&wanted,  @directories);
sub wanted {
$filename=$File::Find::name;
if ($filename =~ /\.\w{3}$/) {
   push(@files, $filename);
 }
   }
foreach $file (@files) {
     open (DATA, "$file") || die "Error opening $file\n";
     @whole_file = <DATA>;
     foreach $line (@whole_file)  {
      @matches = /\b\w+@\w+\b/g;
      }
     close DATA || die "Unable to close $file\n";
       # closes the current file
}
foreach $match (@matches) {
     print "$match\n";
}
$count += @matches;
print "$count matches\n"; 




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

Date: Sat, 30 Dec 2006 17:36:53 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Assigning pattern matches to an array
Message-Id: <Vsxlh.96488$YV4.8365@edtnps89>

Graham Stow wrote:
> The following is a crude attempt at matching occurrences of email addresses 
> within files in a directory. However, I can't figure out why line 15 doesn't 
> assign the pattern matches to the @matches array. Any ideas gang, or have I 
> been eating too much turkey?
> 
> #!/usr/local/bin/perl

use warnings;
use strict;

> use File::Find;
> @directories = ("c:/email2");
> find (\&wanted,  @directories);
> sub wanted {
> $filename=$File::Find::name;
> if ($filename =~ /\.\w{3}$/) {
>    push(@files, $filename);
>  }
>    }
> foreach $file (@files) {
>      open (DATA, "$file") || die "Error opening $file\n";
>      @whole_file = <DATA>;
>      foreach $line (@whole_file)  {
>       @matches = /\b\w+@\w+\b/g;

That line is short for:

       @matches = $_ =~ /\b\w+@\w+\b/g;

But the current line is in $line not in $_ so you have to do:

       @matches = $line =~ /\b\w+@\w+\b/g;


>       }
>      close DATA || die "Unable to close $file\n";
>        # closes the current file
> }
> foreach $match (@matches) {
>      print "$match\n";
> }
> $count += @matches;
> print "$count matches\n"; 




John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall


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

Date: Sat, 30 Dec 2006 13:30:48 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Assigning pattern matches to an array
Message-Id: <x7psa1kzhj.fsf@mail.sysarch.com>

>>>>> "JWK" == John W Krahn <someone@example.com> writes:


  JWK> That line is short for:

  JWK>        @matches = $_ =~ /\b\w+@\w+\b/g;

  JWK> But the current line is in $line not in $_ so you have to do:

  JWK>        @matches = $line =~ /\b\w+@\w+\b/g;

and that will overwrite any matches for the previous line. so the print
loop will only see the matches on the last line of a file. push is
needed here. or a map can be used which will remove the loop:

	@matches = map /\b\w+@\w+\b/g, @lines ;

if that is in a file loop, use push also.

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: Sat, 30 Dec 2006 18:30:39 -0000
From: "Graham Stow" <graham@letsgouk.com>
Subject: Re: Assigning pattern matches to an array
Message-Id: <4596b5e8.0@entanet>


"John W. Krahn" <someone@example.com> wrote in message 
news:Vsxlh.96488$YV4.8365@edtnps89...
> Graham Stow wrote:
>> The following is a crude attempt at matching occurrences of email 
>> addresses
>> within files in a directory. However, I can't figure out why line 15 
>> doesn't
>> assign the pattern matches to the @matches array. Any ideas gang, or have 
>> I
>> been eating too much turkey?
>>
>> #!/usr/local/bin/perl
>
> use warnings;
> use strict;
>
>> use File::Find;
>> @directories = ("c:/email2");
>> find (\&wanted,  @directories);
>> sub wanted {
>> $filename=$File::Find::name;
>> if ($filename =~ /\.\w{3}$/) {
>>    push(@files, $filename);
>>  }
>>    }
>> foreach $file (@files) {
>>      open (DATA, "$file") || die "Error opening $file\n";
>>      @whole_file = <DATA>;
>>      foreach $line (@whole_file)  {
>>       @matches = /\b\w+@\w+\b/g;
>
> That line is short for:
>
>       @matches = $_ =~ /\b\w+@\w+\b/g;
>
> But the current line is in $line not in $_ so you have to do:
>
>       @matches = $line =~ /\b\w+@\w+\b/g;
>
>
>>       }
>>      close DATA || die "Unable to close $file\n";
>>        # closes the current file
>> }
>> foreach $match (@matches) {
>>      print "$match\n";
>> }
>> $count += @matches;
>> print "$count matches\n";
>
>
>
>
> John
> -- 
> Perl isn't a toolbox, but a small machine shop where you can special-order
> certain sorts of tools at low cost and in short order.       -- Larry Wall
Makes sense John, but doesn't work -I still get 0 matches (and I'm certain I 
should be getting some).
Graham




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

Date: Sat, 30 Dec 2006 18:42:01 -0000
From: "Graham Stow" <graham@letsgouk.com>
Subject: Re: Assigning pattern matches to an array
Message-Id: <4596b88f.0@entanet>


"Uri Guttman" <uri@stemsystems.com> wrote in message 
news:x7psa1kzhj.fsf@mail.sysarch.com...
>>>>>> "JWK" == John W Krahn <someone@example.com> writes:
>
>
>  JWK> That line is short for:
>
>  JWK>        @matches = $_ =~ /\b\w+@\w+\b/g;
>
>  JWK> But the current line is in $line not in $_ so you have to do:
>
>  JWK>        @matches = $line =~ /\b\w+@\w+\b/g;
>
> and that will overwrite any matches for the previous line. so the print
> loop will only see the matches on the last line of a file. push is
> needed here. or a map can be used which will remove the loop:
>
> @matches = map /\b\w+@\w+\b/g, @lines ;
>
> if that is in a file loop, use push also.
>
> 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

Thanks Uri!
    push(@matches, $line=~/\b\w+@\w+\b/g);  did it for me
The pattern doesn't match an email address, but I can work on that...
Graham




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

Date: Sat, 30 Dec 2006 11:02:18 GMT
From: Alan_C <mtbr0228AT@sbcglobalDOT.net>
Subject: Re: CPAN install difficulties on CentOS 4.4
Message-Id: <87irft63ru.fsf@AB60R.localdomain>

"dan" <dhazer@gmail.com> writes:

> I just finished install some modules (i.e. Archive::Tar  Compress::Zlib
>  and its dependencies)
> 
> because in order to install any other module it needed the above two.

You didn't tell us which perl.  Is it the default Centos perl at /usr/bin/perl

or is it perl that you compiled and installed to /usr/local/bin/perl

and, which version of Perl?

<snip>

> Is it a setting during install, was there an init script I didn't run?

I might hazard a guess that some of your binaries (wget, etc. and others
mentioned by Sherm) are in a non standard location on Centos which could
cause this -- but I doubt this is the case.

The CPAN.pm has a configuration which activates the first time that you
specify CPAN on the commandline.  (unless it had been somewhat of a non
standard thing, ie distro specific, Centos -- again, I doubt this is the case).

We be kinda left in the dark -- as Sherm said, it is *supposed* to work.
But, for whatever reason(s), yours didn't.

Another guess: perhaps a default Centos install leaves off a few Perl
modules? -- that such modules could be added as .rpm Centos packages?

As above, more specifics, which perl, etc.

> If I'm posting this in the wrong group, please let me know.

Oh, I don't know about that.  But I'm guessing it might possibly be better
served at

http://groups.google.com/group/perl.beginners

or maybe at a Centos list/newsgroup if this is a distro specific caused.

-- 
Alan.


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

Date: 30 Dec 2006 06:49:34 -0800
From: "Robert Nicholson" <robert.nicholson@gmail.com>
Subject: Disable functionality thru commenting out a use
Message-Id: <1167490174.371363.53630@k21g2000cwa.googlegroups.com>

I want to disable some functionality by making it conditional that it's
use statement is in the script.

How in general can you tell if a module is present or loaded? if
defined(X) what should X be?

I want to disable some features in a big perl script by
conditionalizing the code that relies on those modules and be able to
disable those features by comment out the "use" line for the modules.



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

Date: Sat, 30 Dec 2006 05:42:13 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Sat Dec 30 2006
Message-Id: <JB2nuD.1u5I@zorch.sf-bay.org>

The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN).  You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.

Class-Generate-1.07
http://search.cpan.org/~swartik/Class-Generate-1.07/
Generate Perl class hierarchies
----
Compress-Raw-Bzip2-2.002
http://search.cpan.org/~pmqs/Compress-Raw-Bzip2-2.002/
Low-Level Interface to bzip2 compression library
----
Compress-Raw-Zlib-2.002
http://search.cpan.org/~pmqs/Compress-Raw-Zlib-2.002/
Low-Level Interface to zlib compression library
----
Compress-Zlib-2.002
http://search.cpan.org/~pmqs/Compress-Zlib-2.002/
Interface to zlib compression library
----
Convert-Binary-C-0.67
http://search.cpan.org/~mhx/Convert-Binary-C-0.67/
Binary Data Conversion using C Types
----
DBIx-Class-SaltedPasswords-0.03000
http://search.cpan.org/~perler/DBIx-Class-SaltedPasswords-0.03000/
Salts password columns
----
Data-Random-String-0.01
http://search.cpan.org/~makis/Data-Random-String-0.01/
Perl extension for creating random strings
----
Egg-Release-0.22
http://search.cpan.org/~lushe/Egg-Release-0.22/
WEB application framework release.
----
IO-Compress-Base-2.002
http://search.cpan.org/~pmqs/IO-Compress-Base-2.002/
Base Class for IO::Compress modules
----
IO-Compress-Bzip2-2.002
http://search.cpan.org/~pmqs/IO-Compress-Bzip2-2.002/
Write bzip2 files/buffers
----
IO-Compress-Lzf-2.002
http://search.cpan.org/~pmqs/IO-Compress-Lzf-2.002/
Write lzf files/buffers
----
IO-Compress-Lzop-2.002
http://search.cpan.org/~pmqs/IO-Compress-Lzop-2.002/
Write lzop files/buffers
----
IO-Compress-Zlib-2.002
http://search.cpan.org/~pmqs/IO-Compress-Zlib-2.002/
----
Image-ExifTool-Location-v0.0.1
http://search.cpan.org/~andya/Image-ExifTool-Location-v0.0.1/
Easy setting, getting of an image's location information
----
Net-Address-Ethernet-1.091
http://search.cpan.org/~mthurn/Net-Address-Ethernet-1.091/
find hardware ethernet address
----
Net-Prizm-0.02
http://search.cpan.org/~jef/Net-Prizm-0.02/
Perl client interface to Motorola Canopy Prizm
----
Net-TiVo-0.04
http://search.cpan.org/~boumenot/Net-TiVo-0.04/
Perl interface to TiVo.
----
POE-Component-IRC-5.18
http://search.cpan.org/~bingos/POE-Component-IRC-5.18/
a fully event-driven IRC client module.
----
POE-Component-Server-IRC-1.07
http://search.cpan.org/~bingos/POE-Component-Server-IRC-1.07/
a fully event-driven networkable IRC server daemon module.
----
Pushmi-v0.991.0
http://search.cpan.org/~clkao/Pushmi-v0.991.0/
Subversion repository replication tool
----
Rsync-Config-0.2
http://search.cpan.org/~diablo/Rsync-Config-0.2/
----
Socialtext-Resting-Utils-0.03
http://search.cpan.org/~lukec/Socialtext-Resting-Utils-0.03/
Utilities for Socialtext REST APIs
----
Socialtext-WikiTest-0.02
http://search.cpan.org/~lukec/Socialtext-WikiTest-0.02/
----
Sys-Statistics-Linux-0.04
http://search.cpan.org/~bloonix/Sys-Statistics-Linux-0.04/
Collect linux system statistics.
----
Test-Without-Module-0.07
http://search.cpan.org/~corion/Test-Without-Module-0.07/
Test fallback behaviour in absence of modules
----
Test-Without-Module-0.08
http://search.cpan.org/~corion/Test-Without-Module-0.08/
Test fallback behaviour in absence of modules
----
Text-CSV-Track-0.1
http://search.cpan.org/~jkutej/Text-CSV-Track-0.1/
module to work with .csv file that stores some value per identificator
----
mogilefs-server-2.00_04
http://search.cpan.org/~bradfitz/mogilefs-server-2.00_04/


If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.

This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
  http://www.stonehenge.com/merlyn/LinuxMag/col82.html

print "Just another Perl hacker," # the original

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 30 Dec 2006 07:47:22 -0800
From: "Robert Nicholson" <robert.nicholson@gmail.com>
Subject: perl -V in 5.8.8 doesn't add architecture dependent directories?
Message-Id: <1167493642.421345.59350@73g2000cwn.googlegroups.com>

Hi,

I've got two systems and one with 5.8.0 and another with 5.8.8

in 5.8.0 perl -V includes architecture dependent directories added to
site_perl where as 5.8.8 doesn't

did this behaviour change in after 5.8.0?

so on 5.8.8 I have to explicitly add the arch directories in PERL5LIB
where as in 5.8.0 I don't.



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

Date: 30 Dec 2006 08:14:13 -0800
From: pod69@gmx.net
Subject: Problem with subroutine Variable "$file" will not stay shared at..
Message-Id: <1167495253.235096.73290@s34g2000cwa.googlegroups.com>

Hello
I use this function with the subroutine match to find a file:

sub search{
	my $file = shift;
	use File::Find;
	find {wanted => \&match, no_chdir => 1}, "/home";
	sub match {
  		return $_ if /$file/;
   }
}

The problem I have is with the inner subroutine. I dont know how i can
get rid of the warning Variable "$file" will not stay shared at. I dont
want to change it i just want to compare it?

thank you



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

Date: 30 Dec 2006 10:15:12 -0800
From: pod69@gmx.net
Subject: Re: Problem with subroutine Variable "$file" will not stay shared at..
Message-Id: <1167502512.677124.194030@48g2000cwx.googlegroups.com>

oh thank u very much for your hint i solved it now like that
        my $file;
	use File::Find;
	find {wanted => sub {$file = $_ if /$filename/ }, no_chdir => 1},
$ENV{INCA_DIST}; 
	return $file;

and with return $file it works;

thx



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

Date: Sat, 30 Dec 2006 18:01:25 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Problem with subroutine Variable "$file" will not stay shared at..
Message-Id: <VPxlh.96492$YV4.9854@edtnps89>

pod69@gmx.net wrote:
> 
> I use this function with the subroutine match to find a file:
> 
> sub search{
> 	my $file = shift;
> 	use File::Find;
> 	find {wanted => \&match, no_chdir => 1}, "/home";
> 	sub match {
>   		return $_ if /$file/;
>    }
> }
> 
> The problem I have is with the inner subroutine. I dont know how i can
> get rid of the warning Variable "$file" will not stay shared at. I dont
> want to change it i just want to compare it?

perldoc perldiag

[ snip ]

    Variable "%s" will not stay shared
        (W closure) An inner (nested) named subroutine is referencing a
        lexical variable defined in an outer subroutine.

        When the inner subroutine is called, it will probably see the value of
        the outer subroutine's variable as it was before and during the
        *first* call to the outer subroutine; in this case, after the first
        call to the outer subroutine is complete, the inner and outer
        subroutines will no longer share a common value for the variable.  In
        other words, the variable will no longer be shared.

        Furthermore, if the outer subroutine is anonymous and references a
        lexical variable outside itself, then the outer and inner subroutines
        will never share the given variable.

        This problem can usually be solved by making the inner subroutine
        anonymous, using the "sub {}" syntax.  When inner anonymous subs that
        reference variables in outer subroutines are called or referenced,
        they are automatically rebound to the current values of such
        variables.


So you probably want to use an anonymous sub:

sub search {
    my $file = shift;
    use File::Find;
    find {wanted => sub { return $_ if /$file/ }, no_chdir => 1}, "/home";
}

Although returning a value from the 'wanted' callback sub will not return it
from your 'search' sub so you may need to use a module other than File::Find.



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall


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

Date: Sat, 30 Dec 2006 11:57:36 +1100
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: running ppm on XP 64
Message-Id: <4595badc$0$5744$afc38c87@news.optusnet.com.au>


"Jerry" <jpreston@general-steel.com> wrote in message
news:12paploopp8a43a@corp.supernews.com...
> Is it possible to get the ppm gui to run on XP 64?  I set the
> compatibilitymode to XP, 98 and no luck.
>

Best place to ask about this is probably the PPM mailing list. Visit
http://listserv.ActiveState.com/mailman/mysubs  to subscribe.

Are there any 64-bit PPM packages for perl extensions available ? (I don't
know of any such repositories, but that could simply be ignorance on my
part.)

Cheers,
Rob




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

Date: 30 Dec 2006 00:14:51 -0800
From: "guba@vi-anec.de" <guba@vi-anec.de>
Subject: Re: Superformula with Perl?
Message-Id: <1167466491.537154.285580@v33g2000cwv.googlegroups.com>

Hello,
thank you for the hint to gnuplot; I need the 2D version of the
superformula.
So I took a look at the Perl API at
http://search.cpan.org/%7Eilyaz/Term-Gnuplot-0.5704/Gnuplot.pm
I hope there is somewhere a tutorial about this because with my
knowledge about Perl based on PerlMagick this API is difficult to
understand. But perhaps there are other options like turtle graphics
where the turtle is controlled by a formula.

Thank you
G=FCnter



zentara schrieb:

> On 28 Dec 2006 03:47:05 -0800, "guba@vi-anec.de" <guba@vi-anec.de>
> wrote:
>
> >Hello,
> >
> >I am wondering how parametric formulas like the Superformula
> >http://en.wikipedia.org/wiki/Superformula
> >can be drawn with Perl. GD or ImageMagick has only some graphic
> >primitives and I can not see how this could be done which such
> >programs. Or can Perl API to a mathe library be used to
> >draw such graphs? Thank you for hints!
> >
> >G=FCnter
>
> These are cool, thanks for pointing them out.
>
> If you just want the 2d , gnuplot will do polar coordinates.
>
> But the general solution for 3d, would be to use PDL.
> The TriD graphics will do parametric equations.
> See http://www.johnlapeyre.com/pdl/pdldoc/newbook/index.html!
> for a guide.
>
> Here is a chopped down version from the PDL demo, which is close,
> and you could probably modify it for your SuperFormula parametric
> equations.
>
> #!/usr/bin/perl
> use warnings;
> use strict;
> use Tk;
> use PDL;
> use PDL::Graphics::TriD;
> use PDL::Graphics::TriD::Contours;
> use PDL::Graphics::TriD::GL;
> use PDL::Graphics::TriD::Tk;
>
> my $TriDW;    # declare the graph object in main, defined in initialize
> my $MW =3D MainWindow->new();
> my $bframe =3D $MW->Frame()->pack( -side =3D> 'top', -fill =3D> 'x' );
>
> # This is the TriD Tk widget it is a Tk Frame widget and has all of the
> # attributes of a Frame
> $TriDW =3D $MW->Tk()->pack( -expand =3D> 1, -fill =3D> 'both');
>
> # The exit button
> my $e_button =3D $bframe->Button(
>    -text    =3D> "Exit",
>    -command =3D> sub { exit }
> )->pack( -side =3D> 'right', -anchor =3D> 'nw', -fill =3D> 'y' );
>
> # Sets a default focus style for viewport
> #setfocusstyle( 'Pointer' );
>
> # a trick needed to display
> # set the graphic  when the window is first opened
> $e_button->bind( "<Configure>", [
>       sub {
>          my $but =3D shift;
>          Torusdemos();
> 	 $e_button->bind( "<Configure>", '' );
>          } ]
>        );
>
> $TriDW->MainLoop;
>
> sub Torusdemos {
>    my ( $bh ) =3D @_;
>
>    return unless defined $TriDW->{ GLwin };
>    my $graph;
>
>    $graph =3D $TriDW->{ GLwin }->current_viewport->graph();
>
>   # define the graph object
>       $graph =3D new PDL::Graphics::TriD::Graph();
>       $graph->default_axes();
>
>       my $data;
>       my $s =3D 40;
>       my $a =3D zeroes 2 * $s, $s / 2;
>       my $t =3D $a->xlinvals( 0, 6.284 );
>       my $u =3D $a->ylinvals( 0, 6.284 );
>       my $o =3D 0.5;
>       my $i =3D 0.1;
>       my $v =3D $o + $i * sin $u;
>
>       my $x =3D $v * sin $t;
>       my $y =3D $v * cos $t;
>       my $z =3D $i * cos( $u ) + $o * sin( 3 * $t );
>
> # color
>          $data =3D new PDL::Graphics::TriD::SLattice(
>             [ $x, $y, $z ],
>             [
>                0.5 *  ( 1 + sin $t ),
>                0.5 *  ( 1 + cos $t ),
>                0.25 * ( 2 + cos( $u ) + sin( 3 * $t ) )
>             ]
>          );
>
> #  black and white
> #     $data =3D new PDL::Graphics::TriD::SLattice_S( [ $x, $y, $z ] );
>
>    $graph->add_dataseries( $data, 'Torus-demo' );
>    $graph->scalethings();
>    $TriDW->current_viewport()->delete_graph( $graph );
>    $TriDW->current_viewport()->graph( $graph );
>    $TriDW->refresh();
> }
> __END__
>
>
> --
> I'm not really a human, but I play one on earth.
> http://zentara.net/japh.html



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

Date: Sat, 30 Dec 2006 11:59:45 GMT
From: zentara <zentara@highstream.net>
Subject: Re: Superformula with Perl?
Message-Id: <h9kcp2h49uj80kodbuk510cvefpbrkohj8@4ax.com>

On 30 Dec 2006 00:14:51 -0800, "guba@vi-anec.de" <guba@vi-anec.de>
wrote:

>thank you for the hint to gnuplot; I need the 2D version of the
>superformula.
>So I took a look at the Perl API at
>http://search.cpan.org/%7Eilyaz/Term-Gnuplot-0.5704/Gnuplot.pm
>I hope there is somewhere a tutorial about this because with my
>knowledge about Perl based on PerlMagick this API is difficult to
>understand. But perhaps there are other options like turtle graphics
>where the turtle is controlled by a formula.
>Thank you
>Günter

There are many tutorials for gnuplot, just google for them.

http://t16web.lanl.gov/Kawano/gnuplot/intro/index-e.html

is one of the better ones. But the best thing to do is run all
the demos that comes with the gnuplot c package.

I had trouble getting the Perl module Term::Gnuplot to
compile on my system, but the latest Gnuplot 4.1 compiles,
and can be run from Perl. You can output to X11 or to a Tk
canvas. Here is a Tk app which will let you adjust the settings
to see the output. For the Tk version, it was easiest for me to
redraw every second, but if you output to X11, you can increase
the efficiency (lower cpu) by using the normal X11 display with the
replot command.

This is fun to play with, and there are some serious "sweet spots"
where unpredictable shapes occur. (Watch for word wrap problems).

#!/usr/bin/perl
#use warnings;
#use strict;
use Tk;
use Tk::ROText;
use IPC::Open3;

$|++;

my %var =(
  'a1'=> 1, 
  'b1'=> 1,        
  'm1'=> 8,
  'n1'=> 1,
  'n2'=> 1,
  'n3'=> 1,
);

my $stop = 0;
my $repeater;
my $running = 0;

my $mw = MainWindow->new;

my $tframe = $mw->Frame()->pack();
my $canvas = $tframe->Canvas(
                  -bg => 'white',
		  -height =>500,
		  -width =>500,
		  )->pack(-side=>'left',-expand=>1,-fill=>'both');
my $tframe1 = $tframe->Frame()->pack(-side=>'right',-padx=>0);

my %scale;

for ('a1','b1','m1','n1','n2','n3'){
 
    my $tframea = $tframe1->Frame()->pack(-side=>'left',-padx=>0);

   $tframea->Label(-text => " $_   ")->pack(-side=>'top');
    
     $scale{$_} = $tframea->Scale(
      -from    => -100,
      -to    => 100,
      -length => 500,
      -orient    => 'vertical',
      -variable    => \$var{$_},
      -resolution => .01,
      -borderwidth =>0,
      -foreground => 'white',
      -background => 'lightslategrey',
      -troughcolor => 'powderblue',
     )->pack(-side => 'left', -padx=>0);
 }

my $text = $mw->Scrolled('ROText',
            -bg=>'white',
	    -height =>5,
	    -width => 45)
     ->pack( -fill => 'both', -expand => 1 );

tie(*STDOUT, 'Tk::Text', $text);

$text->tagConfigure( 'red', -foreground => 'red' );

my $pid = open3( \*gIN, \*gOUT, \*gERR, "/usr/bin/gnuplot" ) || die;
$mw->fileevent( \*gOUT, readable => \&read_out );
$mw->fileevent( \*gERR, readable => \&read_err );

#comment out the below line to get gnuplot's X11 display
#which is more efficient than the canvas plot
print gIN "set term tkcanvas perltk interactive\n";

my $bframe = $mw->Frame->pack();
my $startbut = $bframe->Button(
                    -text=>'Start',
                    -command=> \&start)->pack(-side=>'left');

my $stopbut = $bframe->Button(
                    -text=>'Stop',
                    -command=> sub{ $auto = 0;
		      $repeater->cancel;
	              $running = 0;	    
		     })->pack(-side=>'left');

#must be last or get broken pipe error
tie(*STDERR, 'Tk::Text', $text);

$mw->update; 

MainLoop;

#sub start1{
#for('a1','b1','m1','n1','n2','n3'){
#   $scale{$_}->configure( -command => sub{ \&start}  );
# }
#&start;
#}


sub start{

my $string =<<"EOF";
reset
unset border
set clip
set polar
set xtics axis nomirror
set ytics axis nomirror
set zeroaxis
set trange [0:2*pi]
a=$var{'a1'}
b=$var{'b1'}
m=$var{'m1'}
n1=$var{'n1'}
n2=$var{'n2'}
n3=$var{'n3'}
# equation below is all one line, watch word wrap)
butterfly(x) =  ( ( abs(( (cos(m*x)/4))/a)  )**n2 + ( abs((
(sin(m*x)/4))/b)  )**n3  )**(-1/n1)
set samples 800
set title "SuperFormula"
unset key
plot butterfly(t)
EOF
print gIN  "$string\n";

if( $running == 0){
 $repeater=$mw->repeat(1000,sub{ 
                     $running = 1;
                     &start;
        });
   }

}

sub read_out {
  my $buffer = <gOUT>;
  #  print $buffer,"\n";
  my $can = $canvas;
  eval($buffer);
}

sub read_err {
#    print "read_err()\n";
    my $num = sysread(gERR, my $buffer, 1024 );
#    print "sysread() got $num bytes:\n[$buffer]\n";
    $text->insert( 'end', $buffer, 'red' );
    $text->see('end');
}
__END__




-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html


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

Date: 30 Dec 2006 10:05:01 -0800
From: "Robert Nicholson" <robert.nicholson@gmail.com>
Subject: Why is this dup failing under BSD?
Message-Id: <1167501901.714449.163760@48g2000cwx.googlegroups.com>

I've been doing the following in order to use flock ie. covert a file
descriptor to a File Handle

  my %hash;
  my $hash = tie (%hash, 'DB_File', $listsDb, O_RDONLY|O_CREAT, 0644)
or
  die "Cannot open $listsDb\n";

  my $fd = $hash->fd;
  open(DB_FH, "+<&=$fd") or die "dup $!";
  flock (DB_FH, LOCK_SH) or die "flock: $!";


under BSD I get an error when I do this.

Can anybody tell me why?



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

Date: Sat, 30 Dec 2006 18:14:05 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Why is this dup failing under BSD?
Message-Id: <N%xlh.108581$hn.36859@edtnps82>

Robert Nicholson wrote:
> I've been doing the following in order to use flock ie. covert a file
> descriptor to a File Handle
> 
>   my %hash;
>   my $hash = tie (%hash, 'DB_File', $listsDb, O_RDONLY|O_CREAT, 0644)
> or
>   die "Cannot open $listsDb\n";
> 
>   my $fd = $hash->fd;
>   open(DB_FH, "+<&=$fd") or die "dup $!";
>   flock (DB_FH, LOCK_SH) or die "flock: $!";
> 
> 
> under BSD I get an error when I do this.

Patient: Doctor it hurts when I do this.

Doctor: Well, don't do that.

(is BSD always on top?)


> Can anybody tell me why?

My ESP tells me ... wait ... I see an error on line 42 ... no ... wait ...
line 15 ... does "line 15" mean anything to you?




John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall


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

Date: 30 Dec 2006 06:26:00 -0800
From: "blazar" <bik.mido@gmail.com>
Subject: Re: Why would I use Perl in place of C/C++?
Message-Id: <1167488760.544325.116150@i12g2000cwa.googlegroups.com>

Kleine Aap wrote:

> > I know the -p switch automatically wraps the -e code with a loop. But I'm
> > quite puzzled with the cryptic "$_ x=!$$_++"
> >
> > I e.g. guess the $$ at the right side of the = is not the process id?
>
> Okay, I think I got it already...
>
> The trick is the symbolic reference with the name of the input line? And the
> value of which is incremented each time that it occurs in the input? Only
> the first time the value is 0 (by implicit initialization) and the !
> results in a 1 for the multiplication (x) operator. Next time it occurs the

"repetition"

> multiplication operator gets a 0 and hence skips the string.

Indeed! (I'm answering from GG because I have troubles reaching my news
server.)


Michele



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

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


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