[19659] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1854 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 2 03:05:37 2001

Date: Tue, 2 Oct 2001 00:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1002006308-v10-i1854@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 2 Oct 2001     Volume: 10 Number: 1854

Today's topics:
        .NET Presentation -- San Francisco -- October 4 (ADDWebSite)
    Re: alternatives to ps command (David Combs)
    Re: binmode with "perl -p" doesn't work (John Lin)
        Can't unlink file under Perl for NT <glenn@surveystar.com>
        Creating hash using array (newbie) <changinsub@hotmail.com>
    Re: Creating hash using array (newbie) <mbudash@sonic.net>
    Re: GIF encoding <pne-news-20011002@newton.digitalspace.net>
    Re: how to get rid of spaces around a string? <theaney@toadmail.toad.net>
    Re: how to get rid of spaces around a string? <jurgenex@hotmail.com>
    Re: how to get rid of spaces around a string? <wyzelli@yahoo.com>
    Re: how to send mail without sendmail (Mario Rizzuti)
    Re: IO::Socket && IO::Select Problem (NuArb)
    Re: Module File::Find and 'prune' variable <dtweed@acm.org>
        newbie question on objects and dereferencing (Old Lars)
    Re: Sorting multidimensional arrays and MIN/MAX (Martien Verbruggen)
    Re: Using TAB - Newbie Question (Damian James)
        XS Question <adverts@teaselsyn.co.uk>
    Re: XS Question <joe+usenet@sunstarsys.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 02 Oct 2001 07:03:30 GMT
From: addwebsite@aol.com (ADDWebSite)
Subject: .NET Presentation -- San Francisco -- October 4
Message-Id: <20011002030330.16745.00003392@mb-cg.aol.com>

San Francisco Bay Area Association of Database Developers
Annual Meeting
425 Market Street, Room 208
San Francisco

Thursday, October 4, 2001
6:30 PM
 
Food:

This year we're providing a huge assortment of party platters from Chevy's,
along with cold beverages. 

Prizes:

Various items will be raffled off during the evening, including gift
certificates for Stacey's bookstore.

Cost:

This event is free for current ADD members.  If your membership is about to
expire, this is a great time to renew.  The cost for guests, non-members, and
expired members will be $10.00 for the presentation and an optional $10.00 for
dinner.  

RSVP:

Please e-mail your RSVP to ADDWebSite@aol.com, and tell us if you will be
bringing one or more guests.  Also, please indicate where you saw this
announcement.

Agenda:

6:30 - Check-in, renew memberships, website photos 
6:45 - Dinner, introduction of board candidates, balloting
7:30 - Presentation
8:30 - 15-minute break, announcement of election results
8:45 - Presentation
9:30 - Wrap-up

Link: 

http://www.magenic.com

Speaker and Topic:

So, there you are immersed in desktop or web app development, battling current
or legacy technologies in Fox 2.x, VFP, SQL, Access and/or VB. Your clients
want it all web enabled, and you're bouncing around between ASP, WebConnection,
Cold Fusion, or open source.  You're finally getting a handle on ADO and stored
procedures, mastering OLEDB, and finally realize that ActiveX is nothing more
than OLE, and DNA is just a marketing term for n-tier distributed
architectures. ASP has revved from 2.0 to 3.0, IIS 4 to IIS 5, you've gotten
2000 installed and stable, and now you have to learn... 'Dot What'? NO WAY! 
 
But you have to at least understand what .NET is, why it is, how it works and
what it all means. You have to take it seriously enough to at least understand
how it will affect you. And now, here's your chance. 
 
The annual meeting of the ADD will feature Martin Triplett of Magenic (see
below) presenting on .NET.  His presentation is being specially customized for
the ADD membership to provide an overview and introduction of what .NET is,
what a .NET application looks like, and an overview of the breadth and depth of
this new paradigm shift from Microsoft that is now bearing down upon us.  It
will include demonstrations (time allowing) of web services, web forms,
winforms, and the data engine ADO.NET, and will include information on the
languages and platform foundation.  He will be showing demo applications and
sample code, and he should leave you with at least a good understanding of what
it is and how it may affect you in the coming years.   
 
