[10603] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4195 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 11 03:07:27 1998

Date: Wed, 11 Nov 98 00:00:37 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 11 Nov 1998     Volume: 8 Number: 4195

Today's topics:
        A Perl Style Question - initializing large numbers of v (Alex V. Kluge)
    Re: A Perl Style Question - initializing large numbers  <zenin@bawdycaste.org>
        Command line globbing and Windows 95 <chris@zucchini.linz.govt.nz>
    Re: concurrently writing to a file without doing flock ronald_f@my-dejanews.com
    Re: concurrently writing to a file without doing flock (Larry Rosler)
    Re: CPAN "r" command is confused? <zenin@bawdycaste.org>
        doing a 'use' within threads.  <mcariaso@genelogic.com>
        Error in script <DeleteThisdev@stabiplan.nl>
    Re: Error in script <dgris@rand.dimensional.com>
    Re: Error in script (Sam Holden)
        Free Web Dev. Resources heliumweb2@my-dejanews.com
    Re: Hash help <uri@sysarch.com>
    Re: Hash help <dgris@rand.dimensional.com>
    Re: Holding CGI file handle in object miko@idocs.com
    Re: How do I sort this list by "port" number? (Sean McAfee)
    Re: How do I sort this list by "port" number? (Larry Rosler)
    Re: Is there a compiler for Perl? <pascual@SPAMZONE.iname.com>
    Re: Net::FTP Help me please. helphand@pacbell.net
        New to perl - How do I run a script and view results of (Lorick)
        Parsing HTML Tables <cglcomputer@earthlink.net>
    Re: pwd without backticks? (Ilya Zakharevich)
        REQ: File locking assistance for Perl CGI .. (rga)
    Re: String Split Help (Tad McClellan)
    Re: sysread() Question (Ronald J Kimball)
    Re: sysread() Question <uri@sysarch.com>
    Re: Want to learm Perl (Bradley K. Farrell)
    Re: Yet another list of lists question <aqumsieh@matrox.com>
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: 11 Nov 1998 01:02:10 -0600
From: kluge@uts.cc.utexas.edu (Alex V. Kluge)
Subject: A Perl Style Question - initializing large numbers of variables
Message-Id: <72bcpi$ess@moe.cc.utexas.edu>


Hi,

   I have a style question - driven mostly by curiosity.  I have a large
  program with several sets of related variables.  For example, some
  describe where the data is located, some describe the range and format
  of the data, and others describe how the data is to be processed. I know
  several methods (as is usually the case with Perl) to set initial values
  for these variables as the program starts up, but is there a (or even
  one or two) methods that might be considered best style?

   For example, I could use a bunch of "my $variable = value" statements.
  I could put the initial variables in a separate file and use "do somefile"
  to execute them, or making them local variables and using function calls
  such as (*a, *b) = func(\@c, \@d); to initialize sets of variables.

                                     Thanks,
                                       Alex

  


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

Date: 11 Nov 1998 07:29:00 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: A Perl Style Question - initializing large numbers of variables
Message-Id: <910769400.553751@thrush.omix.com>

Alex V. Kluge <kluge@uts.cc.utexas.edu> wrote:
:    I have a style question - driven mostly by curiosity.  I have a large
:   program with several sets of related variables.  For example, some
:   describe where the data is located, some describe the range and format
:   of the data, and others describe how the data is to be processed. I know
:   several methods (as is usually the case with Perl) to set initial values
:   for these variables as the program starts up, but is there a (or even
:   one or two) methods that might be considered best style?
:
:    For example, I could use a bunch of "my $variable = value" statements.
:   I could put the initial variables in a separate file and use "do somefile"
:   to execute them, or making them local variables and using function calls
:   such as (*a, *b) = func(\@c, \@d); to initialize sets of variables.

	This sounds like mostly configuration type options.  I often build
	such config files as an anonymous hash that gets required:
	
	## my foo.conf file
	my $config = {
	    SomeOption => "some value",
	    SomeList   => [ "foo", "bar", "dog"],
	};
	## Do not put a "1" here, or any other code!

	Later in the program:

	my $Config = require "foo.conf";
	doSomethingWith ($Config->{SomeOption});

-- 
-Zenin (zenin@archive.rhps.org)           From The Blue Camel we learn:
BSD:  A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts.  Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.)  The full chemical name is "Berkeley Standard Distribution".


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

Date: 11 Nov 1998 04:45:58 GMT
From: "Chris Crook" <chris@zucchini.linz.govt.nz>
Subject: Command line globbing and Windows 95
Message-Id: <01be0d2e$582614e0$123361cb@chrishome.linz.gov.nz>

Hi

I have a problem with ActivePerl (versions 502, 504, 506, it doesn't matter
which) and file globbing under Windows 95.  Wild card filenames on the
command line aren't being expanded.  That is, if I enter something like

   perl -e "print join(' ',@ARGV);" *.*

