[31054] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2299 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 26 11:09:46 2009

Date: Thu, 26 Mar 2009 08:09:11 -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, 26 Mar 2009     Volume: 11 Number: 2299

Today's topics:
    Re: Debian MySQL Perl  DBI - connection terminates unex <xhoster@gmail.com>
        help with IO::Socket:INET <ebabin@yahoo.com>
    Re: help with IO::Socket:INET <ben@morrow.me.uk>
    Re: help with IO::Socket:INET <smallpond@juno.com>
    Re: How to sleep less then 1 second (hymie!)
        logic, algorithms, and (Perl) data structures <cartercc@gmail.com>
    Re: logic, algorithms, and (Perl) data structures <smallpond@juno.com>
    Re: monitoring oracle rac services <alfonso.baldaserra@gmail.com>
    Re: monitoring oracle rac services <tzz@lifelogs.com>
        new CPAN modules on Thu Mar 26 2009 (Randal Schwartz)
    Re: Sharing BerkeleyDB among forked children <liarafan@xs4all.nl>
    Re: Typeglobs vs References <schaitan@gmail.com>
    Re: Typeglobs vs References <RedGrittyBrick@spamweary.invalid>
    Re: Typeglobs vs References <schaitan@gmail.com>
    Re: Typeglobs vs References <peter@makholm.net>
    Re: Typeglobs vs References <RedGrittyBrick@spamweary.invalid>
    Re: what is the return value type of !1 ? <nospam-abuse@ilyaz.org>
    Re: what is the return value type of !1 ? <nospam-abuse@ilyaz.org>
    Re: what is the return value type of !1 ? <nospam-abuse@ilyaz.org>
    Re: what is the return value type of !1 ? <peter@makholm.net>
    Re: what is the return value type of !1 ? <ben@morrow.me.uk>
    Re: what is the return value type of !1 ? <uri@stemsystems.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 25 Mar 2009 18:40:10 -0700
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: Debian MySQL Perl  DBI - connection terminates unexpectedly after 100 secs.
Message-Id: <49caf1a1$0$25307$ed362ca5@nr5-q3a.newsreader.com>

John wrote:
> 
> Many thanks.  That was very helpful.  I have maxed both RLimitCPU and 
> RLimitMEM in Apache2 and that has had led to better performance.  There are 
> severe problems in using MySQL when you start hitting more than 2 million 
> rows irrespective how well you tweak your settings.

I have MySQL tables with 150 times that many rows.  Obviously I don't 
try to run unrestricted update DML on them.  It isn't how many rows you 
have, it is what you are trying to do with them.

Xho



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

Date: Thu, 26 Mar 2009 06:58:47 -0700 (PDT)
From: me <ebabin@yahoo.com>
Subject: help with IO::Socket:INET
Message-Id: <5844a69e-46ff-4d31-9100-1a0a84ee1278@q18g2000vbn.googlegroups.com>

Hi, I'm using IO::Socket:INET in a client/server connect and all is
working well but I want to restrict connections on the server side by
only allowing certain IP addresses to connect (or in the case I was
working to drop the connection if the IP is not contained in a list).

my $sock = new IO::Socket::INET(
      LocalPort => $port,
      Proto => 'tcp',
      Listen => SOMAXCONN,
      Reuse => 1);
$sock or die "no socket : $!";