Martin Triplett is a 14-year veteran Developer, Technical Architect, Team Lead,
Multi-Team Lead, Designer, Project Manager, Trainer and Mentor. Currently a
Principal Consultant with Magenic Technologies, his broad collection of skills
include Internet technologies such as .NET, COM, Components, and Web Services
as well as multiple languages such as ASP.NET, VB.NET, VB 3-6, PL/SQL, C++, C#
and TransactSQL. His database experiences span SQL Server 6.5-2000, Oracle,
Informix and Access.  His industry knowledge includes E-Commerce, Retail,
Telecom, Manufacturing, Healthcare, Financial, Utilities and Real Estate. 
 
Magenic is a premiere Microsoft Gold Certified Partner with offices in Atlanta,
Dallas, Minneapolis, and the San Francisco Bay Area, working with a wide
variety of clients ranging from ISVs to innovative Fortune 1000 companies. 
They provide expertise in E-Commerce application development, Distributed
Application Development, Application Integration and Enterprise Data Services
(Business Intelligence).



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

Date: 2 Oct 2001 06:59:48 GMT
From: dkcombs@panix.com (David Combs)
Subject: Re: alternatives to ps command
Message-Id: <9pbol4$hso$1@news.panix.com>

In article <5d4a715a.0109240540.7ae1a16f@posting.google.com>,
Ilja Tabachniks <billy@arnis-bsl.com> wrote:
><SNIP>
>
>Check your system's man ps for more information. To preserve portability
>take a look at ps(1) from Single Unix Specification at
>http://www.opengroup.org/onlinepubs/007908799/xcu/ps.html.
>
>For example, the following command works on Solaris, AIX and linux
>and presensts an (almost) identically formatted result:
>
>ps -u ilja -o pid= -o user= -o vsz= -o etime= -o time= -o args=
>
>Hope this helps.
>Ilja.


But *not* on netbsd, at least not at my shell-ISP, panix.com:

> !ps:p
ps -u ilja -o pid= -o user= -o vsz= -o etime= -o time= -o args=
> ^ilja^dkcombs
ps -u dkcombs -o pid= -o user= -o vsz= -o etime= -o time= -o args=
ps: kvm_openfiles: -o: No such file or directory
ps: falling back to /proc-based lookup
ps: statfs on /proc failed: No such file or directory
ps: fallback /proc-based lookup also failed.  Giving up...
> 


David



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

Date: 2 Oct 2001 00:00:18 -0700
From: johnlin@chttl.com.tw (John Lin)
Subject: Re: binmode with "perl -p" doesn't work
Message-Id: <a73bcad1.0110012300.53397c24@posting.google.com>

Bart Lateur wrote
> John Lin wrote:
> 
> >I was preparing to give this answer (1.doc is a MS-Word file):
> >
> >perl -i.bak -0777 -ple "BEGIN{binmode STDIN; binmode STDOUT} s/abc/123/g" 1.doc
> >
> >but I found binmode doesn't work with "perl -p".
> >The file size is changed.  Is this a bug of ActivePerl?
> 
> I think it is because your file doesn't come in on STDIN, but on ARGV,
> and your STDOUT isn't the same STDOUT you started with.
> 
> I don't think you can achieve this. You should set binmode on ARGV (not
> STDIN) everytime a new file is opened,but *before* anything is read. And
> that is impossible. If <> sees no file open, it will get the next file
> from @ARGV, open it, and read a line, before you get a chance to set
> binmode.

Thank you.

So, do you think my proposal of "perl -b" switch for binmode is considerable?
What can I contribute to make it happen?

John Lin


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

Date: Tue, 02 Oct 2001 01:16:13 GMT
From: Glenn <glenn@surveystar.com>
Subject: Can't unlink file under Perl for NT
Message-Id: <3BB91332.152A5049@surveystar.com>

I can't seem to be able to delete a file via a Perl script under Win
NT.  Have tried many things -- most recently this simple test...

    open (OUTFILE,"> e:/somedir/testfile.zzz");   #open it
    printf OUTFILE "some test data\n";                # write something
    close (OUTFILE);                                         # be sure
