[18944] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1139 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 15 06:05:59 2001

Date: Fri, 15 Jun 2001 03:05:11 -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: <992599511-v10-i1139@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 15 Jun 2001     Volume: 10 Number: 1139

Today's topics:
    Re: [comp.lang.perl.misc] Re: Can an lvalue sub also be <q@tardis.ed.ac.maps.uk>
    Re: A simple pattern match problem? (Craig Berry)
    Re: Another possible need for a pattern match (Rolf Krahl)
    Re: ARGV <pne-news-20010615@newton.digitalspace.net>
    Re: cgi browser recognition <goldbb2@earthlink.net>
        DBI does not get all rows in DB2 table (andy standley)
    Re: FAQ 7.27:   How do I clear a package? <goldbb2@earthlink.net>
    Re: Help please with sourcing an environment variable <goldbb2@earthlink.net>
    Re: Help please with sourcing an environment variable <krahnj@acm.org>
    Re: How do I get the current directory from Windows Exp (Garry)
    Re: How do I get the current directory from Windows Exp <pne-news-20010615@newton.digitalspace.net>
    Re: initialising multi-dimensional array <pne-news-20010615@newton.digitalspace.net>
    Re: initialising multi-dimensional array <goldbb2@earthlink.net>
    Re: initialising multi-dimensional array <goldbb2@earthlink.net>
    Re: initialising multi-dimensional array <pne-news-20010615@newton.digitalspace.net>
    Re: Looking for good tutorial/book on Perl programming. <wyzelli@yahoo.com>
        Mail Attachment from StdIn <robin@aly.de>
    Re: Memory Issues/File Slurping <goldbb2@earthlink.net>
    Re: Multiplexing stdin and stderr to screen and logfile <goldbb2@earthlink.net>
    Re: Multiplexing stdin and stderr to screen and logfile <krahnj@acm.org>
        networ maps (Julien Baconat)
    Re: Premature end of srcipt headers? <goldbb2@earthlink.net>
    Re: Problems with Threads and Signal handlers <arbman@dhmail.net>
        Shrinking word <beyondcontrol@runbox.com>
        signals <todd@designsouth.net>
    Re: signals (Damian James)
    Re: transfer file <peter.sogaard@tjgroup.com>
    Re: transfer file <Graham.T.Wood@oracle.com>
    Re: Validating postcodes <goldbb2@earthlink.net>
    Re: Validating postcodes <pne-news-20010615@newton.digitalspace.net>
    Re: Validating postcodes (Craig Berry)
    Re: Validating postcodes <webmaster@webdragon.unmunge.net>
    Re: Validation and escape \ requirement? <davsoming@lineone.net>
        What is the ideal way to parse? <F.J.Dessing@siep.shell.com>
    Re: When Not To Mix select & read/print/<> (yes i RTFM) (Villy Kruse)
    Re: Why does my a: grind when I copy a file in perl? <andrew@mvt.ie>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 15 Jun 2001 11:03:09 +0100
From: Hugh Greene <q@tardis.ed.ac.maps.uk>
Subject: Re: [comp.lang.perl.misc] Re: Can an lvalue sub also be an rvalue?
Message-Id: <Pine.GS4.4.33.0106151101040.4989-100000@omega.tardis.ed.ac.uk>

On Fri, 15 Jun 2001, Gwyn Judd wrote:
> Subject: Re: Can an lvalue sub also be an rvalue?
> From: buggs <buggs-clpm@splashground.de>
> Newsgroups: comp.lang.perl.misc
>
> Ilya Zakharevich wrote:
> ...
> > <anno4000@lublin.zrz.tu-berlin.de>], who wrote in article
> > <9g7goh$qv2$1@mamenchi.zrz.TU-Berlin.DE>:
> >> > *No* question about programming may be answered by experiments (unless
> >> > answered negatively ;-).  ...
> >>
> >> ... I think you will agree too, that before asking "What would 'print
> >> sqrt(-1)' print?" it's a good idea to run "perl -le 'print sqrt(-1)'".
> >
> > I do not agree.  It is a good idea to run
> >
> >   perldoc -f sqrt
> >
> > If it does not help, no experiments will (unless you find two systems
> > which produce different results).
>
> I wonder what
>
> perldoc -f sqrt
>
> would produce.

Okay, somebody has to say this ...

It is a good idea to run

  man perldoc

(or maybe "info perldoc" on a GNU system :-)

Hugh
-- 
Version 3.1 GCS/IT d- s+:+>+: a- C++$ UL P+ L+(++) E W++$ N++ o K++ w(++) O?
M V? PS(+) PE Y+ PGP->++ t(+) 5+(++) X(+) R tv b++ DI+ D+ G e++ h- r>++ y+
(Removed reversed spam from my email address to reply)



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

Date: Fri, 15 Jun 2001 06:33:17 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: A simple pattern match problem?
Message-Id: <tijb1deh8m9v54@corp.supernews.com>

E.Chang (echang@netstorm.net) wrote:
: cberry@cinenet.net (Craig Berry) wrote in
: >   $string =~ tr/\n//s;
: 
: This is certainly the version to use, since it's much faster.  
: 
: Is this effect of /s  with a null replacement character documented 
: anywhere?

It's not an effect of /s, it's a general principle of tr///.  If the
replacement string is shorter than the pattern string and /d isn't
specified, then excess pattern characters translate to themselves.

  I interpreted "If the /s modifier is specified, sequences of 
: characters that were transliterated to the same character are squashed 
: down to a single instance of the character." to mean squashed to a 
: single instance of the replacement character, not the original, and 
: that is certainly what happens with a non-null. Just hoping to learn 
: something.