Then all that gets printed is "*.*", not a list of file names.  I'm sure
that this used to work with at least one of these versions of perl.  This
occurs on several different PCs.  I believe that the program perlglob.exe
is used for file name expansion, and the program itself certainly works ok
(ie perlglob *.* prints a list of file names).  Also the glob command works
fine.  I have seen work arounds with running modules using the -M option to
expand @ARGV.  

Any suggestions as to what I can do to get the command line file names to
expand properly (other than  install Linux, of course)

Thanks in advance for any help

Chris Crook


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

Date: Wed, 11 Nov 1998 06:56:46 GMT
From: ronald_f@my-dejanews.com
Subject: Re: concurrently writing to a file without doing flock
Message-Id: <72bcfe$uu$1@nnrp1.dejanews.com>

In article <3648C98F.83D09948@fccj.org>,
  bill@astro.fccj.org wrote:
> ronald_f@my-dejanews.com wrote:
> >
> > What is the worst thing that can happen when several processes print to the
> > same file, without using flock, every print writes exactly one line, and the
> > file handles are set to unbuffered? In particular: Could it be that some
lines
> > arrive split into pieces or get lost?
> >
> > From the FAQ I conclude that, using autoflush, the buffer is flushed at the
> > end of each print statement, so I think that no lines should be lost, and
> > every line is written to the file in one piece. Can someone confirm this?

> You can confirm it yourself.

Actually I tried it, and *never* got inconsistent results. This may be due to
sheer luck, of course, and that's why I posted this question.

I know that in general one should never concurrently write to a file without
locking, lest desaster will occur. But IMO, my case is particular to Perl:

Perl guarantees that - for unbuffered file handles - the buffer gets flushed
automatically at the end of its print statement, so when two Perl processes do
this concurrently, process A tells the operating system to write line A, and
process B tells the operating system to write line B. One of these processes
must be the first, and since output is unbuffered, the operating system takes
either one of these lines and writes it to the file as a piece, so I
contemplated that, while the relative sequence of the lines is not
deterministic, no line should be lost (as Tom Phoenix suspected), and no two
lines should be garbled together. Please correct at which point my conclusions
go wrong.

Ronald
--
Ronald Fischer <ronald_f@my-dejanews.com>
http://ourworld.compuserve.com/homepages/ronald_fischer/

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Tue, 10 Nov 1998 23:35:07 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: concurrently writing to a file without doing flock
Message-Id: <MPG.10b2de0481056638989905@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and copy mailed.]

In article <72bcfe$uu$1@nnrp1.dejanews.com> on Wed, 11 Nov 1998 06:56:46 
GMT, ronald_f@my-dejanews.com <ronald_f@my-dejanews.com> says...
 ... 
> Perl guarantees that - for unbuffered file handles - the buffer gets flushed
> automatically at the end of its print statement, so when two Perl processes do
> this concurrently, process A tells the operating system to write line A, and
> process B tells the operating system to write line B. One of these processes
> must be the first, and since output is unbuffered, the operating system takes
> either one of these lines and writes it to the file as a piece, so I
> contemplated that, while the relative sequence of the lines is not
> deterministic, no line should be lost (as Tom Phoenix suspected), and no two
> lines should be garbled together. Please correct at which point my conclusions
> go wrong.

Your conclusions would be correct if each process has opened the file 
for *appending*.  The operating system should ensure that any writes to 
the file are forced to the end, so they might appear 
nondeterministically, but would not overwrite each other.

But when the files are opened simply for *writing*, each process will 
have its own idea of where the file pointer is, and disaster will ensue.

See the following article in DejaNews (April 16, 1998, "Re: File IO 
Question: opening for appending without flock?"):

<URL:http://x1.dejanews.com/getdoc.xp?AN=344789136>

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 11 Nov 1998 07:39:06 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: CPAN "r" command is confused?
Message-Id: <910770006.301186@thrush.omix.com>

John G Dobnick <jgd@alpha3.csd.uwm.edu> wrote:
	>snip<
: I installed the TK::Pod module, and when I then issue a CPAN "r"
: command (to obtain its idea of "reinstallation recommendations")
: it tells me the following:
:
: Package namespace         installed    latest  in CPAN file
: Tk::Pod                        3.14      3.14  ACH/Tk-Pod-0.10.tar.gz
: 129 installed modules have no parseable version number
:
: But....   I just _installed_ version 3.14.  So, what's going on here?

	Did you run 'r' in the same session that you upgraded the module?
	CPAN seems to cache information, and often gets confused if you
	do something like this in the same session.  Try exiting and
	starting the CPAN shell again and see if this persists.

:   o  Is this a Perl problem?

	Nope.

:   o  Is this a CPAN problem?

	Probably.

:   o  Is this a module problem?

	Maybe.  I just tried to recreate your conditions, but it installed
	3.15.  Maybe 3.14 had some funky way of building a $VERSION?

:   o  Where is the best place to ask about this?

	p5p, the perltk mailing lists, and/or the perltk newsgroup.

-- 
-Zenin (zenin@archive.rhps.org)           From The Blue Camel we learn:
BSD:  A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts.  Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.)  The full chemical name is "Berkeley Standard Distribution".


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