to close it
    unlink("e:/somedir/testfile.zzz") || print "could not delete  $!";
# then delete it

The file gets created (it is there), but not deleted.  I get a
"Permission denied" error.  Don't ask why I am creating a file just to
delete it -- my real use involves use of temporary files which I want to
clean up when done. Any thoughts appreciated.  Thanks!




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

Date: Fri, 28 Sep 2001 16:41:15 -0400
From: "Insub Chang" <changinsub@hotmail.com>
Subject: Creating hash using array (newbie)
Message-Id: <Gb5t7.115$4W2.165@news-srv1.fmr.com>

Hi, all.
Let me make this short. I have an array :
@array qw(1 2 3 2 4 5 5 8 2 1)

Now, I want to know how many distict array value are in @array. Also I need
to know how many times an @array value repeated. For example, @array has
disctict value as;
1 -> 2 times
2 -> 3 times
3 -> 1 times
4 -> 1 times
5 -> 2 times
8 -> 1 times

The whole purpose of this script is for counting IP address and hitting
number from web server's logfile.
For example, @array values are IP address. And I need to know which IP
address is hitting my server and how many times on a certain day.

I will be appreciate your help.






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

Date: Tue, 02 Oct 2001 06:05:44 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Creating hash using array (newbie)
Message-Id: <mbudash-D6A7CC.23054701102001@news.sonic.net>

In article <Gb5t7.115$4W2.165@news-srv1.fmr.com>, "Insub Chang" 
<changinsub@hotmail.com> wrote:

> Hi, all.
> Let me make this short. I have an array :
> @array qw(1 2 3 2 4 5 5 8 2 1)
> 
> Now, I want to know how many distinct array value are in @array. Also I 
> need
> to know how many times an @array value repeated. For example, @array has
> distinct value as;
> 1 -> 2 times
> 2 -> 3 times
> 3 -> 1 times
> 4 -> 1 times
> 5 -> 2 times
> 8 -> 1 times
> 

i'm sure some clever person will come up with something else, but this 
certainly works:
 
my @array = qw(1 2 3 2 4 5 5 8 2 1);
my %hash;
foreach (@array) {
 $hash{$_}++;
}
print "There are ", scalar keys %hash, " distinct values in \@array\n";
foreach (sort keys %hash) {
 print "$_ -> ", $hash{$_}, " times\n";
}

hth-
-- 
Michael Budash ~~~~~~~~~~ mbudash@sonic.net


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

Date: Tue, 02 Oct 2001 07:03:40 +0200
From: Philip Newton <pne-news-20011002@newton.digitalspace.net>
Subject: Re: GIF encoding
Message-Id: <28iirts28kdmuhoisqcnisf1159teajfoc@4ax.com>

(You snipped the bit where I quoted you; I think that belongs in this
discussion.)

On Tue, 2 Oct 2001 09:01:56 +1000, "Gregory Toomey" <nobody@nowhere.com>
wrote:

> "Philip Newton" <pne-news-20011001@newton.digitalspace.net> wrote in message
> news:q91grtsbub7d33nqti1npqjftku6pbkkt5@4ax.com...
> >
> > Then you have an old version of the module. Newer versions of the module
> > will not write GIF but, instead, PNG (and also JPEG), since that's what
> > newer versions of libgd (on which the module is based) write.
> 
> Correct, but some of us have thousands of users around the world with olders
> browsers that support gif but not png.

In that case, you can't point people to "the" GD module, as what people
will download from CPAN or from boutell.com will not be able to produce
GIF images.

So the statement "the GD module ... will write in gif format" is false,
IMO.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: 01 Oct 2001 21:07:22 -0400
From: Tim Heaney <theaney@toadmail.toad.net>
Subject: Re: how to get rid of spaces around a string?
Message-Id: <87vghyhmt1.fsf@susie.watterson>

Zimmen Gnauh <yah00204052@yahoo.com> writes:

>    $string="  abcd  ";
> what function can give me "abcd"?

The answer is right on your hard drive...

  perldoc -q 'How do I strip blank space from the beginning/end of a string?'