This still works as you describe with the addition of the rule above.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Magick is the art and science of causing change in conformity
   |   with Will."  - Aleister Crowley


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

Date: 15 Jun 2001 06:18:33 GMT
From: rolf.krahl@gmx.net (Rolf Krahl)
Subject: Re: Another possible need for a pattern match
Message-Id: <9gc9bp$5c3$1@rotkraut.de>

In article <9gbnuj$e3e$1@plutonium.btinternet.com>,
	"Leo Hemmings" <leapius@hotmail.com> writes:
> Hi all,
> 
> I need to substitute a string with the equivalent number of stars "*".
> 
> E.g:
> 
> hello = *****
> love perl = *********

| nuomi-> perl -w -e '$a = "hello"; $a =~ s/./*/g; print $a, "\n"'
| *****

-- 
		   Rolf Krahl <rolf.krahl@gmx.net>


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

Date: Fri, 15 Jun 2001 07:18:37 +0200
From: Philip Newton <pne-news-20010615@newton.digitalspace.net>
Subject: Re: ARGV
Message-Id: <5h4jito4i5kg06o3qltn291bmobcc7rpah@4ax.com>

On Wed, 13 Jun 2001 21:10:00 -0700, "Jürgen Exner"
<jurgenex@hotmail.com> wrote:

> "Bart Lateur" <bart.lateur@skynet.be> wrote in message
> news:quvcit4f2v2aaugr62o0auv89d6uq69bki@4ax.com...
[@ARGV]
> > It conteins the words on the command line.
> 
> No! It contains the arguments (from the command line). This can be
> individual words, but it can also be multiple words in a single value.

What you see might not even be what the user typed in (for example,
depending on your shell, wildcards may have been expanded, and you
probably will not have access to the exact number of spaces typed
between arguments[1]).

Cheers,
Philip

[1] This is a slight problem, for example, with shells which don't allow
you to put quotes around arguments that are to stay together; then you
could write a helper module such as Jenda Krynicky's G.pm that'll
reassemble them for you, but it can't tell whether qw("This is") in
@ARGV came from "This is" on the command line or from "This    is".
-- 
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: Fri, 15 Jun 2001 04:55:41 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: cgi browser recognition
Message-Id: <3B29CD8D.69B0FAA3@earthlink.net>

Kira's been replaced with a pod-person!  She's actually giving helpful
advice!

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: 14 Jun 2001 22:19:23 -0700
From: andrews@ecnetwork.co.nz (andy standley)
Subject: DBI does not get all rows in DB2 table
Message-Id: <74b11556.0106142119.3e258bf5@posting.google.com>

Hi,
	When I run my script on a AIX with a DB2 table I don't get all the
rows and the rows I do get are not all correct. Is there some cache
issue here. I looked at the manuals but no clues.... or is it just me
not looking hard enough???
	Any clues please

andy 





#!/usr/bin/perl

use DBI;
use DBD::DB2::Constants;
use DBD::DB2 qw($attrib_int $attrib_char $attrib_float
		$attrib_date $attrib_ts);

$cls = DBI->connect("dbi:DB2:devecndb", "", "", "");

$originator = "SUPPLIER";
$receiver = "FOODSTUFFS";
$type = "INVOIC";

$statement = "SELECT * FROM devecndb.parameters;";
$sth = $cls->prepare($statement);
print "Query will return $sth->{NUM_OF_FIELDS} fields.\n\n";

$sth->execute();
while (my @row = $sth->fetchrow_array){
  print "@row\n";
}

# check for problems which may have terminated the fetch early
warn $DBI::errstr if $DBI::err;

$sth->finish;


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

Date: Fri, 15 Jun 2001 04:53:31 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: FAQ 7.27:   How do I clear a package?
Message-Id: <3B29CD0B.7EBA7246@earthlink.net>

PerlFAQ Server wrote:
> +
>   How do I clear a package?
> 
>     Use this code, provided by Mark-Jason Dominus:
> 
>         sub scrub_package {
>             no strict 'refs';
>             my $pack = shift;
>             die "Shouldn't delete main package"
>                 if $pack eq "" || $pack eq "main";
>             my $stash = *{$pack . '::'}{HASH};
>             my $name;
>             foreach $name (keys %$stash) {
>                 my $fullname = $pack . '::' . $name;
>                 # Get rid of everything with that name.
>                 undef $$fullname;
>                 undef @$fullname;
>                 undef %$fullname;
>                 undef &$fullname;
>                 undef *$fullname;
>             }
>         }
> 
>     Or, if you're using a recent release of Perl, you can just use the
>     Symbol::delete_package() function instead.
> 
> -

Don't you also need to clear/close the filehandle, if there is one?
I think this would be done as:
	undef *{$fullname}{IO};
or
	close *$fullname;


-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: Fri, 15 Jun 2001 01:23:52 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Help please with sourcing an environment variable
Message-Id: <3B299BE8.36234F2B@earthlink.net>

Abigail wrote:
> 
> Simon Barnard (sbarnard@dial.pipex.com) wrote:
> &&
> &&  $ENV{DB_USER} = `. <path to shell script>; echo $DB_USER`;
> &&  $ENV{DB_PASSWD} = `. <path to shell script>; echo $DB_PASSWD`;
> 
> $DB_USER and $DB_PASSWD are interpolated by Perl before the line is
> passed to the shell. You would need to escape the $ signs with a
> backslash.

Or else use qx and '

chomp $ENV{DB_USER}   = qx'. <path to shell script>; echo $DB_USER  ';
chomp $ENV{DB_PASSWD} = qx'. <path to shell script>; echo $DB_PASSWD';