if ($pid = fork)  {
   log_msg("Parent spawning child process $pid", $logfile);
   close $client;
} elsif (defined ($pid = fork))  {
   if ($sock->peerhost() ne $accepted_ip)  {
     printf "$timestamp   Connection from $accepted_ip rejected\n";
     close $client;


the $sock->PeerHost() is not evaluating as expected.  Is this used on
the server side?  how to accomplish what I want?


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

Date: Thu, 26 Mar 2009 14:28:15 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: help with IO::Socket:INET
Message-Id: <v0gs96-2do.ln1@osiris.mauzo.dyndns.org>


Quoth me <ebabin@yahoo.com>:
> Hi, I'm using IO::Socket:INET in a client/server connect and all is
> working well but I want to restrict connections on the server side by
> only allowing certain IP addresses to connect (or in the case I was
> working to drop the connection if the IP is not contained in a list).

This is often something better handled at the firewall. You may want to
talk to your firewall admin to see if they can help you.

> my $sock = new IO::Socket::INET(
>       LocalPort => $port,
>       Proto => 'tcp',
>       Listen => SOMAXCONN,
>       Reuse => 1);
> $sock or die "no socket : $!";
> 
> if ($pid = fork)  {
>    log_msg("Parent spawning child process $pid", $logfile);
>    close $client;
> } elsif (defined ($pid = fork))  {

This is not correct. You will end up forking twice, which is not what
you meant. You want something more

    my $pid = fork;

    unless (defined $pid) {
        die "fork failed: $!";
    }

    if ($pid) {
        # parent
    }
    else {
        # child
    }

>    if ($sock->peerhost() ne $accepted_ip)  {
>      printf "$timestamp   Connection from $accepted_ip rejected\n";
>      close $client;
> 
> 
> the $sock->PeerHost() is not evaluating as expected.  Is this used on
> the server side?  how to accomplish what I want?

You haven't called ->accept, so you haven't actually made a connection
yet. ->accept returns a new socket for each connection, and it is that
socket which has a valid ->peerhost. For example,

    my $S = IO::Socket::INET->new(
        LocalPort => $port,
        Listen    => 1,
    );

    my $C = $S->accept;

    warn "Got connection from " . $C->peerhost;

Ben



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

Date: Thu, 26 Mar 2009 07:54:30 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: help with IO::Socket:INET
Message-Id: <c669af35-d4b2-46b6-8486-8d682a4b68d6@f19g2000vbf.googlegroups.com>

On Mar 26, 9:58 am, me <eba...@yahoo.com> wrote:
> Hi, I'm using IO::Socket:INET in a client/server connect and all is
> working well but I want to restrict connections on the server side by
> only allowing certain IP addresses to connect (or in the case I was
> working to drop the connection if the IP is not contained in a list).
>
> my $sock = new IO::Socket::INET(
>       LocalPort => $port,
>       Proto => 'tcp',
>       Listen => SOMAXCONN,
>       Reuse => 1);
> $sock or die "no socket : $!";
>
> if ($pid = fork)  {
>    log_msg("Parent spawning child process $pid", $logfile);
>    close $client;} elsif (defined ($pid = fork))  {
>

print "Remote:",$sock->peerhost(),": Accept:",$accepted_ip,":\n";

>    if ($sock->peerhost() ne $accepted_ip)  {
>      printf "$timestamp   Connection from $accepted_ip rejected\n";

Note that you are printing the wrong address here. ^^

>      close $client;
>
> the $sock->PeerHost() is not evaluating as expected.  Is this used on
> the server side?  how to accomplish what I want?

String comparisons of numeric data could have a problem if the
data is not in the same exact form.  IPv4 addresses can always
be converted to a 32-bit integer.



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

Date: Thu, 26 Mar 2009 12:51:25 GMT
From: hymie@lactose.homelinux.net (hymie!)
Subject: Re: How to sleep less then 1 second
Message-Id: <hTKyl.170071$xK6.155219@newsfe12.iad>

In our last episode, the evil Dr. Lacto had captured our hero,
  Jürgen Exner <jurgenex@hotmail.com>, who said:


>"tower.grv@gmail.com" <tower.grv@gmail.com> wrote:
>>sleep(1) is not good for me. Usually it is needed to sleep less then
>>second.
>
>You may want to check the FAQ: "perldoc -f second"

s/f/q/

:)

--hymie!    http://lactose.homelinux.net/~hymie    hymie@lactose.homelinux.net
------------------------ Without caffeine for 877 days ------------------------


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

Date: Thu, 26 Mar 2009 06:39:32 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: logic, algorithms, and (Perl) data structures
Message-Id: <d3ee1ec4-548e-4d8d-ab79-93ec7e6b25d8@e25g2000vbe.googlegroups.com>

I've been given an assignment to revive a project that was apparently
abandoned by the original developers, and I need some help thinking
through the logic.

The DB has Person table with the name, address, etc., of individual
people. This should have been called the Actors table, but it's too
late now. The names are identifiers, and I know names are not unique,
individuals having several names (J. Smith, Jim Smith, and James Smith
are all the same person) and names being shared by individuals (three
people all named Jim Smith) but we are dealing with this as I indicate
below.

The DB also has an Accounts table for discrete events. Should have
been called the Events table, but never mind. This list events by ID,
which is a unique identifier. The idea is that an Even (or Account)
has a primary Actor (Person) with other actors associated with the
event in one way or another. There are often multiple accounts
concerning the same person with different ID numbers. For example,
medical events may record a broken arm, sprained ankle, and cuts and
abrasions for the same person in three different records.

Accounts are pushed in CSV files and inserted into the database in an
automated manner. Each row contains the data defining the account and
the primary actor. These rows are not currently split, and all the
data gets inserted into the Account table. The secondary actors are
inserted into the Person table.

I would like to split the account records, insert the account specific
data into the Account table and the person specific data into the
Person table. This means associating each account with the primary
person, which means checking the import names against the Person
table. (The fact that we can't uniquely identify the people means that
the accounts must be manually worked, and the client has a staff that
already does this. This is a data problem, not a software problem,
that I am not responsible for.)

The Person table isn't large now, but we anticipate that it will grow
to several million records. Each import file, the accounts, has from
20 to 50 records. There can be as many as 50 per day.

Each day, I read the Person table into a hash that has elements that
look like this: %person --> $person{$last}{$first}{$middle}{$suffix}

I split each record into a series of scalars, including a hash that
looks like this: %account_person  --> $account_person{$last}{$first}
($middle}($suffix}.

If there isn't a match, the account is read into Account and the
person is read into Person. If there is a match, the record is flagged
for manual handling.

I've been thinking about Schwartzian Transforms and Guttman-Rosler
Transforms, and am wondering of this is the best way to handle this.
I'm not concerned with real time processing since this is handled off-
line, but I'd like to make it as efficient as I can.

Thanks, CC.


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

Date: Thu, 26 Mar 2009 08:00:01 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: logic, algorithms, and (Perl) data structures
Message-Id: <bba2eee2-be20-4864-9675-ebcca5c816c2@r29g2000vbp.googlegroups.com>

On Mar 26, 9:39 am, ccc31807 <carte...@gmail.com> wrote:

>
> I've been thinking about Schwartzian Transforms and Guttman-Rosler
> Transforms, and am wondering of this is the best way to handle this.
> I'm not concerned with real time processing since this is handled off-
> line, but I'd like to make it as efficient as I can.
>
> Thanks, CC.


My advice:
1) define the operations you want to do
2) lay out tables to simplify the operations
3) write the SQL needed to perform the operations
4) write the perl glue
5) test, test, test, test, test
 ...