Or, if you prefer, on the web

  http://www.perldoc.com/perl5.6.1/pod/perlfaq4.html#How-do-I-strip-blank-space-from-the-beginning-end-of-a-string-

Alternatively, there is this

  http://www.perlfaq.com/cgi-bin/view?view_by_id=122

I hope this helps,

Tim


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

Date: Mon, 1 Oct 2001 19:36:20 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: how to get rid of spaces around a string?
Message-Id: <3bb9282a$1@news.microsoft.com>

"Zimmen Gnauh" <yah00204052@yahoo.com> wrote in message
news:3BB90E92.434B79E@yahoo.com...
>    $string="  abcd  ";
> what function can give me "abcd"?

No function, but of course you can use the substitution or even the
transliterator operator.

    s/^\s*(.*)\s*$/$1/;

should do the job.
Further details see perldoc perlop

jue




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

Date: Tue, 2 Oct 2001 12:20:37 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: how to get rid of spaces around a string?
Message-Id: <6Q9u7.22$xu5.599@wa.nnrp.telstra.net>

"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:3bb9282a$1@news.microsoft.com...
> "Zimmen Gnauh" <yah00204052@yahoo.com> wrote in message
> news:3BB90E92.434B79E@yahoo.com...
> >    $string="  abcd  ";
> > what function can give me "abcd"?
>
> No function, but of course you can use the substitution or even the
> transliterator operator.
>
>     s/^\s*(.*)\s*$/$1/;
>
> should do the job.


But doesn't really,  try:

s/^\s*(.*?)\s*$/$1/;

Which I prefer to the two seperate entries in the FAQ (despite getting in
trouble with certain peoples because of it), because this is a FAQ.

> Further details see perldoc perlop


Wyzelli
--
@x='074117115116032097110111116104101114032080101114108032104097099107101114
'=~/(...)/g;
print chr for @x;




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

Date: 1 Oct 2001 22:05:44 -0700
From: mariorizzuti@yahoo.com (Mario Rizzuti)
Subject: Re: how to send mail without sendmail
Message-Id: <42f3ee2.0110012105.19350f12@posting.google.com>

Zimmen Gnauh <yah00204052@yahoo.com> wrote in message news:<3BB79D91.1247D5A9@yahoo.com>...
> My unix system does not have sendmail (somehow removed by admin). Is
> there any way to send mail without it?

via Socket is a way.

A starting point:
----

use Socket;

$smtp_server = 'smtp.domain.com';
$host_name   = 'XXX';

$from    = 'me@mail.com';
$to      = 'you@mail.com';
$subject = "hi";
$body    = "hello";

send_mail ($from, $to, $subject, $body);

sub send_mail {

   my ( $from , $to , $subject , $body ) = @_;

   $body =~ s/\n\.[\r|\n]/\n. $1/g;   
  
   my $proto = getprotobyname('tcp');
   socket(SERVER, AF_INET, SOCK_STREAM, $proto);
   my $iaddr = gethostbyname($smtp_server);
   my $port = getservbyname('smtp', 'tcp');
   my $sin = sockaddr_in($port, $iaddr);
   
   my $sreply;

   connect(SERVER, $sin);
   recv SERVER, $sreply, 512, 0;   
   
   send SERVER, "HELO $host_name\r\n", 0;
   recv SERVER, $sreply, 512, 0;
   
   send SERVER, "MAIL From:<$from>\r\n", 0;
   recv SERVER, $sreply, 512, 0;
   
   send SERVER, "RCPT To:<$to>\r\n", 0;   
   recv SERVER, $sreply, 512, 0;   
   
   send SERVER, "DATA\r\n", 0;   
   recv SERVER, $sreply, 512, 0;
   
   send SERVER, "Subject: $subject\r\n", 0;
   send SERVER, "\r\n$body\r\n", 0; 
   send SERVER, ".\r\n", 0;
   recv SERVER, $sreply, 512, 0;
   
   send SERVER, "QUIT\r\n", 0;
   recv SERVER, $sreply, 512, 0;
   close SERVER;   
}

---
Mario Rizzuti


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

Date: 1 Oct 2001 23:40:10 -0700
From: tristan.braun@gmx.net (NuArb)
Subject: Re: IO::Socket && IO::Select Problem
Message-Id: <3dae1176.0110012240.7bd13ffc@posting.google.com>