Of course, it would be better to do both assignments at once:
chomp @ENV{DB_USER,DB_PASSWD} = qx'
	. <path to shell script>
	echo $DB_USER
	echo $DB_PASSWD';

You also need chomp on the `` version, unless DBI ignores a trailing
newline on the userid and password.

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: Fri, 15 Jun 2001 09:26:58 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Help please with sourcing an environment variable
Message-Id: <3B29D513.22A08BA3@acm.org>

Benjamin Goldberg wrote:
> 
> Abigail wrote:
> >
> > Simon Barnard (sbarnard@dial.pipex.com) wrote:
> > &&
> > &&  $ENV{DB_USER} = `. <path to shell script>; echo $DB_USER`;
> > &&  $ENV{DB_PASSWD} = `. <path to shell script>; echo $DB_PASSWD`;
> >
> > $DB_USER and $DB_PASSWD are interpolated by Perl before the line is
> > passed to the shell. You would need to escape the $ signs with a
> > backslash.
> 
> Or else use qx and '

And use chomp correctly.

> chomp $ENV{DB_USER}   = qx'. <path to shell script>; echo $DB_USER  ';
> chomp $ENV{DB_PASSWD} = qx'. <path to shell script>; echo $DB_PASSWD';

chomp( $ENV{DB_USER}   = qx'. <path to shell script>; echo $DB_USER  '
);
chomp( $ENV{DB_PASSWD} = qx'. <path to shell script>; echo $DB_PASSWD'
);

> Of course, it would be better to do both assignments at once:
> chomp @ENV{DB_USER,DB_PASSWD} = qx'
>         . <path to shell script>
>         echo $DB_USER
>         echo $DB_PASSWD';

chomp( @ENV{DB_USER,DB_PASSWD} = qx'
        . <path to shell script>;
        echo $DB_USER;
        echo $DB_PASSWD' );

> You also need chomp on the `` version, unless DBI ignores a trailing
> newline on the userid and password.


John
-- 
use Perl;
program
fulfillment


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

Date: 15 Jun 2001 01:59:47 -0700
From: garry_short@hotmail.com (Garry)
Subject: Re: How do I get the current directory from Windows Explorer?
Message-Id: <bdcefd33.0106150059.507111f0@posting.google.com>

Mr. SunRay <nospam@hotmail.com> wrote in message news:<64PV6.769$hw6.272456@news.uswest.net>...
> > I'm writing a script that is triggered by actions within Windows ...
< SNIP >
> 
> Sounds like a job for Win32::OLE - ick, ick, ICK!

Hmm. I've looked through Win32::OLE. Either there's nothing useful in
there (possible), or I'm just not seeing it (far too likely!), or I'm
not recognising it as what I'm after. I'll have another look, but any
other suggestions would be more than welcome!
> 
> <some stuff snipped>
> > 
< SNIP CLEARCASE STUFF > 
> > --
> > 
> > Many thanks,
> > 
> > Garry
> 
> I've used clearcase in unix, but not NT, and it's been a while.  I did notice 
> that there are a few clearcase modules out on CPAN.  Perhaps they can help you 
> out?  I haven't looked at them myself.
> 

There are four modules that I could find (I had a look for them before
replying - previously, I'd only noticed the clearcase scripts on
there), and all look pretty good. Unfortunately, it looks as though
they're all designed to be used from the command prompt; certainly,
none of them offer what I'm after at the moment.

> Doesn't ClearCase use/set some special environment variables (clearcase_root 
> comes to mind) that perhaps you could use as well?
> 

I think you're thinking of <ccase_root_dir>, which is the root
directory of where the software is installed. The trouble is,
environment variables are usually static, whereas the view I'm
currently isn't :-(

> Regards,
> 
> Mr. Sunray

Thanks for the suggestions so far - any other ideas?

Regards,

Garry


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

Date: Fri, 15 Jun 2001 11:47:47 +0200
From: Philip Newton <pne-news-20010615@newton.digitalspace.net>
Subject: Re: How do I get the current directory from Windows Explorer?
Message-Id: <tamjitknv9rmpj575ebndjpo22cjo1jrk1@4ax.com>

On 15 Jun 2001 01:59:47 -0700, garry_short@hotmail.com (Garry) wrote:

> Hmm. I've looked through Win32::OLE. Either there's nothing useful in
> there (possible), or I'm just not seeing it (far too likely!), or I'm
> not recognising it as what I'm after.

The main strengths of Win32::OLE are not in itself, but in the OLE
objects you can call from it. For example, you can query not only
Microsoft Word but also other programs. So maybe there is a Windows
Shell OLE object that has a property or method which will tell you the
current Windows Explorer directory (though if you have three Explorers
open, you'll have to find the right one to query).

So you'd really have to look for information about how you can talk to
Explorer with OLE, or if that's possible at all.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
Yes, 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: Fri, 15 Jun 2001 07:18:38 +0200
From: Philip Newton <pne-news-20010615@newton.digitalspace.net>
Subject: Re: initialising multi-dimensional array
Message-Id: <6n4jitsbq0teo12d2bd6jmhdhdlggr9cfk@4ax.com>

On Thu, 14 Jun 2001 15:47:27 +0100, Mark Grimshaw
<m.grimshaw@salford.ac.uk> wrote:

> I'm currently setting all columns to 0 (if they're undef) _after_ I've
> populated (parts of) the array.  It works but is a loop within a loop. 

You may be able to speed this up a little by changing code like this

    for($i = 0; $i < $numcols; $i++) {
        $array[$row][$i] = 0;
    }