Date: Wed, 11 Nov 1998 05:51:29 GMT
From: Mike Cariaso <mcariaso@genelogic.com>
Subject: doing a 'use' within threads. 
Message-Id: <364925DB.999C7AF4@genelogic.com>

Does the following seem kosher?

It should load each file, point a coderef at the new subroutine in each file,
and then use that coderef to run a thread.

If I uncomment the sleep it runs fine. If I comment it out, it is EXTREMELY
crash prone, especially on the bigger files. This would seem to suggest
(something like) the perl interpreter is trying to load these modules into the
same locations in memory, and is crashing because of it. Is this plausible? What
is actually happening?

If this is the case, rather than sleeping, is there some better way I can know
when a file is done being loaded?


use Thread;

@files = ('file1', 'file2', 'file3');
foreach $file (@files) {
   use $file;
   $ref = *$module::new{CODE}; #make a codref to the new subroutine in the file
   $t = new Thread $ref;       #run a thread from this coderef
#  sleep 5;
}



The code above paraphrases my actual code. Which is done in an eval, etc. I may
have made a syntax error in the translation, but I think the gist of it is
fairly clear.
-- 
       "Its easy to have dead heroes"
Mike Cariaso                     (301) 987-1834
Software Engineer        mcariaso@genelogic.com         
Gene Logic, Inc.       http://www.genelogic.com


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

Date: Wed, 11 Nov 1998 08:18:40 +0100
From: "Martijn van der Kooij" <DeleteThisdev@stabiplan.nl>
Subject: Error in script
Message-Id: <72bdta$31r$1@news.Kijfhoek.NL.net>

The following doesn't work properly. What I want is to scan all lines, do
several regular expressions on it and when 1 of those met add 2 tabs in
front of the line, after cutting away spaces in front of that line.

But the while loop is never entered. Do someone knowns what i'm doing wrong?

M.C. van der Kooij

use strict;
my $regel;
my @SearchLines;
my @TempSearchLines;
my $searchLine;
my $LineNotPrinted;

@SearchLines = ('^Galaxy Game', '^ *Status of Players', '^A');

open (TURN, "r024.txt");
open (NEWTURN, ">r024_new.txt");