"Benjamin Goldberg" <goldbb2@earthlink.net> schrieb im Newsbeitrag
news:3BB6AE5E.AA1B7EC9@earthlink.net...

Hi !

Thanks for the time you spend to help me !

 ...
> > The same result is when I startet the VB MDI on two NT boxes with each
> > have 50 instances.
> > 
> > And when try more than 127 connections + 1 listen my perlserver
> > crashes.
> 
> That *sounds* like you've got a system limit on the number of open
> connections.  What kind of error does perl output to the console when it
> crashes?

None ! I call the script with "perl -Tw chat.pl" and the result on the
console is the
following:

IP [fileno]: Message [IO::Select->Count()]

 ...
10.84.39.163[127]: Connected [124]
10.84.39.163[128]: Connected [125]
E:\Perl>

Thats it ! No errormessage !

The problem is not the amount of open connections. The problem is
IO::Select. It can not handle more than 128.

If I try to the code without IO::Select than I can accept 128+.

> Might I suggest that you run a number of servers on your machine to
> spread the load?

And what kind of communication would you prefer between the servers ? 
 
> Also... I see a number of improvements that could be made in the code
> you have.

[snip]
> #!/usr/local/bin/perl -w
> use strict; # always use -w and strict
> use IO::Socket;
> # don't need to use IO::Socket::INET,
> # since it IO::Socket makes it available.
> use IO::Select;
> 
> # no need to make the log object-oriented.
> $SIG{INT} = sub { close CHATLOG; exit 0 };
 ...
>     foreach my $socket ( $writing->can_read(0) ) {
>         my $client = $clients{$socket};
>         local *buffer = \$client{output};
>         my $wrote = syswrite( $socket, $buffer ) or do {
>             debug($client, "failed to write: $!");
>             close $socket;
>             $reading->remove($socket);
>             $writing->remove($socket);
>             delete $clients{$socket};
>             next;
>         };
>         substr( $buffer, 0, $wrote, "" );
>         $writing->remove($socket) if !length $buffer;
>     }
> }

I had to change some things in your code to get it run (under Windows
2000) BUT without "use strict" because I get
the in the Typeglob assignment line the error msg "Variable "$buffer"
is not imported at chat3.pl line 56.".

The result is the same like I written in my first statement.

[snip]

> When I try 90 simultanious connections the connect sucedded for all.
> ALL can receive messages.
> BUT only the first ~60 Instances can send and the server receives the
> message. After closing
> any Instances the previously sended message will received by the
> server.

Here is the changed code:

<perl>

#!/usr/local/bin/perl -w
#use strict; # always use -w and strict
use IO::Socket;
# don't need to use IO::Socket::INET,
# since it IO::Socket makes it available.
use IO::Select;

# no need to make the log object-oriented.
#$SIG{INT} = sub { close CHATLOG; exit 0 };

my $listen = IO::Socket::INET->new(
    # no need for Proto=>'tcp', as that's the default.
    LocalPort => 2666, Listen => 256, Reuse => 1
) or die "Couldn't create listening socket: $!";

my ($reading, $writing) = (IO::Select->new($listen), IO::Select->new);

open( CHATLOG, ">>Chat.txt" )
    or die "Could not open Chat.txt for append: $!";
select( (select(CHATLOG), $|=1)[0] );

my %clients; # data on each client.

my @lines; # last 6 lines

sub debug {
    my ($client, $line) = @_;
    print $line . "\n";
    print CHATLOG "$client->{ip}\[$client->{fileno}]: $line\n"
}