to something like this

    @{$array[$row]}[0..$numcols-1] = (0) x $numcols;

, which moves the loop from Perl code into C code.

> This being perl, I thought there might be a faster/simpler/more
> efficient way to do it.  i.e. something like a special variable (like
> the $INPUT_RECORD SEPARATOR - $/) which I can set to 0 meaning that all
> unpopulated array elements (that have been skipped during the population
> process) will be 0 instead of the default undef.

Not that I know of. (Barring tied variables.)

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: Fri, 15 Jun 2001 02:13:02 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: initialising multi-dimensional array
Message-Id: <3B29A76E.C9913726@earthlink.net>

Mark Grimshaw wrote:
> 
> Philip Newton wrote:
> >
> > On Thu, 14 Jun 2001 15:15:56 +0100, Mark Grimshaw
> > <m.grimshaw@salford.ac.uk> wrote:
> >
> > > Mark Grimshaw wrote:
> > > >
> > > > How do I initialise everything in a multi-dimensional array to 0
> > > > (or any variable for that matter)?  Currently, all rows/column
> > > > elements are undef.
> > >
> > > Forgot to add, I don't know the number of rows/columns beforehand.
> >
> > How are you going to find out, then?
[snip]
> I'm currently setting all columns to 0 (if they're undef) _after_ I've
> populated (parts of) the array.  It works but is a loop within a loop.
> This being perl, I thought there might be a faster/simpler/more
> efficient way to do it.  i.e. something like a special variable (like
> the $INPUT_RECORD SEPARATOR - $/) which I can set to 0 meaning that
> all unpopulated array elements (that have been skipped during the
> population process) will be 0 instead of the default undef.

This is an interesting idea, but there is no way to do what you suggest.
It would require a change to the perl source.  Maybe you can make it a
suggestion for perl 6.

Part of the problem is that when an array is magically grown, there is
no requirement that that much memory be allocated -- it could be
implemented as a sparse array of some sort.  For example:
	my @x; $x[100_000] = 42;
There is no requirement that perl allocate 100,000 empty elements and
populate them with undef.  It could have some funky structure like:
struct spare_array {
	int nelems;
	struct {
		int blanks;
		int nelems;
		SV  *elems;
	} * unsparse_stretches;
	int trailing_blanks;
}

So @x would contain just:
	{ 1, { 100000, 1, {42} }, 0 }

Without having allocated 100,000 elements.

Sparse arrays can use much less memory, but they are often rather
slower.

So as stated, what you want can't be done.  However, you can get
something close to it... instead of definining a default value for
initialization, you could define a default value for when you fetch from
the array.  To do this, use a tied array, of course.

package MyArray;
use Tied::Array;
use lib qw(Tied::StdArray);
sub FETCH {
	return $_[0]->[$_[1]] if exists $_[0]->[$_[1]];
	return $_[0]->[$_[1]] = 0;
}

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: Fri, 15 Jun 2001 02:46:46 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: initialising multi-dimensional array
Message-Id: <3B29AF56.68DF1356@earthlink.net>

Michael Carman wrote:
[snip]
> But this doesn't work, because when you say
> 
> $x[5][1] = 4;
> 
> perl first looks up $x[5] (using the FETCH method). Our new class
> obediently returns 0 instead of undef, and therefore perl won't
> autovivify a reference to a new anonymous array. Damn.
> 
> What we really need here is a wantref() function so that FETCH can
> know how it's being used, but there's no such builtin. Does anyone
> have any ideas on how to emulate one?

Perhaps in perl6 we'll get such a thing, possibly bundled with what will
used to have been wantarray.  I would propose it be called context(),
and return undef in void context (as wantarray does), "SCALAR", "ARRAY",
"HASH" or "CODE" when the return value is being used as a reference to
one of those, "method" if some method is being called on it, "list" if
called in list context, and "scalar" if nothing more specific can be
figured out.  Done this way, even ordinary subs would benefit from it.

	somesub();		# context() in somesub() is undef
	scalar somesub();	# context() in somesub() is "scalar"
	@{[somesub()]};		# context() in somesub() is "list"
	@{ somesub() };		# context() in somesub() is "ARRAY"
	${ somesub() };		# context() in somesub() is "SCALAR"
	%{ somesub() };		# context() in somesub() is "HASH"
	&{ somesub() );		# context() in somesub() is "CODE"
	*{ somesub() };		# context() in somesub() is "GLOB"
	*{ somesub() }{IO};	# context() in somesub() is "IO"
	print { somesub() };	# context() in somesub() is "IO"
	somesub() -> xyz();	# context() in somesub() is "method"

If anyone thinks this is a bad idea, please say so.  I'm writing this at
2:45 am, so I might possibly be off my rocker atm.  I'm especially not
sure on GLOB and IO.  Also, testing for lvalue-ness is desired, somehow.

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: Fri, 15 Jun 2001 09:16:28 +0200
From: Philip Newton <pne-news-20010615@newton.digitalspace.net>
Subject: Re: initialising multi-dimensional array
Message-Id: <hbdjit092ggb4u6g3jn7pfp09f3gnudef1@4ax.com>

On Fri, 15 Jun 2001 02:46:46 -0400, Benjamin Goldberg
<goldbb2@earthlink.net> wrote:

> Perhaps in perl6 we'll get such a thing, possibly bundled with what will
> used to have been wantarray.  I would propose it be called context(),

IIRC, it may be called 'want'.

> 	@{[somesub()]};		# context() in somesub() is "list"

Even better, I think it'll give you the number of elements wanted. For
example, given

    ($foo, $bar, $baz) = somesub();

somesub() will have some way of knowing that three elements are wanted
and do optimisations similar to the ones split does now.