97) worry about the efficiency of the perl code


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

Date: Thu, 26 Mar 2009 00:26:36 -0700 (PDT)
From: alfonsobaldaserra <alfonso.baldaserra@gmail.com>
Subject: Re: monitoring oracle rac services
Message-Id: <c064ff0d-541a-4f6b-a1ef-e594251a4c38@d2g2000pra.googlegroups.com>

> i need to monitor only specific services so we can pass the service
> name as argument and check it's output.
>
> the problem is i cannot relate NAME with STATE to check it's current
> state, for example, if i do
>

i guess i can load all the values in hash like

NAME=ora.srv04.ASM2.asm
TYPE=application
TARGET=ONLINE
STATE=ONLINE on srv04

my %services = (
   NAME => ora.srv04.ASM2.asm,
   TYPE => application,
   TARGET => ONLINE
   STATE => ONLINE on srv04
);

but i still cannot figure how to relate TYPE, TARGET and STATE for
argument NAME.


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

Date: Thu, 26 Mar 2009 09:01:36 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: monitoring oracle rac services
Message-Id: <86bpro2xj3.fsf@lifelogs.com>

On Thu, 26 Mar 2009 00:26:36 -0700 (PDT) alfonsobaldaserra <alfonso.baldaserra@gmail.com> wrote: 

>> i need to monitor only specific services so we can pass the service
>> name as argument and check it's output.
>> 
>> the problem is i cannot relate NAME with STATE to check it's current
>> state, for example, if i do
>> 

a> i guess i can load all the values in hash like

a> NAME=ora.srv04.ASM2.asm
a> TYPE=application
a> TARGET=ONLINE
a> STATE=ONLINE on srv04