while(1) {
    # yes, I know I discard the list of writables... see below.
    my ($toread) = IO::Select->select($reading, $writing);
    my $anoutput = 0;
    foreach my $socket ( @$toread ) {
        if( $socket == $listen ) {
            my $newsock = $listen->accept;
            $reading->add($newsock);
            $writing->add($newsock);
            $clients{$newsock} = {
                ip => join(".", unpack "C4", $newsock->peeraddr),
				input => "",
                output => "0" x 9 . "Willkommen\n" . join("", @lines),
                colors => "0" x 9,#substr( rand, -9 ),
                fileno => $socket->fileno,
            };
			next;
        }
        #my $client = $clients{$socket}; #client is empty !
        local *buffer = \$clients{$socket}{input}; # with "use strict"
I get the errormsg:
						   # Variable "$buffer" is not imported at chat3.pl line 56.
        $! = 0;
        unless( sysread $socket, $buffer, 4096, length $buffer ) {
			print $socket->fileno . "disconected";
            debug( $clients{$socket}, $! || "sent EOF" );
            $reading->remove($socket);
            $writing->remove($socket);
            delete $clients{$socket};
            close $socket; # Closing the socket before
"$reading->remove($socket);" causes the script
			   # not to clear the Hash correctly.
            next;
        }
        while((my $newline = index( $buffer, "\r\n" )) >= 0) {
           my $theline = substr( $buffer, 0, ++$newline, "" );
            $theline =~ tr/\012\015//d;
            debug( $clients{$socket}, $theline );
            $theline = $clients{$socket}{colors} . $theline . "\n";
            push @lines, $theline; shift @lines if @lines > 6;
            $_->{output} .= $theline for values %clients;
            $anoutput = 1;
        }
    }
    $writing->add(grep $_ != $listen, $reading->handles) if $anoutput;
    foreach my $socket ( $writing->can_write(0) ) {
        #my $client = $clients{$socket}; #client is empty !
        local *buffer = \$clients{$socket}{output}; # with "use
strict" I get the errormsg:
					            # Variable "$buffer" is not imported at chat3.pl line
56.
         my $wrote = syswrite( $socket, $buffer ) or do {
            debug($clients{$socket}, "failed to write: $!");
            $reading->remove($socket);
            $writing->remove($socket);
            delete $clients{$socket};
            close $socket;
            next;
        };
        substr( $buffer, 0, $wrote, "" );
        $writing->remove($socket) if !length $buffer;
    }
}

</perl>

Now i have no idea anymore to solve this behavior.

Regards,

Tristan


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

Date: Tue, 02 Oct 2001 02:36:29 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: Module File::Find and 'prune' variable
Message-Id: <3BB926E3.CF0FD15C@acm.org>

Bruno Costacurta wrote:
> I have a question related to File::Find::prune variable which is used as
> a boolean to descend or not descend into the directory specified in find
> function. Correct ?

No, you set prune *inside* the wanted function when you decide not to
explore the subtree you've just been given.

For example, you might say

   sub wanted {
      if (-d _) {
          $File::Find::prune=1;
      } else {
          # do something with the file
      }
   }

-- Dave Tweed


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

Date: 1 Oct 2001 18:17:21 -0700
From: lsulky@home.com (Old Lars)
Subject: newbie question on objects and dereferencing
Message-Id: <4662e966.0110011717.4935cefb@posting.google.com>

I'm new to perl and even newer to OO programming (despite my age!). I
find myself wanting to "see" for myself values of objects, and am
often confused by levels of object indirection. I really don't
understand what I'm doing but I feel that I would if I could get a
concrete handle on it...which I can't because I don't really
understand it.....

Here is a sample snippet I pulled from a nice tutorial page:

my $Top_Ten_Times = $DOM_document->DocumentElement();  # assign the
root node
my $Events = $Top_Ten_Times->childNodes();             # assign child
nodes

Why do we not do this:

	$Events = $DOM_document->childNodes() ;

That is, why is the assignment indirect? 

Also, I've tried examining values of these objects like this:

	print("\nEvents=" . "$Events") ;

and of course I get HASH values like these:

	Events=Win32::OLE=HASH(0x1838344)

 ...but I'm getting fuddled trying to dereference properly to see what
I think of as "real" values. I can't show the values as arrays or
hashes no matter what gonzo sequence of $@% I try. Can anyone take
pity and help me :-) ?


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

Date: Tue, 2 Oct 2001 13:14:22 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Sorting multidimensional arrays and MIN/MAX
Message-Id: <slrn9ric8e.t75.mgjv@martien.heliotrope.home>