> If anyone thinks this is a bad idea, please say so.  I'm writing this at
> 2:45 am, so I might possibly be off my rocker atm.  I'm especially not
> sure on GLOB and IO.  Also, testing for lvalue-ness is desired, somehow.

I think want() will give you back not just one item of information, but
you can query it for multiple things (e.g. lvalue-ness independently of
number-of-return-elements-expected, or whatever).

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: Fri, 15 Jun 2001 14:34:22 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Looking for good tutorial/book on Perl programming.
Message-Id: <sEgW6.33$vM6.4406@vic.nntp.telstra.net>

"Axiom" <ufnitehawk@yahoo.com> wrote in message
news:9gb0cb$jlq$1@node21.cwnet.roc.gblx.net...
> I'm a windows user. If you have any information on a good tutorial/book
that
> i can use to learn please inform me. I am wanting to get into Perl
> programming and using it on web design.
>

http://www.manning.com/Johnson/index.html

One of the most useful for starting out that I have come across.

Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass it
around');
$d='$_$a$s$b$w';$e='$_$a$s$b';sub d{$h=shift;$h=~s/\$(\w+)/${$1}/g;return$h}
sub
e{return(shift!=1)?'s':''}for(reverse(1..100)){$s=e($_);$f=d($d);$g=d($e);
$c.="$f\n$g\n$t\n";$_--;$s=e($_);$e=d($d);$c.="$e\n\n";}print"$c*hic*";




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

Date: Fri, 15 Jun 2001 09:09:42 +0200
From: "Robin Aly" <robin@aly.de>
Subject: Mail Attachment from StdIn
Message-Id: <9gcc8p$pnv$04$1@news.t-online.com>

Hello,

I need to extract an attachment of a Mime-EMail that comes from STDIN. The
attachment will be the second part of the email. it will be a txt.File
written on a windows system. Will encoding be a problem.

thank you
robin




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

Date: Fri, 15 Jun 2001 04:26:12 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Memory Issues/File Slurping
Message-Id: <3B29C6A4.82B41942@earthlink.net>

Doug McGrath wrote:
[snip]
>     if ($line =~ m/^\s*head\s+(.*?);/oscg)
>         <snip>
>     if ($line =~ m/\G\s*branch\s+(.*?);/oscg)
>         <snip>
>     if ($line =~ m/\G\s*access\s*(.*?);/oscg)
>         <snip>
>     if ($line =~ m/\G\s*symbols\s*(.*?);/oscg)
>         <snip>
>     if ($line =~ m/\G\s*locks\s*(.*?);/oscg)
>         <snip>
>     $line =~ m/\G\s*strict\s*;/scg;
>     if ($line =~ m/\G\s*comment\s+(\@.*?[^\@]\@)?;/oscg)
>         <snip>
>     if ($line =~ m/\G\s*expand\s+(.*?);/oscg)
>         <snip>

Firstly, the /o has no effect, since there are no interpolations in the
matches.  Second, you could probably benefit quite a bit by replacing
the "if"s with "elsif"s if these are done in a loop.  Third, have you
considered using one [large] regex for parsing some parts?  The /x
option will help quite a bit here.

my $string = qr[ \@((:[^\@]|\@\@)*))\@ ];

$line =~ m[^
	\s*	head	\s*	([^;]*)	;
(:	\s*	branch	\s*	([^;]*)	;	)?
	\s*	access	\s*	([^;]*)	;
	\s*	symbols	\s*	([^;]*)	;
(:	\s*	locks	\s*	([^;]*)	;	)?
(	\s*	strict	\s*		;	)?
(:	\s*	comment	\s*	$string	;	)?
(:	\s*	expand	\s*	$string	;	)?
	]xg or die "Invalid RCSfile -- bad header, begining at " . pos;
($head,$branch,$access,$symbols,$locks) = ($1, $2, $3, $4, $5);
$strict = ($6 ? 1 : 0);
($comment = $7) =~ s/@@/@/g;	# I hope this doesn't change pos()
($expand  = $8) =~ s/@@/@/g;

while( $line =~ m[\G
	\s*	([0-9.]+)
	\s*	date	\s*	([^;]+)	;
	\s*	author	\s*	([^;]+)	;
	\s*	state	\s*	([^;]*)	;
	\s*	branches\s*	([^;]*)	;
	\s*	next	\s*	([^;]*)	;
	]xg ) {
	# do stuff with $1 .. $5
}

$line =~ m[\G
	\s*	desc	$string
	]xg or die "No desc.  Expected it near: " . pos();
($desc = $1) =~ s/@@/@/g;

while( 1 ) {
	$line =~ m[\G
		\s*	([0-9.]+)
		\s*	log	$string
	]xg;
	my ($num, $log) = ($1, $2);
	$line =~ m[\G
		\s*	text	$string
	]xg or last;
	my $text = $1;
	# do stuff with $num, $log, $text
}
	
> Hopefully, these snippets will be enough detail. What it looks like to
> me is either that the regular expression engine isn't freeing its
> memory, or that the expressions I'm using are causing a lot of memory
> fragmentation so that the free pool can't be reused efficiently.

Or else memory is leaking elsewhere.  Are you sure that you either
eliminate all references to $line or else assign undef or somesuch to
it?

> If I have to, I can go back to re-reading the repository file line by
> line, but the slurping method got a 50% performance increase for most
> of our operations, and this is stuff that we use constantly. Some of
> the scripts that rely on this module were taking an hour and a half to
> run; with the new method, they run in under 10 minutes, so the savings
> are considerable.