a> my %services = (
a>    NAME => ora.srv04.ASM2.asm,
a>    TYPE => application,
a>    TARGET => ONLINE
a>    STATE => ONLINE on srv04
a> );

a> but i still cannot figure how to relate TYPE, TARGET and STATE for
a> argument NAME.

You can do this with a hash or with a nicer OO framework like Moose.
I'd recommend Moose, unless performance is an issue.  Just get it from
CPAN, set up your rw fields named Type, Target, State, and Name.  That's
it, you can start using those objects.

With a hash this is easy but inflexible:

my %services;

$services{'ora.src04.ASM2.asm'} = { 
 NAME => 'ora.srv04.ASM2.asm', # you don't need it, the key already has the name
 TYPE => 'application',
 TARGET => 'ONLINE',
 STATE => 'ONLINE on srv04',
};

Ted


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

Date: Thu, 26 Mar 2009 04:42:25 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Thu Mar 26 2009
Message-Id: <KH3Jqp.8Iq@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.

App-DualLivedDiff-1.07
http://search.cpan.org/~smueller/App-DualLivedDiff-1.07/
Diff between the perl core and dual-lived modules' CPAN distributions 
----
App-Toodledo-0.04
http://search.cpan.org/~pjs/App-Toodledo-0.04/
Interacting with the Toodledo task management service. 
----
Authen-Htpasswd-Trac-0.00001
http://search.cpan.org/~nishikawa/Authen-Htpasswd-Trac-0.00001/
interface to read and modify Trac password files 
----
Authen-Simple-IMAP-0.1.0
http://search.cpan.org/~dmartin/Authen-Simple-IMAP-0.1.0/
Simple IMAP and IMAPS authentication 
----
Business-OnlinePayment-PaymenTech-1.2
http://search.cpan.org/~gphat/Business-OnlinePayment-PaymenTech-1.2/
PaymenTech backend for Business::OnlinePayment 
----
CPAN-Test-Dummy-Perl5-Make-PerlReq-Fail-0.001
http://search.cpan.org/~dagolden/CPAN-Test-Dummy-Perl5-Make-PerlReq-Fail-0.001/
CPAN Test Dummy that fails to find a required version of Perl 
----
Catalyst-Action-REST-0.67_01
http://search.cpan.org/~hdp/Catalyst-Action-REST-0.67_01/
Automated REST Method Dispatching 
----
Catalyst-Controller-SOAP-1.12
http://search.cpan.org/~druoso/Catalyst-Controller-SOAP-1.12/
Catalyst SOAP Controller 
----
Collection-0.44
http://search.cpan.org/~zag/Collection-0.44/
Collections framework for CRUD of the data or objects. 
----
Drupal-Admin-0.02
http://search.cpan.org/~durist/Drupal-Admin-0.02/
screen scraping Perl API to some Drupal admin functions 
----
Email-Sender-Transport-SMTP-TLS-0.02
http://search.cpan.org/~fayland/Email-Sender-Transport-SMTP-TLS-0.02/
Email::Sender with Net::SMTP::TLS (Eg. Gmail) 
----
Encode-2.33
http://search.cpan.org/~dankogai/Encode-2.33/
character encodings 
----
Env-Export-0.12
http://search.cpan.org/~rjray/Env-Export-0.12/
Export %ENV values as constant subroutines 
----
FreeBSD-Pkgs-0.1.1
http://search.cpan.org/~vvelox/FreeBSD-Pkgs-0.1.1/
Reads the FreeBSD installed packaged DB. 
----
FreeBSD-Pkgs-FindUpdates-0.2.0
http://search.cpan.org/~vvelox/FreeBSD-Pkgs-FindUpdates-0.2.0/
Finds updates for FreeBSD pkgs by checking the ports index. 
----
FreeBSD-Ports-INDEXhash-1.2.0
http://search.cpan.org/~vvelox/FreeBSD-Ports-INDEXhash-1.2.0/
Generates a hash out of the FreeBSD Ports index file. 
----
HTML-TreeBuilder-LibXML-0.02
http://search.cpan.org/~tokuhirom/HTML-TreeBuilder-LibXML-0.02/
HTML::TreeBuilder::XPath compatible interface with libxml 
----
HTML-TreeBuilder-LibXML-0.03
http://search.cpan.org/~tokuhirom/HTML-TreeBuilder-LibXML-0.03/
HTML::TreeBuilder::XPath compatible interface with libxml 
----
HTTP-Engine-0.1.5
http://search.cpan.org/~yappo/HTTP-Engine-0.1.5/
Web Server Gateway Interface and HTTP Server Engine Drivers (Yet Another Catalyst::Engine) 
----
HTTP-MobileAttribute-0.14
http://search.cpan.org/~tokuhirom/HTTP-MobileAttribute-0.14/
Yet Another HTTP::MobileAgent 
----
Jifty-DBI-0.53
http://search.cpan.org/~alexmv/Jifty-DBI-0.53/
An object-relational persistence framework 
----
Math-Random-ISAAC-1.0
http://search.cpan.org/~frequency/Math-Random-ISAAC-1.0/
Perl interface to the ISAAC PRNG Algorithm 
----
MooseX-InstanceTracking-0.02
http://search.cpan.org/~sartak/MooseX-InstanceTracking-0.02/
Trait for tracking all instances of a class 
----
Net-LimeLight-Purge-0.01
http://search.cpan.org/~gphat/Net-LimeLight-Purge-0.01/
LimeLight Purge Service API 
----
Net-Twitter-2.12
http://search.cpan.org/~cthom/Net-Twitter-2.12/
Perl interface to twitter.com 
----
Net-Whois-Raw-1.65
http://search.cpan.org/~despair/Net-Whois-Raw-1.65/
Get Whois information for domains 
----
POE-Component-IRC-Plugin-MegaHAL-0.17
http://search.cpan.org/~hinrik/POE-Component-IRC-Plugin-MegaHAL-0.17/
A PoCo-IRC plugin which provides access to a MegaHAL conversation simulator. 
----
POE-Component-IRC-Plugin-MegaHAL-0.18
http://search.cpan.org/~hinrik/POE-Component-IRC-Plugin-MegaHAL-0.18/
A PoCo-IRC plugin which provides access to a MegaHAL conversation simulator. 
----
POE-Component-IRC-Plugin-MegaHAL-0.19
http://search.cpan.org/~hinrik/POE-Component-IRC-Plugin-MegaHAL-0.19/
A PoCo-IRC plugin which provides access to a MegaHAL conversation simulator. 
----
POSIX-Regex-1.0001
http://search.cpan.org/~jettero/POSIX-Regex-1.0001/
OO interface for the gnu regex engine 
----
Perl-Critic-Pulp-15
http://search.cpan.org/~kryde/Perl-Critic-Pulp-15/
some add-on perlcritic policies 
----
RDF-AllegroGraph-Easy-0.01
http://search.cpan.org/~drrho/RDF-AllegroGraph-Easy-0.01/
Simplistic Interface to AllegroGraph HTTP server 
----
Set-Relation-0.9.0
http://search.cpan.org/~duncand/Set-Relation-0.9.0/
Relation data type for Perl 
----
Spreadsheet-XLSX-0.1
http://search.cpan.org/~dmow/Spreadsheet-XLSX-0.1/
Perl extension for reading MS Excel 2007 files; 
----
Test-Fork-0.01
http://search.cpan.org/~tokuhirom/Test-Fork-0.01/
fork test 
----
Test-SharedFork-0.02
http://search.cpan.org/~tokuhirom/Test-SharedFork-0.02/
fork test 
----
Unix-Lsof-0.0.7
http://search.cpan.org/~marcb/Unix-Lsof-0.0.7/
Wrapper to the Unix lsof utility 
----
Util-Task-0.01_1
http://search.cpan.org/~mart/Util-Task-0.01_1/
Abstract class representing a possibly-coalescable task. 
----
Variable-Magic-0.33
http://search.cpan.org/~vpit/Variable-Magic-0.33/
Associate user-defined magic to variables from Perl. 
----
WWW-MobileCarrierJP-0.30
http://search.cpan.org/~tokuhirom/WWW-MobileCarrierJP-0.30/
scrape mobile carrier information 
----
WWW-Search-AOL-0.0103
http://search.cpan.org/~shlomif/WWW-Search-AOL-0.0103/
backend for searching search.aol.com 
----
Weather-Bug-0.24
http://search.cpan.org/~gwadej/Weather-Bug-0.24/
Provide an object oriented interface to the WeatherBug API. 
----
XML-Compile-1.03
http://search.cpan.org/~markov/XML-Compile-1.03/
Compilation based XML processing 
----
XML-Compile-SOAP-2.03
http://search.cpan.org/~markov/XML-Compile-SOAP-2.03/
base-class for SOAP implementations 
----
XML-Reader-0.01
http://search.cpan.org/~keichner/XML-Reader-0.01/
Reading XML and providing path information based on a pull-parser. 
----
XML-Reader-0.02
http://search.cpan.org/~keichner/XML-Reader-0.02/
Reading XML and providing path information based on a pull-parser. 


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/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


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