On Tue, 2 Oct 2001 01:31:42 +0100,
	S Warhurst <bigusAT@btinternetDOT.com> wrote:
> "Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
> news:slrn9rfcv7.t75.mgjv@martien.heliotrope.home...
>> [Please in the future, put your reply _after_ the suitably trimmed text
>> you reply to. It is the commonly accepted quoting style on this
>> newsgroup, and Usenet in general]
> 
> When it is necessary to reply to particular passages of the original
> message, like now, then yes I agree, but since my reply didn't require such
> quotes and could be read "standalone" then I put it at the top where it's
> quickest & easiest to read. I maybe a relative novice to Perl but I have
> used Usenet for years and both methods are commonly accepted depending the
> context of the reply.

I'm not going to get into that war again. Yes, I am.

You'll find that on this group (and, amazingly, all groups I subscribe
to) the quoting style I mentioned is the norm, and top-posting or
jeopardy quoting are severly frowned upon.

>> Sort always uses curlies there:
>> @array = sort { $a <=> $b } @other_array;
>> Can you give an example with round brackets that compiles?
> 
> Yeah, the following syntax I have used before:
> 
> @names = ('Peter', 'Alan', 'John');
> @sorted = sort(@names);

Aha, now I see what you mean.  Yes, those parentheses are optional.  I
have almost never seen sort used with parentheses, which is why I didn't
get what you meant. I thought you meant parentheses to surround the
block, as in:

sort ( $a <=> $b ) @numbers;

which would be a syntax error.

In the case of sort the parentheses are hardly ever used, especially
when a block or subroutine name is specified as a sort routine. The
parentheses are just used for grouping when precedence could become a
problem, for example.

sort (and map, grep and print) are slightly different from other functions,
because they optionally can take something after the keyword that isn't
part of a normal argument list. From perlfunc:

       sort SUBNAME LIST
       sort BLOCK LIST
       sort LIST

       map BLOCK LIST
       map EXPR,LIST

       grep BLOCK LIST
       grep EXPR,LIST

       print FILEHANDLE LIST
       print LIST

See the lack of a comma after the first 'argument' in some of these
cases? Those syntactical oddities encourage a use without parentheses,
at least they do in my case.

> I guess the round brackets aren't needed at all in that and you could just
> say:
> @sorted = sort @names;  # having been a previous been a dabbler with VB, I
> guess I feel comfortable sticking round brackets round everything ;-)

That's fine. The parentheses won't hurt, really, as long as you put them
in the right place, and you don't get the idea that you need commas,
simply because you have parens. It's

@s = sort({$a cmp $b} @names);

or

@s = sort {$a cmp $b}(@names); #yuck

but _not_

@s = sort({$a cmp $b}, @names);

> So perhaps it's just Perl being flexible again, and it's only when you are
> specifying things to sort by that you need to use the curlies?

*nod*

><snip>
>> I hope the above has made it a little easier. It is, however, not a
>> substitute for reading the documentation. You could also consider buying
>> a book[1].
> 
> Yes, amazingly, I think I understood all that :)

I'm glad I could have been of help :)

> Thanks for taking the time to explain things to me.. I will study the
> perldoc site in more detail :)

You don't need a site. All the doucmentation comes with Perl, and should
be installed wherever Perl is installed. perldoc is a command, that you
can use from a shell (or command, or cmd) prompt. If you are on MS win,
and you installed the ActiveState distribution, then you also have the
documentation installed as HTML, available from your start menu thingy.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Useful Statistic: 75% of the people
Commercial Dynamics Pty. Ltd.   | make up 3/4 of the population.
NSW, Australia                  | 


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

Date: 2 Oct 2001 02:23:04 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: Using TAB - Newbie Question
Message-Id: <slrn9ri936.6ni.damian@puma.qimr.edu.au>

On 1 Oct 2001 17:43:31 -0700, Daniel Riveong said:
>...
>I am creating a flat database with data from a submitted form. My
>Question is how does one use TAB is a delimiter?

A tab is represented by \t. 