Just offhand, is this being used in mod_perl or somesuch?  What kind of
application is handling RCS files in such huge numbers?  I would think
that any single process would touch only a small number of files [and
then exit], making memory leaks less important.

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: Fri, 15 Jun 2001 01:36:11 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Multiplexing stdin and stderr to screen and logfile
Message-Id: <3B299ECB.2E2FBEC0@earthlink.net>

This isn't a perl solution, but isn't there a unix program called "type"
or somesuch which creates a tty, handles all stdin, stdout, and stderr
for the program given on the commandline, even allowing normal
interaction with a user?

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: Fri, 15 Jun 2001 09:29:54 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Multiplexing stdin and stderr to screen and logfile
Message-Id: <3B29D5C3.4A7CB747@acm.org>

Benjamin Goldberg wrote:
> 
> This isn't a perl solution, but isn't there a unix program called "type"
> or somesuch which creates a tty, handles all stdin, stdout, and stderr
> for the program given on the commandline, even allowing normal
> interaction with a user?

Are you thinking of "expect"?


John
-- 
use Perl;
program
fulfillment


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

Date: 15 Jun 2001 09:27:08 GMT
From: baconat@ensg.ign.fr (Julien Baconat)
Subject: networ maps
Message-Id: <slrn9ijlp6.673.baconat@potee.ensg.ign.fr>


Hi,

I'm looking for free softwares such as Tkined but in PERL in order to map
my network 

Thanks for your answers

julien


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

Date: Fri, 15 Jun 2001 04:39:54 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Premature end of srcipt headers?
Message-Id: <3B29C9DA.269C3D4B@earthlink.net>

Unbelievable!  An intelligent, useful post by Kira!  I'm having a heart
attack from shock!

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: Fri, 15 Jun 2001 10:08:29 +0200
From: Scott Rutherford <arbman@dhmail.net>
Subject: Re: Problems with Threads and Signal handlers
Message-Id: <3B29C27D.D012342@dhmail.net>

Dan Sugalski wrote:

> Scott Rutherford <arbman@dhmail.net> wrote:
> > Dan Sugalski wrote:
> >>
> >> Well, the best you can do is read the thread docs for the platforms
> >> you're working on. Most Unices conform fully to the POSIX thread
> >> standard at this point (assuming a recent version of them, of
> >> course) and their docs normally mention where they don't. Non-unix
> >> platforms might be a bit trickier, but for signals it's not a big
> >> deal, as signals are a unix thing anyway.
> >>
> >>                                         Dan
>
> > Ok, I tried the Thread::Signal module but I didn't seem to get anywhere,
> > but I figure that trying to combine forking, signals and threads is probably
> > unnecessary and certainly painful. So I've opted for a fully threaded
> > approach.
>
> Mixing threads and fork is a bad idea. You hit all sorts of deadlock problems
> that way.
>
> > However whatever the situation I couldn't get Thread::Signal to work infact
> > non of
> > the scripts containing
>
> > use Thread::Signal
>
> > wouldn't even run!!!
>
> What errors were you getting?

Acutally I think I may of been a bit hasty with that comment, as I found another
bug
yesterday evening that produces a random (in time) segmentation fault very
similar to the one I got when I used Thread::Signal (which I blamed for it).

So I have a feeling that it was a but of a coincidence and in fact the error was
due to
a variable access problem in HTTP::Request and URI. (as yet unresolved) So when
that is sorted I will probably try to install a handler for SIG{INIT} so I will
let you know
then if I have an further problems.

Cheers for your help thus far.
Scott

>
>
>                                                 Dan



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

Date: Wed, 13 Jun 2001 19:14:00 +0200
From: "BeyondContol Inc." <beyondcontrol@runbox.com>
Subject: Shrinking word
Message-Id: <9gcd8g$rld$1@news.netvision.net.il>

Hello,

The example in Win32::OLE, word2xxx, can transform a word document to an
HTML file by invoking Word.Application.

I was wondering if someone tried to access the document directly,
without invoking word itself, and shrink it to a text or HTML file....

It's just that I want to be able to run this script on computers without
ms-office.
Anyone?




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

Date: Fri, 15 Jun 2001 08:51:02 GMT
From: "Todd Smith" <todd@designsouth.net>
Subject: signals
Message-Id: <W%jW6.152832$I5.44340397@news1.rdc1.tn.home.com>

How do I make perl run a subroutine instead of printing out an error message
if the script dies? And I don't mean on a 'die', I mean if it has an error
that I wasn't aware of (but still compiles).




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

Date: 15 Jun 2001 09:04:58 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: signals
Message-Id: <slrn9ijjsu.llu.damian@puma.qimr.edu.au>

Todd Smith chose Fri, 15 Jun 2001 08:51:02 GMT to say this:
>How do I make perl run a subroutine instead of printing out an error message
>if the script dies? And I don't mean on a 'die', I mean if it has an error
>that I wasn't aware of (but still compiles).
>

You need a signal handler :-).

$SIG{__DIE__} = coderef;

See 
	perldoc perlvar

	and

	perldoc perlipc

for details.

HTH,