while ($regel = <TURN>) {
 $LineNotPrinted = 1;
 @TempSearchLines = @SearchLines;
 while (($#TempSearchLines => 0) && ($LineNotPrinted eq 1)) {
  $searchLine = shift @TempSearchLines;
  print NEWTURN "$searchLine";
  if ($regel =~ /$searchLine/i) {
   $regel =~ s/^\s+//;
   print NEWTURN "\t\t$regel";
   $LineNotPrinted = 0;
  };
 };
 if ($LineNotPrinted == 1) {
  print NEWTURN $regel;
 };
};

close TURN;
close NEWTURN;




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

Date: 11 Nov 1998 01:32:09 -700
From: Daniel Grisinger <dgris@rand.dimensional.com>
Subject: Re: Error in script
Message-Id: <m3vhkmeik6.fsf@rand.dimensional.com>

"Martijn van der Kooij" <DeleteThisdev@stabiplan.nl> writes:

<snip>

> open (TURN, "r024.txt");
> open (NEWTURN, ">r024_new.txt");

Your open()s are probably failing for some reason.  Add

    || die "Coudln't open: $!"

to each of those lines.

dgris
-- 
Daniel Grisinger              dgris@rand.dimensional.com
Supporter of grumpiness where grumpiness is due on clpm.
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print 
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'


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

Date: 11 Nov 1998 07:49:22 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Error in script
Message-Id: <slrn74igc2.eco.sholden@pgrad.cs.usyd.edu.au>

On Wed, 11 Nov 1998 08:18:40 +0100, Martijn van der Kooij
	<DeleteThisdev@stabiplan.nl> wrote:
>The following doesn't work properly. What I want is to scan all lines, do
>several regular expressions on it and when 1 of those met add 2 tabs in
>front of the line, after cutting away spaces in front of that line.
>
>But the while loop is never entered. Do someone knowns what i'm doing wrong?

Which while loop?

>
>M.C. van der Kooij
>
>use strict;
>my $regel;
>my @SearchLines;
>my @TempSearchLines;
>my $searchLine;
>my $LineNotPrinted;
>
>@SearchLines = ('^Galaxy Game', '^ *Status of Players', '^A');
>
>open (TURN, "r024.txt");
>open (NEWTURN, ">r024_new.txt");
You should always check the return value of open...
open(TURN,"r024.txt") || die "Unable to open r024.txt : $!";
and again for NEWTURN.
This is probably the problem (although I must admit I never ran your code
to check the rest).

>while ($regel = <TURN>) {
while(defined($regel = <TURN>)) {
if you want to be more overtly paranoid.

> $LineNotPrinted = 1;
> @TempSearchLines = @SearchLines;
> while (($#TempSearchLines => 0) && ($LineNotPrinted eq 1)) {
                                                      ^^
== would probably be better...

Even better yet, would be to use last to get out fo the loop instead of
doing an extra test everytime through...

>  $searchLine = shift @TempSearchLines;
>  print NEWTURN "$searchLine";
Those quotes do nothing but confuse matters...
And printing that seems a strange thing to do...

>  if ($regel =~ /$searchLine/i) {
>   $regel =~ s/^\s+//;
use $regel =~ s/^\s*/\t\t/;
and you can lose that $LineNotPrinted variable and the next line, and
the test at the bottom. In other words modify $regel here if you need to
and print it at the end always.


>   print NEWTURN "\t\t$regel";
>   $LineNotPrinted = 0;
>  };
> };
> if ($LineNotPrinted == 1) {
>  print NEWTURN $regel;
> };
>};

You don't need all those semi-colons after the }s.
>
>close TURN;
>close NEWTURN;

I would probably use something like this :
(in fact I would read from <> write to STDOUT, and probably eval a
string containing the while loop with the regexes now embedded inside but
that is another story)

#!/usr/local/bin/perl -w
use strict;
my $regel;
my @SearchLines = ('^Galaxy Game', '^ *Status of Players', '^A');

open(TURN,"r024.txt") || die "Unable to open r024.txt : $!";
open (NEWTURN, ">r024_new.txt") || die "Unable to open r024_new.txt : $!";

while(defined($regel = <TURN>)) {
        for (@SearchLines) {
                print NEWTURN $_; # this makes the output file really messy
                if ($regel=~/$_/i)
                {
                        $regel =~ s/^\s*/\t\t/;
                        last;
                }
        }
        print NEWTURN $regel;
}

close(TURN);
close(NEWTURN);
 

in fact I did run that and with my input test it worked as I expected...
not very useful with all those regexes on each line though.

-- 
Sam

You can blame it all on the internet. I do...
	--Larry Wall


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

Date: Wed, 11 Nov 1998 04:46:39 GMT
From: heliumweb2@my-dejanews.com
Subject: Free Web Dev. Resources
Message-Id: <72b4rf$r37$1@nnrp1.dejanews.com>

Hi
    WebKnowHow.Net is a web development directory with over 900 resources,
inclusing tutorials, FAQ's, books, and scripts for subjects such as CGI, Perl,
Java, HTML, Web Design, Graphics, Web Promotion and more. There is also a free
search engine submission section.

http://webknowhow.net


-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 10 Nov 1998 23:43:19 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Hash help
Message-Id: <x7btmec00o.fsf@sysarch.com>

>>>>> "JH" == Jeff Hunter <jhunter@igg-tx.net> writes:

  JH> I was hoping to match the value of the mapped variable, ie:
  JH> printf COM3 "%-25s", map $_->{hostname}, $hosts{$long_name};
  JH> if($_ =~ /mvr/){
  JH> 	#do something with it.
  JH> }
  JH> 				Jeff

now that i am looking at your code better, you don't need map there. map
is used to perform some set of operations on a list of scalars. you have
only 1 there $hosts{$long_name}. you could just do that with

	$hosts{$long_name}{hostname} ;

another trick (which i don't use much) is the foreach loop on a scalar
this will set $_ to the scalar in the list so it can be used in the code
block.

foreach ( $hosts{$long_name} ) {

	printf COM3 "%-25s", map $_->{hostname} ;

# no need for $_ for regex, as it defaults to using that

	if( /mvr/ ) {
		#do something with it.
	}
}

map should only be used when you use the result list. using it in a void
context (which you are not) is considered a mortal sin and you will be
excommunicated from the perl community. :-)

hth,

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire  ----------------------  Perl, Internet, UNIX Consulting
uri@sysarch.com  ------------------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: 10 Nov 1998 23:31:07 -700
From: Daniel Grisinger <dgris@rand.dimensional.com>
Subject: Re: Hash help
Message-Id: <m31znag2qc.fsf@rand.dimensional.com>

Uri Guttman <uri@sysarch.com> writes:

> another trick (which i don't use much) is the foreach loop on a scalar
> this will set $_ to the scalar in the list so it can be used in the code
> block.

I use this all the time.  I think that it is particularly 
good style that leads to clean, easily readable code.  

Consider-

    ${ $line{'foo'} } [0] =  '      this is some data     ';
    ${ $line{'foo'} } [0] =~ s/^\s*//;
    ${ $line{'foo'} } [0] =~ s/\s*$//;

    $status1 = do_something      ( ${ $line{'foo'} } [0] );
    $status2 = do_something_else ( ${ $line{'foo'} } [0] );

compared against-

    ${ $line{'foo'} } [0] =  '      this is some data     ';

    for ( ${ $line{'foo'} } [0] ) {
        s/^\s*//;
        s/\s*$//;
 
        $status1 = do_something      ($_);
        $status1 = do_something_else ($_);
    }

The second is much clearer and much easier to read, IMO.

dgris 
-- 
Daniel Grisinger              dgris@rand.dimensional.com
Supporter of grumpiness where grumpiness is due on clpm.
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print 
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'


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

Date: Wed, 11 Nov 1998 04:37:48 GMT
From: miko@idocs.com
Subject: Re: Holding CGI file handle in object
Message-Id: <72b4as$qk6$1@nnrp1.dejanews.com>

In article <72a1e5$sps$1@nnrp1.dejanews.com>,
  miko@idocs.com (that's me) wrote:
>
> I'm having a problem storing the file handle from a CGI
> in an object. The following code is a boiled down version
> which highlights the specific problem:

I finally found the answer to this, so I'll put it on record here for the next
poor soul.

Basically, I solved the problem by upgrading to the latest version of CGI.pm
-- 2.43 as of now.  It appears CGI.pm didn't like having it's object tossed
around, but the latest version is OK with it.  Much thanks to Jacqui Caren
for pointing this out.

-miko

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Wed, 11 Nov 1998 04:10:22 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: How do I sort this list by "port" number?
Message-Id: <O6822.6038$fS.19967516@news.itd.umich.edu>

In article <72avp0$n0j$1@nnrp1.dejanews.com>,  <munn@bigfoot.com> wrote:
>I have an array with the following elements:
>(for this context, assume that each entry is in the order presented assigned
>sequentially to the array, so $a[0] is the first line and so on)

>25 Simple Mail Transfer tcp 101.1.48.26 101.1.49.36 Nov 6 00:04:33
>25 Simple Mail Transfer tcp 198.108.149.2 200.36.131.36 Nov 6 00:04:33
>25 Simple Mail Transfer tcp 198.108.149.2 198.81.17.2 Nov 6 00:04:33
>43424 not assigned tcp 198.108.149.2 207.82.90.10 Nov 6 00:04:33
>43235 not assigned tcp 198.108.149.2 203.18.38.243 Nov 6 00:04:33
>123 Network Time Protocol udp 101.1.48.26 101.1.48.67 Nov 6 00:04:33
[etc, snip]

>I am wanting to sort ONLY by the first numbers in the "line", in this case,
>the number is the "port", and I want to sort based on this.  any way to do it?
>I can't figure it out, sort doesn't work very well at all...

No, actually it works very well.

@sorted_a = sort { $a <=> $b } @a;

This is the same way one sorts lists of numbers, and it works here becasue
when each line is treated as a number, it turns into your port number.

If, on the other hand, each line started with, say, a ":", you might have
to do something a little more complicated:

@sorted_a = sort { ($a=~/(\d+)/)[0] <=> ($b=~/(\d+)/)[0] } @a;

or (probably better)

@sorted_a = sort { substr($a,1) <=> substr($b,1) } @a;

-- 
Sean McAfee | GS d->-- s+++: a26 C++ US+++$ P+++ L++ E- W+ N++ |
            | K w--- O? M V-- PS+ PE Y+ PGP?>++ t+() 5++ X+ R+ | mcafee@
            | tv+ b++ DI++ D+ G e++>++++ h- r y+>++**          | umich.edu


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

Date: Tue, 10 Nov 1998 22:35:39 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: How do I sort this list by "port" number?
Message-Id: <MPG.10b2d014c94a41e6989904@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and copy mailed.]

In article <O6822.6038$fS.19967516@news.itd.umich.edu> on Wed, 11 Nov 
1998 04:10:22 GMT, Sean McAfee <mcafee@waits.facilities.med.umich.edu> 
says...
> In article <72avp0$n0j$1@nnrp1.dejanews.com>,  <munn@bigfoot.com> wrote:
 ...
> >25 Simple Mail Transfer tcp 101.1.48.26 101.1.49.36 Nov 6 00:04:33
> >25 Simple Mail Transfer tcp 198.108.149.2 200.36.131.36 Nov 6 00:04:33
> >25 Simple Mail Transfer tcp 198.108.149.2 198.81.17.2 Nov 6 00:04:33
> >43424 not assigned tcp 198.108.149.2 207.82.90.10 Nov 6 00:04:33
> >43235 not assigned tcp 198.108.149.2 203.18.38.243 Nov 6 00:04:33
> >123 Network Time Protocol udp 101.1.48.26 101.1.48.67 Nov 6 00:04:33
> [etc, snip]
> 
> >I am wanting to sort ONLY by the first numbers in the "line", in this case,
> >the number is the "port", and I want to sort based on this.  any way to do it?
> >I can't figure it out, sort doesn't work very well at all...
> 
> No, actually it works very well.

I think it works very poorly, because it is not '-w' clean, and all 
programs should run with '-w' enabled at all times!
 
> @sorted_a = sort { $a <=> $b } @a;
> 
> This is the same way one sorts lists of numbers, and it works here becasue
> when each line is treated as a number, it turns into your port number.

But these are not lists of numbers.  They are strings that begin with 
numbers.

> If, on the other hand, each line started with, say, a ":", you might have
> to do something a little more complicated:
> 
> @sorted_a = sort { ($a=~/(\d+)/)[0] <=> ($b=~/(\d+)/)[0] } @a;

That is ungainly and slow, but at least it is '-w' clean.

> or (probably better)
> 
> @sorted_a = sort { substr($a,1) <=> substr($b,1) } @a;

No, worse, because of the '-w' problem again.

Let's roll out the Schwartz Transform:

  @sorted_a = map $_->[0],
              sort { $a->[1] <=> $b->[1] }
              map { [ $_, /(\d+)/ ] } @a;

And let's aim the questioner at perlfaq4:  "How do I sort an array by 
(anything)?"

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 11 Nov 1998 00:08:14 -0500
From: Pasc <pascual@SPAMZONE.iname.com>
Subject: Re: Is there a compiler for Perl?
Message-Id: <910761270.1541879703@nntp.isc.rit.edu>

Peter,

Yes.  In the Perl 5.005 announcement, listed with other new things that are
considered experimental:
 	"A suite of compiler modules with various backends, for producing C or
bytecode from Perl, and for various useful diagnostics." 
-> http://language.perl.com/doc/manual/html/READMEs/Announce.html

See also the FAQ:
-> http://www.perl.com/CPAN-local/doc/FAQs/FAQ/PerlFAQ.html#How_can_I_compile_my_Perl_progra

There isn't much use for it though.  From what I hear, the performance
difference isn't all that much.  I'd rather keep my Perl the way it was
supposed to be.  ;-)

--
Pasc

--
On Tue, 10 Nov 1998, Peter wrote:
>Is there a compiler for Perl?
>
>If not, does anyone know a similar language where I can convert Perl
>to a compiled self contained .exe?
>
>Peter


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

Date: Wed, 11 Nov 1998 05:20:03 GMT
From: helphand@pacbell.net
Subject: Re: Net::FTP Help me please.
Message-Id: <36491d06.815419842@news.pacbell.net>

On Wed, 11 Nov 1998 03:18:57 GMT, "sethnjen" <sethnjen@megahertz.net>
wrote:

>I am a perl beginner and I am trying to use get and/or getstore to get a
>file through ftp:
>
>getstore('ftp://some.site/some.file', 'some.file');
>
>If i use http this works, yet using ftp gives many headaches.  The first
>thing I figured out is that I don't have Net::FTP but I got it.  

   Good. Net::FTP will do exactly what you want.

>Then the
>files for Net::FTP contained compiler errors!  I fixed, I believe, all of
>them but I still cant retrieve files over ftp...if i try to get the

  This doesn't sound right. Are you sure you got Net:FTP from CPAN?

>directory listing (ftp://some.site) it gives me a html back that would
>represent that but if i want a file (ftp://some.site/some.file) it returns
>ftp error 500.
>

  A sample of your code would be helpful. Just saying that it returned
error 500 doesn't help much.

>I also tried a little with using the ua object oriented approach but it
>resulted in the same errors.  I was not sure what to use as an object so I
>used the HTTP::Request, the same as if i wanted an html page.
>

  HTTP::Request is not a method that's part of Net::FTP.

>All I want to be able to do is retrieve a plain text file through a ftp
>command.

  The Net::FTP module contains some execellent examples of how to 
accomplish just that. Did you try any of the examples?

>
>Please email me if you can provide help, thanks a lot.
>

  Sorry, post here, read here.

  HTH,

   Scott


--------
Delta Performance Group, "Achieving the Competitive Edge"
http://www.deltagrp.com/


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

Date: 11 Nov 1998 07:12:26 GMT
From: ce492@torfree.net (Lorick)
Subject: New to perl - How do I run a script and view results offline?
Message-Id: <72bdcq$lt6$1@news.bconnex.net>

I just started using Perl yesterday and don't know anything otherwise about CGI
type things, but I've found a need to write some things in Perl to put on a
web page like a guest book or something else that reads/writes data, and I have
found lots of sample code to do this, but my question Is:

I am running win 95/dos on my desktop machine and I am wondering how I can 
run a PERL script at home locally to see how it works before uploading it to 
my provider, because they don't have open CGI access.  I'd have to re-submit 
the script for security checking by system admin before it would be able to 
run...so how can I run it at home to see how it runs?
I installed a dos port that I obtained from www.perl.com and I can run a script 
into it on the commandline and it executes as if there has been no data entered 
on the web page (obviously) and it spits out the error message, but can I 
simulate an online connection with the html files calling the perl script 
somehow to check operation and read/write file access?



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

Date: Tue, 10 Nov 1998 22:56:19 -0500
From: Chris Lambrou <cglcomputer@earthlink.net>
Subject: Parsing HTML Tables
Message-Id: <36490AE3.8160AC36@earthlink.net>

What is the most *efficient* way to parse values in table cells in
HTML?  

I have a script that uses the LWP::UserAgent and HTTP::Request modules
to retrieve an HTML page on a remote site.  On this page, data 
is displayed in an HTML table like this:

<table>
<tr><td> cell data </td><td> cell data </td></tr>
<tr><td> cell data </td><td> cell data </td></tr>
<tr><td> cell data </td><td> cell data </td></tr>
<tr><td> cell data </td><td> cell data </td></tr>
</table>

Note that that the table is not as neatly formatted as above.
There could be a carriege return anywhere in the middle of a cell
or a row.  From the above, I need to create a structure like this:

$table[$row][$column] = $value;

I did come up with a way that works, but it's kinda ugly.



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

Date: 11 Nov 1998 06:24:52 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: pwd without backticks?
Message-Id: <72bajk$29g$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Uri Guttman 
<uri@fastengines.com>],
who wrote in article <sar7lx39lqj.fsf@camel.fastserv.com>:
>   IZ> Right.  This is why 'pwd' must be suid.
> 
> wrong. if you got into below strange dir which has only execute perms,
> you should know where you are. as i said on solaris, pwd is not suid.

This is a bug of Solaris's pwd.

>   >> in most cases so you save the fork. if a system does restrict pwd to
>   >> root (why?)
> 
>   IZ> Since some directories up above can be unreadable (as you wrote in
>   IZ> your message yourself).
> 
> that is the program's fault. how did you get there to begin with unless
> some parent with permission cd'd there and forked you off. or someone
> changed perms on a parent dir after you got there. if you need a pwd
> with suid, you can hack one yourself (in perl!). so the Cwd:: stuff is
> fine as it is. if you need more, then you have to fork and you should
> know how to do that on your own. the module is for basic use and should
> work fine in most real world situations.

Eh?

	mkdir foo/bar
	chmod a-r foo
	cd foo/bar
	pwd
	  pwd: cannot get current directory: Permission denied
	  Exit 1

Ilya


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

Date: Wed, 11 Nov 1998 03:55:43 GMT
From: rga@io.com (rga)
Subject: REQ: File locking assistance for Perl CGI ..
Message-Id: <36490902.6687885@news.io.com>


I need to install file locking in a perl CGI script ..
I would like a generic, simple way to put it in ..
And have it work w/ Linux, Unix, and even NT ( if possible )

The script is used by some NT servers ..
But, more important that I have the locking for Unix, Linux

Would someone be willing to just write in the code ..
As it would effect the simple file opening code below ..

And please email response :-)
Thanks MUCHO in advance.


# Open the File with locking
open (NUMBER, "$number_path")) || die
$num = <NUMBER>;
close (NUMBER);
$num++;




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

Date: Tue, 10 Nov 1998 23:26:52 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: String Split Help
Message-Id: <s67b27.9mf.ln@flash.net>

bigcheese@my-dejanews.com wrote:

: @kana = split(/([aeiou ])/,"$ENV{'QUERY_STRING'}'}");
                                                  ^^
                                                  ^^ why add these 2 chars?

   Actually, why put it in double quotes at all?


: and it splits the a,e,i,o,u's and spaces on both sides
: (ie: cow (w/space) splits to "c" "o" "w" and " ")


   It splits into *five* elements.

   The four you have, and q/'}/.


   You should not try and type in code. You should use cut/paste.

   Else you'll get a bunch of followups about your typos
   instead of about your real question...


: Is it possible to make it split "cow "(w/ space) to "co" and "w "?


   @kana = $ENV{'QUERY_STRING'} =~ /([^aeiou ]*[aeiou ])/g;


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Tue, 10 Nov 1998 23:08:50 -0500
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: sysread() Question
Message-Id: <1diavoa.6nberb1v58bswN@bay1-310.quincy.ziplink.net>

Uri Guttman <uri@sysarch.com> wrote:

>     regex => sub { $buf =~ /^\0*(?!\n)$/ },
>     regex2 => sub { $buf =~ /[^\0]/ },

This should be

      regex2 => sub { $buf !~ /[^\0]/ },


-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: 10 Nov 1998 23:35:04 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: sysread() Question
Message-Id: <x7emrac0ef.fsf@sysarch.com>

>>>>> "RJK" == Ronald J Kimball <rjk@coos.dartmouth.edu> writes:

  RJK> Uri Guttman <uri@sysarch.com> wrote:
  >> regex => sub { $buf =~ /^\0*(?!\n)$/ },
  >> regex2 => sub { $buf =~ /[^\0]/ },

  RJK> This should be

  RJK>       regex2 => sub { $buf !~ /[^\0]/ },

the basic test of all zeroes does work there though but i didn't care to
do that for the benchmark. i was assuming the neagtion would occur
outside. i don't like !~ anyway. i would negate it with unless or some
other logic.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire  ----------------------  Perl, Internet, UNIX Consulting
uri@sysarch.com  ------------------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Wed, 11 Nov 1998 03:57:26 GMT
From: bradley@iinet.net.au (Bradley K. Farrell)
Subject: Re: Want to learm Perl
Message-Id: <364b09f6.66487370@news.m.iinet.net.au>

>I am very interested in learning the perl language
Great.

>and am looking for an online tutorial..
You have tried the major search engines, haven't you?

>If you know of anything like this please let me know
See above. You can also try:
http://www.digitaled.com/preview/oreilly/

BTW, this link was on the frontpage at perl.oreilly.com
--
Bradley K. Farrell
bradley@iinet.net.au


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

Date: 10 Nov 1998 16:54:06 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Yet another list of lists question
Message-Id: <x3y7lx3gqo1.fsf@tigre.matrox.com>


Gordon Haverland <haverlan@agric.gov.ab.ca> writes:

> 
> Hi.
>   I'm playing with some splines (piecewise polynomials).
> Within each segment, we have some number of coefficients
> representing the polynomial.  So $coeff[0] is the
> array of coefficents on the first segment of the spline.

$coeff[0] is a scalar .. not an array. Maybe you meant that $coeff[0]
is a reference to an array. How do you exactly assign to $coeff[0] ?

If you say:
	$coeff[$i] = $x;
Then $coeff[$i] is, most probably, not a reference to an array, only a
simple scalar.
However if you say:
	$coeff[$i] = [$x1, $x2, $x3 ..];
or
	push @{$coeff[$i]}, $x2, $x2, $x3, .. ;
or something of the sort, then $coeff[$i] will be a reference to an
anonymous array.

I suspect you are doing the first, but you want the second. Or maybe
you do the second, but are unable to access your individual elements.

> 
> I want to pass this array to a subroutine, and thinking a bit
> about efficiency, I figured a reference might be better.
> 
>   $f[0] += &subroutine( $begin, $end, \@coeff[$i] );

Hmmm.. do you use -w ? the above line should give you a warning if you
did. If $coeff[$i] is a reference to an array, then it's all you
want. Just pass it. If you want to pass a reference to @coeff then you
pass it as \@coeff.

> 
> I must be goofing somewhere in how I read the docs, because
> in the subroutine I need this in order to get the number
> of elements in the array:
>   local( $begin, $end, $r_coeff ) = @_;

Ok .. assuming that you passed a reference to an array, $r_coeff
should be a reference to that same array.

>   ...
>      = $#{$r_coeff->[0]}

$r_coeff->[0] makes you access the first element of the array
referenced by $r_coeff. You are then using this single element in a
list context to get the index of the last element of your virtual
(single-element) list. In simpler words, this gives you 0.

The proper way would be $#{@$r_coeff} 

btw, do you "use strict;" ??

Anyhow, this will give you the number of elements of the array - 1
(unless you messed with $[, in which case all of the Perl community
will probably shoot you), which is not what you want. Either add 1 to
the result or:

	..  = scalar @{$r_coeff};

> or to access the j'th element
>      = $$r_coeff[0][$j]

No .. to access the j-th element you write 
	$r_coeff->[$j]

> 
> How should a person be doing this?  (I've looked in perldoc,
> man and dejanews, so if it is in the docs somewhere, my brain
> isn't working.)

Perldoc should've pointed you to perldsc. Read that a few times before
you think over your approach. Pay close attention to the section
describing arrays of arrays.

> 
> Gordon Haverland
> haverlan @ agric.gov.ab.ca

Hope this helps,

Ala


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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 4195
**************************************

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