>
>Here is a sample of the code:
>
>   foreach $to_print (@sortlist) {
>      if ($fields{'outputfile'} ne "")
>       { print OUT_FILE "$fields{$to_print}\|"; }
>      if ($fields{'submit_to'} ne "")
>       { $msgtext .= "$to_print = $fields{$to_print}\n"; }
>   }

Do you really want all records on the same line, with a trailing
delimiter? Remember that anything other than '', 0 and undefined will
evaluate as true. Also, you can test for the existence of hash keys
with exists(). See `perldoc -f exists` and `perldoc -f defined`.

You are specifically testing for the empty string in both
conditionals. You *probably* don't need to do that.

Since $fields{'submit_to'} and $fields{'outputfile'} are not going to
change, and you probably don't want to be testing them for every
element in @sortlist, the above could be rewritten to eliminate the
foreach loop:

[warning: untested]

    print OUT_FILE join("\t", @fields{@sortlist})
        if $fields{'outputfile'};
    $msgtext = join('', map("$_ = $fields{$_}\n", @sortlist))
        if $fields{'submit_to'};

You might want to have a look at the perldata man page to find out
about hash slices. See also, `perldoc -f map` and `perldoc -f join`.

HTH

Cheers,
Damian
-- 
@:=grep!(m!$/|#!..$|),split//,<DATA>;@;=0..$#:;while($:=@;){$;=rand
$:--,@;[$;,$:]=@;[$:,$;]while$:;push@|,shift@;if$;[0]==@|;select$,,
$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/}  __END__
Just another Perl Hacker,### http://home.pacific.net.au/~djames.hub


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

Date: Tue, 02 Oct 2001 01:19:09 GMT
From: pkent <adverts@teaselsyn.co.uk>
Subject: XS Question
Message-Id: <adverts-94B86C.02182202102001@news.cableinet.co.uk>

hi all,

I've just started dabbling with XS, and have successfully built some 
_very_ basic libraries with which to decorate my auto/ tree. So far so 
good.

I have a real application that I would like to see whether I can turn 
into an XS module (it does some rather tortuous date&time calculations). 
It's a command line app at the moment and it's laid out like:

File1.c
main - parses the input args, when happy it calls this multiple times...
dateconvert - takes in munged arguments, printf's the answer after 
calling...
a_huge_batch_of_interesting_functions - about 10 functions that take in 
some numbers, crunch, return different numbers

Now what I wanted to do was put the huge_batch_of_interesting_functions 
in a separate file from the XS file. The XS file would contain the 
smallish dateconvert function, and that would be rewritten for this XS 
specific implementation.
However, I don't want to touch the huge_batch_of_interesting_functions 
because they really are quite intricate, and I'd rather just leave them 
unouched. All they do is take in some ints and floats and return ints or 
floats.

So, hopefully that makes sense as to _why_ I want to do this. The basic 
question is really: can I somehow have an extra .c source file in 
addition to my .xs file?

I've tried a few things like #include foo.c, or specifying the 
additional file at the compilation stage after the XS preprocessor has 
run, but no luck.

regards
P

-- 
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply


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

Date: 02 Oct 2001 01:35:30 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: XS Question
Message-Id: <m3d746mwnx.fsf@mumonkan.sunstarsys.com>

pkent <adverts@teaselsyn.co.uk> writes:

> So, hopefully that makes sense as to _why_ I want to do this. The basic 
> question is really: can I somehow have an extra .c source file in 
> addition to my .xs file?
> 
> I've tried a few things like #include foo.c, or specifying the 
                               ^^^^^^^^^^^^^^

I think you should be including a header file, like foo.h, and not 
foo.c.  Otherwise when perl is make-ing your package's shared library, 
it'll likely get confused by the multiple function definitions in both 
foo.o and the object file arising from your xs file.

> additional file at the compilation stage after the XS preprocessor has 
> run, but no luck.

It would help to have seen exactly what error you got. Be sure to
read the h2xs manpage as well as perlxstut and perlxs.  Also, I found 
Steven McDougall's perlmonth articles very helpful:

  http://www.perlmonth.com/columns/modules/modules.html?issue=8
  
That's the third one out of five.

-- 
Joe Schaefer                  "Whatever you are, be a good one."
                                               -- Abraham Lincoln



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

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.  

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


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