Cheers,
Damian
-- 
@:=grep!($;+=m!$/|#!),split//,<DATA>;@;=0..$#:;while(@;){for($;=@;;--$;;)
{@;[$;,$:]=@;[$:,$;]if($:=rand$;+$|)!=$;}push@|,shift@;if$;[0]==@|;select
$,,$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker # rev 3.1 -- a JAPH in progress, I guess...


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

Date: Fri, 15 Jun 2001 11:02:39 +0200
From: "Peter Søgaard" <peter.sogaard@tjgroup.com>
Subject: Re: transfer file
Message-Id: <9gciqb$jln$1@news.inet.tele.dk>


"miss" <north@nmpm.com.my> wrote in message
news:3B298430.F98FB467@nmpm.com.my...
> Dear sir/madam;
>
> Does anyone know how to use perl program to transfer the file. eg: I got
> C:/temp/a.txt ,when I run perl ,it will copy this a.txt to other folder/
> pc.
>
> how to do this??

link 'C:\temp\a.txt','C:\otherfolder\a.txt'

>
> Dose anyone what is e-ftp.bat ?
> how does it function??
>
>




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

Date: Fri, 15 Jun 2001 10:46:24 +0100
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: transfer file
Message-Id: <3B29D970.57C6A5DD@oracle.com>

This is a multi-part message in MIME format.
--------------F5901E8257665299470C4954
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit



miss wrote:

> Dear sir/madam;
>
> Does anyone know how to use perl program to transfer the file. eg: I got
> C:/temp/a.txt ,when I run perl ,it will copy this a.txt to other folder/
> pc.
>
> how to do this??
>

Use the File::Copy module and the copy function that is in it.  This is
installed with the base Perl distribution so all you need to do is this.
----------------------------------------------------------------
use File::Copy; # before calling copy

copy("C:/temp/a.txt","C:/other/folder/a.txt") || die "Can't copy a.txt
$!\n";
----------------------------------------------------------------

The last part

     || die "Can't copy a.txt $!\n"

will tell you what happened if the file copy failed.  It is not essential
but is sensible.


>
> Dose anyone what is e-ftp.bat ?
> how does it function??

I'm guessing the e-ftp.bat is a batch file that automates an FTP (File
Transfer Protocol) transfer to a remote machine but I've never seen it so I
can't say for certain.

Graham Wood

--------------F5901E8257665299470C4954
Content-Type: text/x-vcard; charset=UTF-8;
 name="Graham.T.Wood.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Graham Wood
Content-Disposition: attachment;
 filename="Graham.T.Wood.vcf"

begin:vcard 
n:;Graham
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:Graham.T.Wood@oracle.com
fn:Graham Wood
end:vcard

--------------F5901E8257665299470C4954--



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

Date: Fri, 15 Jun 2001 01:42:31 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Validating postcodes
Message-Id: <3B29A047.2DB015DB@earthlink.net>

Craig Berry wrote:
> 
> Wayne Marrison (wayne.marrison@consignia.com) wrote:
> : I need to validate postcodes given to my program to ensure that they
> : correspond to the RoyalMail standard (UK).
> :
> : I have the patterns required, i.e. "AN NAA","ANN NAA",
> : "AAN NAA","AANN NAA","ANA NAA","AANA NAA","AAA NAA" (with or
> : without the space) and need to ensure that the code passed to my
> : program conforms to one of the above (A=Alpha, N=Numeric).
> 
> #!/usr/bin/perl -w
> # postcode - validate British post codes (demo for clpm)
> # Craig Berry (20010614)
> 
> use strict;
> 
> my @patterns = ('AN NAA', 'ANN NAA', 'AAN NAA', 'AANN NAA',
>                 'ANA NAA', 'AANA NAA', 'AAA NAA');
> 
> foreach (@patterns) {
>   s/A/[A-Z]/g;
>   s/N/\\d/g;
>   s/ /\\s?/g;
> }
> 
> my $re = join '|', @patterns;
> 
> while (<>) {
>   print /^(?:$re)$/o ? "valid\n" : "invalid\n";
> }

Why do you have the /o here?  Since the string $re does not change on
successive iterations of the loop, the regular expression version of it
is not recreated on successive iterations (for most modern perls,
anyway).

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: Fri, 15 Jun 2001 07:58:19 +0200
From: Philip Newton <pne-news-20010615@newton.digitalspace.net>
Subject: Re: Validating postcodes
Message-Id: <1u8jitk52g9i71nio1uuvsmdu7ucd7r1m7@4ax.com>

On Fri, 15 Jun 2001 01:42:31 -0400, Benjamin Goldberg
<goldbb2@earthlink.net> wrote:

> Craig Berry wrote:
> > 
> > while (<>) {
> >   print /^(?:$re)$/o ? "valid\n" : "invalid\n";
> > }
> 
> Why do you have the /o here?  Since the string $re does not change on
> successive iterations of the loop, the regular expression version of it
> is not recreated on successive iterations (for most modern perls,
> anyway).

I don't think this behaviour is guaranteed, while the behaviour of /o is
documented.

Also, this saves Perl the bother of checking $re on each iteration to
see whether it has changed, which it would otherwise have to do to
determine whether it can re-use the compiled form.

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: Fri, 15 Jun 2001 06:30:39 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Validating postcodes
Message-Id: <tijasff9uojq1c@corp.supernews.com>

Benjamin Goldberg (goldbb2@earthlink.net) wrote:
: > while (<>) {
: >   print /^(?:$re)$/o ? "valid\n" : "invalid\n";
: > }
: 
: Why do you have the /o here?  Since the string $re does not change on
: successive iterations of the loop, the regular expression version of it
: is not recreated on successive iterations (for most modern perls,
: anyway).

First, because of that 'recent perls' caveat, and on the general principle
that it's nice to help the compiler optimize when you can.  Second,
because it documents for human readers that the interpolated variable is
not intended to change. 

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Magick is the art and science of causing change in conformity
   |   with Will."  - Aleister Crowley


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

Date: 15 Jun 2001 07:18:34 GMT
From: "Scott R. Godin" <webmaster@webdragon.unmunge.net>
Subject: Re: Validating postcodes
Message-Id: <9gccsa$i7q$0@216.155.32.176>