Date: Thu, 26 Mar 2009 14:58:47 +0100
From: "Mark" <liarafan@xs4all.nl>
Subject: Re: Sharing BerkeleyDB among forked children
Message-Id: <c5OdnaHiMYyEF1bUnZ2dnUVZ8ouWnZ2d@giganews.com>

"Mark" <liarafan@xs4all.nl> wrote in message 
news:0JqdnWjvc7mT0VfUnZ2dnUVZ8tyWnZ2d@giganews.com...

Anyone? Anyone? Bueller? Bueller? :)

There's gotta be someone here who understands how
the BerkeleyDB cache works amongst forked children.
I've googled until I saw blue in the face, but strangely
enough there's no info to be found for it.

- Mark 



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

Date: Thu, 26 Mar 2009 00:06:43 -0700 (PDT)
From: Krishna Chaitanya <schaitan@gmail.com>
Subject: Re: Typeglobs vs References
Message-Id: <1b0acd3f-5d4e-4aea-865f-0625fd25a061@a5g2000pre.googlegroups.com>

On Mar 25, 8:18=A0pm, Krishna Chaitanya <schai...@gmail.com> wrote:
> Learned references and their uses in creating data structures. Now
> moving onto typeglobs...

No help? :(


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

Date: Thu, 26 Mar 2009 09:52:30 +0000
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: Typeglobs vs References
Message-Id: <49cb505f$0$2530$da0feed9@news.zen.co.uk>


Krishna Chaitanya wrote:
> On Mar 25, 8:18 pm, Krishna Chaitanya <schai...@gmail.com> wrote:
>> Learned references and their uses in creating data structures. Now
>> moving onto typeglobs...
> 
> No help? :(

I suggest you ignore typeglobs. I've managed for decades without knowing 
about them. If you are learning Perl I think your efforts would be more 
usefully directed to other aspects of Perl. I'd learn popular varieties 
of Perl OO before typeglobs.

Just my ¤0.02 worth.

-- 
RGB


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

Date: Thu, 26 Mar 2009 05:32:15 -0700 (PDT)
From: Krishna Chaitanya <schaitan@gmail.com>
Subject: Re: Typeglobs vs References
Message-Id: <34f148a0-216d-4c55-8999-5c9f7e10cfc2@i28g2000prd.googlegroups.com>

I was forced to notice them while using modules like IPC::* (open3,
etc). I agree most perl coding can do without typeglobs, but I
definitely wouldn't want to be ignorant on a day when I have to use
them. Started reading up about these entities.....they are definitely
mysterious (esp, in "perlsub" - passing arguments by reference vs.
indirection).

Also, dealing with filehandles, passing them around to subroutines,
don't you agree we need to know abt typeglobs?

Thanks...


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

Date: Thu, 26 Mar 2009 13:41:14 +0100
From: Peter Makholm <peter@makholm.net>
Subject: Re: Typeglobs vs References
Message-Id: <878wmsxxqt.fsf@vps1.hacking.dk>

Krishna Chaitanya <schaitan@gmail.com> writes:

> Also, dealing with filehandles, passing them around to subroutines,
> don't you agree we need to know abt typeglobs?

Except for the third argument to open3 I can't remember I have any
problmes with using lexical filehandles alle places where I'm using
filehandles.

Only time I messes around with typeglobs are when I need aliases to
names where references wouldn't do. Most of the times this is for
autogenerated functions in a package. But even for this I should
probably use Sub::Install instead to hide the messing around with
typeglobs.

//Makholm



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

Date: Thu, 26 Mar 2009 15:05:27 +0000
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: Typeglobs vs References
Message-Id: <49cb99b9$0$16176$db0fefd9@news.zen.co.uk>


Krishna Chaitanya wrote:
> 
> Also, dealing with filehandles, passing them around to subroutines,
> don't you agree we need to know abt typeglobs?

I don't agree.

-----------------------------8<------------------------------
#!/usr/bin/perl
use strict;
use warnings;

open my $fh, '>', "foo.txt" or die "can't open foo.txt - $!\n";
foo($fh);
close $fh;

sub foo {
   my $handle = shift;
   print $handle "foo!\n" or die "can't write - $!\n";
}
-----------------------------8<------------------------------

 >perl t2.pl
 >cat foo.txt
foo!

-- 
RGB


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

Date: Thu, 26 Mar 2009 02:20:31 GMT
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: what is the return value type of !1 ?
Message-Id: <slrngslpjf.kf2.nospam-abuse@chorin.math.berkeley.edu>

On 2009-03-25, Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:

>>     Truth and Falsehood
>>
>>     The number 0, the strings '0' and '', the empty list "()", and
>>     "undef" are all false in a boolean context.  All other values are
>>     true.

> Wrong.

This one is wrong indeed...

>>     Negation of a true value by "!" or "not" returns a special
>>     false value.  When evaluated as a string it is treated as '', but
>>     as a number, it is treated as 0.
>
> There is nothing especially "special" about the returned value (unless
> one noticed that it is the same value for all statements returning FALSE).

 ... but here I was wrong: I forgot that + is different from ++.  ++
does not warn when applied to an empty string (well, even on undefined
value!); but + does - UNLESS this empty string is what is known as
&sv_false in Perl-internal speak...

Thanks for all the people who finilly got through my defence lines and
convinced me to check my faulty memory!
Ilya


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

Date: Thu, 26 Mar 2009 02:30:55 GMT
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: what is the return value type of !1 ?
Message-Id: <slrngslq6v.kf2.nospam-abuse@chorin.math.berkeley.edu>

On 2009-03-25, Ben Morrow <ben@morrow.me.uk> wrote:
> There is *something* there. If the parens were only there for
> precedence, they could safely be omitted, which they can't:
>
>     ~% perl -e'unless ( () ) { 1 }'
>     ~% perl -e'unless (    ) { 1 }'
>     syntax error at -e line 1, near "(    ) "
>     Execution of -e aborted due to compilation errors.
>     ~%

Having read and debugged perly.y, I won't think that any argument
about boundary cases based ONLY on perl syntax parser error messages
is very well-founded...  Quite often the parser works "in this or that
way" not because

  people wanted to make it work in this way,

but because

  people did not find a way to convince the parser to work some other way...

>> (parens are not a "list constructor". You very often see lists in
>>  parens but that is for precedence reasons.
>> )
>
> While this is generally true, () is special (under some circumstances:
> the parsing of parens in Perl is very complicated and context-
> dependant). It represents the empty list, which evaluates to undef in
> scalar context:

I think that keeping distinction between list and array is very
helpful, but sometimes one needs a different distinction: "lists as
constructed by comma operator", and "lists as returned by Perl
internal and XSUB functions".

Note that the second kind of lists cannot appear in scalar context.
The first one can; but AFAIK, the usual description DOES NOT specify
the result of evaluation of empty comma-list in scalar context...

Hope this helps,
Ilya


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

Date: Thu, 26 Mar 2009 02:36:54 GMT
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: what is the return value type of !1 ?
Message-Id: <slrngslqi6.kf2.nospam-abuse@chorin.math.berkeley.edu>

On 2009-03-25, Tim McDaniel <tmcd@panix.com> wrote:
>>>     Truth and Falsehood
>>>
>>>     The number 0, the strings '0' and '', the empty list "()", and
>>>     "undef" are all false in a boolean context.  All other values
>>>     are true.

>>Wrong.

> I would like to learn more about Perl, so would you please explain
> what is correct?

As other people explained, the list in scalar context is kinda fishy...

But what is very definitely wrong is the last part:

  perl -wle "{package o; use overload q(\"\") => sub{q(one but false)},
	      q(0+) => sub {11}, bool => sub {} }"
     -e "$v=bless [], o; printf qq(%d; %s; ), $v, $v; print q(FALSE) unless $v"

  11; one but false; FALSE

Hope this helps,
Ilya


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

Date: Thu, 26 Mar 2009 09:38:22 +0100
From: Peter Makholm <peter@makholm.net>
Subject: Re: what is the return value type of !1 ?
Message-Id: <87k56cy8zl.fsf@vps1.hacking.dk>

Uri Guttman <uri@stemsystems.com> writes:

>>>>>> "PM" == Peter Makholm <peter@makholm.net> writes:
>
>   PM> Ben Morrow <ben@morrow.me.uk> writes:
>   >> Well, it's a dualvar, which is reasonably special. It is possible to
>   >> create an equivalent dualvar with
>   >> 
>   >> use Scalar::Util;
>   >> 
>   >> my $false = dualvar 0, "";
>
>   PM> This is not quite the same value as I get with !1. The latter has bot
>   PM> the IOK and NOK flags set but with dualvar I can only get one of these
>   PM> flags set together with POK.
>
> you seem to be wrong here. both have a string value set and POK as well.

That is what I said. Both values has POK set. But !1 has both IOK and
NOK set but dualvar only one of them, just like you examples
shows. For some reason I didn't manage to come up with you third
example which shows that the !1-false isn't really sepcial.

//Makholm


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

Date: Thu, 26 Mar 2009 02:50:50 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: what is the return value type of !1 ?
Message-Id: <a57r96-hse.ln1@osiris.mauzo.dyndns.org>


Quoth Ilya Zakharevich <nospam-abuse@ilyaz.org>:
> On 2009-03-25, Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
> 
> >>     Truth and Falsehood
> >>
> >>     The number 0, the strings '0' and '', the empty list "()", and
> >>     "undef" are all false in a boolean context.  All other values are
> >>     true.
> 
> > Wrong.
> 
> This one is wrong indeed...

For those following along at home, an example of a scalar which is false
but isn't listed above is Scalar::Util::dualvar(42, "0"). Another, less
obscure, would be an object with "bool" overloading that returns false.

Ben



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

Date: Thu, 26 Mar 2009 08:55:01 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: what is the return value type of !1 ?
Message-Id: <x7tz5g8k3u.fsf@mail.sysarch.com>

>>>>> "PM" == Peter Makholm <peter@makholm.net> writes:

  PM> Uri Guttman <uri@stemsystems.com> writes:
  >>>>>>> "PM" == Peter Makholm <peter@makholm.net> writes:
  >> 
  PM> Ben Morrow <ben@morrow.me.uk> writes:
  >> >> Well, it's a dualvar, which is reasonably special. It is possible to
  >> >> create an equivalent dualvar with
  >> >> 
  >> >> use Scalar::Util;
  >> >> 
  >> >> my $false = dualvar 0, "";
  >> 
  PM> This is not quite the same value as I get with !1. The latter has bot
  PM> the IOK and NOK flags set but with dualvar I can only get one of these
  PM> flags set together with POK.
  >> 
  >> you seem to be wrong here. both have a string value set and POK as well.

  PM> That is what I said. Both values has POK set. But !1 has both IOK and
  PM> NOK set but dualvar only one of them, just like you examples
  PM> shows. For some reason I didn't manage to come up with you third
  PM> example which shows that the !1-false isn't really sepcial.

well that is because dualvar is called DUALvar! it only sets the string
and integer parts and not the number (float) part. builtin false knows
that it is also a valid number (probably just zeroes out the float slot)
and so does !1 since that is the same. look at this variant:

 perl -MDevel::Peek -MScalar::Util=dualvar -le' print Dump dualvar 0.0, ""'
SV = PVNV(0x8161a38) at 0x8163248
  REFCNT = 1
  FLAGS = (TEMP,NOK,POK,pNOK,pPOK)
  IV = 0
  NV = 0
  PV = 0x8173228 ""\0
  CUR = 0
  LEN = 4

dualvar on 0.0 sets NOK and not IOK. so it knows the internal parsed 0.0
is a number and DWIMs. it still only sets 2 of the possible 3 values.

so this is just a weakness on dualvar's part that it can only set the
number or integer slot. i can't seem to force that. it always sets the
string slot (POK).
the 

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


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

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 V11 Issue 2299
***************************************


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