In article <tijasff9uojq1c@corp.supernews.com>,
 cberry@cinenet.net (Craig Berry) wrote:

 | Benjamin Goldberg (goldbb2@earthlink.net) wrote:
 | : > while (<>) {
 | : >   print /^(?:$re)$/o ? "valid\n" : "invalid\n";
 | : > }
 | : 
 | : Why do you have the /o here?  Since the string $re does not change on
 | : successive iterations of the loop, the regular expression version of it
 | : is not recreated on successive iterations (for most modern perls,
 | : anyway).
 | 
 | First, because of that 'recent perls' caveat, and on the general principle
 | that it's nice to help the compiler optimize when you can.  Second,
 | because it documents for human readers that the interpolated variable is
 | not intended to change.

Thanks for clarifying that, Craig. I was wondering myself after he 
asked, since on first read, it had 'made sense' to me, and I wasn't 
aware of the 'recent perls' difference.. 

Seems to make good sense from a maintainer's perspective. :-)

-- 
unmunge e-mail here:
#!perl -w
print map {chr(ord($_)-3)} split //, "zhepdvwhuCzhegudjrq1qhw"; 
# ( damn spammers. *shakes fist* take a hint. =:P )


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

Date: Fri, 15 Jun 2001 05:39:01 +0100
From: "David Soming" <davsoming@lineone.net>
Subject: Re: Validation and escape \ requirement?
Message-Id: <tij3v3spp7tmd9@corp.supernews.co.uk>


"John W. Krahn" <krahnj@acm.org> wrote in message
news:3B297986.FF711A1@acm.org...
> David Soming wrote:
> >
> > <snipped>
> > > >
> > > > The hyphen character (-) is special in character classes hence it
has to
> > > > be escaped unless it is at the beginning or end or specifies a valid
> > > > range of characters.
> > >
> > This is at the 'end' but ($) trips errormessage:
tr/a-zA-Z0-9?',£&.!$-\n\t
> > //c)
> > Now I am confused!
>
> Here you have a hyphen between the dollar sign and the newline
> characters, not at the end.
> Either
> tr/a-zA-Z0-9?',£&.!$\n\t -//c;
> or
> tr/-a-zA-Z0-9?',£&.!$\n\t //c;
>
Thanks for the lesson John! I presumed the new line was the end.. but
clearly not -Much wiser now :-)
> John
> --
> use Perl;
> program
> fulfillment




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

Date: Fri, 15 Jun 2001 10:01:45 +0200
From: "Frank Dessing" <F.J.Dessing@siep.shell.com>
Subject: What is the ideal way to parse?
Message-Id: <JhjW6.310$O6.2628@wwwserv3.shell.nl>

Hi,

I am looking for a way to parse variables into a scripts. The scripts can be
unix or another language.

What I want to do looks like this. I have a long script with here and there
a variable at a certain position in the line. The variables should be
sometimes of a fixed format. The script can have the following structure.

=== START_OF_SCRIPT
command1 $variable1 remainder_of_command1
command2
$variable3 command3
=== END_OF_SCRIPT

At the moment I read the base script and search for $variable1, $variable2
etc. and replace them with a s/// command. Subsequently I write the replaced
lines to a new file. This is perfectly doable as long as the number of
variables is small. If the number of variables gets larger the substitution
approach starts to become more problematic.

Any ideas on more efficient solutions.

Thanks,

Frank Dessing




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

Date: 15 Jun 2001 07:15:52 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: When Not To Mix select & read/print/<> (yes i RTFM)
Message-Id: <slrn9ijdh7.go5.vek@pharmnl.ohout.pharmapartners.nl>

On Thu, 14 Jun 2001 14:21:02 -0400,
       Antoine Beaupre (LMC) <Antoine.Beaupre@lmc.ericsson.se> wrote:

>
>"
>B<WARNING>: One should not attempt to mix buffered I/O (like C<read()>
>or E<lt>FHE<gt>) with C<select()>, except as permitted by POSIX, and 
>even then only on POSIX systems.  You have to use C<sysread()> instead.
>"
>
>(great, along with pod formatting... :)
>
>Do I have to read the whole POSIX spec to know when it's permitted??? :) 
>And would anyone have a easy reference to that spec, by any chance?
>


The problem with select is that it doesn't check if you have data pending
in the input buffer.  If you do and the socket is not readable at the
moment, then select will tell you you don't have data to read.  

For example if you read 10 bytes using read from a socket, the perl io
system might get 200 bytes from the socket and hand the first 10 to
your program.  Subsequent reads will then return more bytes from the
stored 200 bytes, but if the first 200 bytes is all the sender has sent
this time, select will return read not ready.



Villy


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

Date: Fri, 15 Jun 2001 09:49:15 +0100
From: "Andrew" <andrew@mvt.ie>
Subject: Re: Why does my a: grind when I copy a file in perl?
Message-Id: <9gcib2$oap$1@kermit.esat.net>


"Ron Savage" <ron@savage.net.au> wrote in message
news:pdcW6.4862$qJ4.213872@ozemail.com.au...
> See below
 ...
> Arvin Portlock <temp133@hotmail.com> wrote in message
news:9gb1di$2c4l$1@agate.berkeley.edu...
> > I'm guessing this isn't a perl-specific question, or at least the
> > solution won't be perl-specific.
> >
> > Whenever I do file copy in perl, my a: drive starts to grind for
> > a couple of seconds, even though I'm not copying anything to
>
> Probably an anti-virus program.
>
Also, check your PATH environment variable to see if it's pointing at the a:
drive




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

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


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