[9490] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3084 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 7 16:07:31 1998

Date: Tue, 7 Jul 98 13:00:26 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 7 Jul 1998     Volume: 8 Number: 3084

Today's topics:
    Re: -w on production code (Abigail)
    Re: 5.004_69 win32 Glob problem <JKRY3025@comenius.ms.mff.cuni.cz>
    Re: 5.004_69 win32 Glob problem (Greg Bacon)
    Re: Accessing shell variables in a perl script <xmarkjones@mindless.com>
    Re: Accessing shell variables in a perl script (I R A Aggie)
        Batch printing of html files <pensch@dadd.ti.com>
    Re: Batch printing of html files (John Stanley)
    Re: better way of getting the last modified file? (Sitaram Chamarty)
    Re: Debug ? <indy@NOSPAMdemobuilder.com>
    Re: Debug ? <indy@NOSPAMdemobuilder.com>
    Re: delete key from array coderkid@hotmail.com
    Re: Globbing from a list (Scott Erickson)
    Re: help I'm a beginner (Mark-Jason Dominus)
    Re: help I'm a beginner (Larry Rosler)
        Image::Magick and Global Color Table <rar@rentrak.com>
    Re: Is Perl through CGI enough for this? <jc@ral1.zko.dec.com>
        Literal string evaluation question (Curry Taylor)
    Re: Literal string evaluation question (Mark-Jason Dominus)
        locking in perl <ran@sgi.com>
    Re: locking in perl (Michael J Gebis)
    Re: newbie q: populating array with interpolated scalar <indy@NOSPAMdemobuilder.com>
    Re: Oh man, DO I love Perl ! (References to things that <jc@ral1.zko.dec.com>
    Re: open2 problems (Harold Bamford)
        Out of memory in sort <chris@zucchini.linz.govt.nz>
        print multiline strings <howard@vortexweb.com>
    Re: question about objects (Tye McQueen)
    Re: regexp s/// for removing tail end of string (Sitaram Chamarty)
        serious bug in Time::Local? (Kajetan Hinner)
    Re: setting @INC in (ActiveState) Perl 5 for Win32 <JKRY3025@comenius.ms.mff.cuni.cz>
    Re: SQL and apostrophe <JKRY3025@comenius.ms.mff.cuni.cz>
        syscall <emge@insulae.neurology.umab.edu>
    Re: why won't my compare work <indy@NOSPAMdemobuilder.com>
    Re: why won't my compare work <indy@NOSPAMdemobuilder.com>
        Win32::Internet <josri@postoffice.pacbell.net>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 7 Jul 1998 18:25:23 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: -w on production code
Message-Id: <6ntp6j$9al$1@client3.news.psi.net>

Mike Stok (mike@stok.co.uk) wrote on MDCCLXXI September MCMXCIII in
<URL: news:6ntjm7$f59@news-central.tiac.net>:
++ In article <35a24712.522455541@news.mr.net>,
++ Scott Erickson <Scott.L.Erickson@HealthPartners.com> wrote:
++ 
++ >I agree that removing the -w switch is one way to eliminate some of
++ >the error messages that are filling up your error logs. However, I
++ >believe a better action to take is to fix the code that is causing the
++ >error messages.
++ >
++ >Where I am working, we are taking such an approach, fix the errors and
++ >leave in the -w switch for production code. However, we have lots of
++ >code that must be fixed. *sigh*
++ 
++ How can I tell what new -w errors are likely to be put into future
++ versions of perl.  I think that -w is an amazingly useful development
++ aid.  

What do you prefer? A warning, or your script silently going wrong?
Or worse, you upgrade now, don't get the warning, and in the next
upgrade, your script no longer compiles.

If it's critical your scripts remain working after an upgrade -

        DO NOT UPGRADE PERL WITHOUT TESTING!

In fact, don't upgrade anything without testing.

And it testing reveals potential problems, get the problems fixed before
upgrading Perl in your production environment. 

++ I try and make code -w and use strict clean in development and then take
++ -w off code in production.  One of the tests to try *before* upgrading
++ perl is to see if your code is still -w clean. 

I don't get it. You don't put -w in production code because you don't know
what warnings future versions of perl will emit. Yet you test whether
your scripts are still -w clean before upgrading Perl. If you do that
test, there's no reason not to have -w in production code, is there?

++ -w does uncover potential danger spots, but how to satisfy everyone in all
++ eventualities seems a difficult problem...



Abigail
-- 
perl -MNet::Dict -we '(Net::Dict -> new (server => "dict.org")\n-> define ("foldoc", "perl")) [0] -> print'


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

Date: Tue, 07 Jul 1998 20:15:12 -0700
From: Jan Krynicky <JKRY3025@comenius.ms.mff.cuni.cz>
Subject: Re: 5.004_69 win32 Glob problem
Message-Id: <35A2E440.49D@comenius.ms.mff.cuni.cz>

Matthew Morley wrote:
> 
> It seems to fail returning directory nodes using the following
> segment:
> 
>   foreach my  $node (<*/*/*/*-*>)

did you try?

	foreach my  $node (<*\\*\\*\\*-*>)

Remember that you are on Win32. If I remember correctly there is some
PerlGlob.exe
in the previous builds, so maybe you have to use backslashes as the
directory separators
with it.

I do not have ActivePerl installed so I cannot test, but maybe this
could help.

> Any ideas?  Thanks.
> --
>  Matthew Morley        m.morley@worldnet.att.net

HTH, Jenda


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

Date: 7 Jul 1998 19:04:44 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
Subject: Re: 5.004_69 win32 Glob problem
Message-Id: <6ntrgc$ijv$2@info.uah.edu>

In article <6ns1on$k6r@bgtnsc02.worldnet.att.net>,
	Matthew Morley <m.morley@NOSPAM.worldnet.att.net> writes:
: I heard somewhere that glob() is pretty inefficient so prehaps this
: is a blessing in disguise.

If you have a C compiler, you can build

    <URL:http://www.cs.uah.edu/~gbacon/perl/File-BSDGlob-0.94.tar.gz>

which also works on Win32.  In the standard distribution, there is a
module called File::DosGlob that also does globbing.

Greg
-- 
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF


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

Date: Tue, 07 Jul 1998 13:10:26 -0500
From: Mark Evan Jones <xmarkjones@mindless.com>
Subject: Re: Accessing shell variables in a perl script
Message-Id: <35A26492.C8272640@mindless.com>

Sean McAfee wrote:
> 
> In article <35A246CF.B7426CBF@mindless.com>,
> Mark Evan Jones  <xmarkjones@mindless.com> wrote:
> >We've got a handy little %ENV for accessing environment settings.  But
> >is there
> >any way to access the shell's own variables?
> 
> No.  Variables which are not exported are simply not available to child
> processes of the shell (eg, Perl).  You can either a) export the
> appropriate variables prior to running Perl, or b) pass the (expanded)
> variables as arguments to Perl.  If you don't know ahead of time which
> shell variables you need, and can't use either of the above methods (for
> whatever reason), it's probably time to rethink your approach.

Hm.  It's not exactly my approach.  I've been told to write something to
be
run within a shell script that makes use of a certain variable within
that
script.  Ah well, now I know to try and make them do this another way.


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

Date: Tue, 07 Jul 1998 15:37:52 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Accessing shell variables in a perl script
Message-Id: <fl_aggie-0707981537520001@aggie.coaps.fsu.edu>

In article <35A26492.C8272640@mindless.com>, Mark Evan Jones
<xmarkjones@mindless.com> wrote:

+ Hm.  It's not exactly my approach.  I've been told to write something to
+ be
+ run within a shell script that makes use of a certain variable within
+ that
+ script.  Ah well, now I know to try and make them do this another way.

Then send the shell variable into the perl script as a command line
arguement:

#!/bin/sh
blah='some value'

perl_program $blah

#etc

James


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

Date: Tue, 07 Jul 1998 14:22:50 -0500
From: Peter Ensch <pensch@dadd.ti.com>
Subject: Batch printing of html files
Message-Id: <35A2758A.2B944DC0@dadd.ti.com>


--------------F0E47FE311873DDC2B1FCFAD
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Does anyone know a way to batch print html files? We want to place a
Print Topic button on an html page that will print the page and all
pages related to it. Those pages could either be linked by being in the
same directory, or could be hard-coded into the 'calling' page.

Please reply by e-mail

Thanks, Peter

--
***********************************************
Peter Ensch,
pensch@dadd.ti.com    D-2183    (972) 480 2333
***********************************************



--------------F0E47FE311873DDC2B1FCFAD
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<HTML>
Does anyone know a way to batch print html files? We want to place a Print
Topic button on an html page that will print the page and all pages related
to it. Those pages could either be linked by being in the same directory,
or could be hard-coded into the 'calling' page.

<P>Please reply by e-mail

<P>Thanks, Peter
<PRE>--&nbsp;
***********************************************
Peter Ensch,
pensch@dadd.ti.com&nbsp;&nbsp;&nbsp; D-2183&nbsp;&nbsp;&nbsp; (972) 480 2333
***********************************************</PRE>
&nbsp;</HTML>

--------------F0E47FE311873DDC2B1FCFAD--



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

Date: 7 Jul 1998 19:44:27 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: Batch printing of html files
Message-Id: <6nttqr$5n4$1@news.NERO.NET>

Newsgroups deboursyfied.

In article <35A2758A.2B944DC0@dadd.ti.com>,
Peter Ensch  <pensch@dadd.ti.com> wrote:
>
>--------------F0E47FE311873DDC2B1FCFAD
>Content-Type: text/plain; charset=us-ascii
>Content-Transfer-Encoding: 7bit

Gack! Don't do this.

>Does anyone know a way to batch print html files? 

lpr *.html

foreach i (*.html)
	lpr $i
end

>We want to place a
>Print Topic button on an html page that will print the page and all
>pages related to it. Those pages could either be linked by being in the
>same directory, or could be hard-coded into the 'calling' page.

<FORM method=POST action="/cgi-bin/print.sh">
<INPUT TYPE=submit VALUE=Submit> 

And then in cgi-bin, print.sh contains:

lpr 'list of files to print when button is pushed'

>Does anyone know a way to batch print html files? We want to place a Print
>Topic button on an html page that will print the page and all pages related
>to it. Those pages could either be linked by being in the same directory,
>or could be hard-coded into the 'calling' page.

Asking twice in one article won't make it more likely you get an
answer.

Now, answer this: what relevance does this have to perl?



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

Date: 7 Jul 98 17:17:09 GMT
From: sitaram@diac.com (Sitaram Chamarty)
Subject: Re: better way of getting the last modified file?
Message-Id: <slrn6q1vnu.nms.sitaram@ltusitaram.diac.com>

On Sun, 5 Jul 1998 22:45:58 -0700, Larry Rosler <lr@hpl.hp.com> wrote:

>Can the application not intercept $SIG{'__DIE__'} and $SIG{'__WARN__'} 
>and send an appropriate message to its maintainer using sendmail (or an 

My approach is halfway between eliminating "-w" altogether (which
was the suggestion I initially responded to) and constantly having
to monitor all warnings.  It hinges on the user finding something
wrong (trust me - they will :-) and telling me.  At which time I
ask them to send me the log file called such-and-such in so-and-so
directory.

I certainly wouldn't want to be getting email for every warning my
scripts produce when the user sees nothing wrong :-)


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

Date: Tue, 7 Jul 1998 15:25:57 -0400
From: "Teflon" <indy@NOSPAMdemobuilder.com>
Subject: Re: Debug ?
Message-Id: <6nts3r$741$1@nntp2.uunet.ca>

Try commenting out most of your code until it works, then uncomment sections
until you get the error.  Then wittle it down to a single line.


Darren Sweeney wrote in message <6neodv$8lr$1@nnrp4.snfc21.pbi.net>...
>Hi
>
>I have a script which returns the '500 Internal error' message.
>
>What is the best way to debug...I have tried telnet perl -c/w but they both
>tell me the script is OK.
>
>All help appreciated.
>
>Regards,
>
>Darren
>
>




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

Date: Tue, 7 Jul 1998 15:25:57 -0400
From: "Teflon" <indy@NOSPAMdemobuilder.com>
Subject: Re: Debug ?
Message-Id: <6nts6n$74h$1@nntp2.uunet.ca>

Try commenting out most of your code until it works, then uncomment sections
until you get the error.  Then wittle it down to a single line.


Darren Sweeney wrote in message <6neodv$8lr$1@nnrp4.snfc21.pbi.net>...
>Hi
>
>I have a script which returns the '500 Internal error' message.
>
>What is the best way to debug...I have tried telnet perl -c/w but they both
>tell me the script is OK.
>
>All help appreciated.
>
>Regards,
>
>Darren
>
>




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

Date: Tue, 07 Jul 1998 19:21:02 GMT
From: coderkid@hotmail.com
Subject: Re: delete key from array
Message-Id: <6ntseu$unl$1@nnrp1.dejanews.com>

You can do splice (@array,1,1) This would delete $array[1], although I think
here you mean to delete $array[0], which is "hallo"...

The general syntax is
splice ARRAY, OFFSET, LENGTH, LIST
(where you can replace the spliced elements with LIST)...

In article <6nsqfq$bhf$1@nnrp1.dejanews.com>,
  dwiesel@my-dejanews.com wrote:
>
> Hi.
>
> I don't seem to find the (probably) simple answer...
>
> I have an array and want to delete a key from it
>
> @array = ("hallo", "hallo2");
>
> how do I delete $array[1] so that the arrays new look is ("hallo2") ???
>
> // Daniel
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum
>


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Tue, 07 Jul 1998 18:26:54 GMT
From: Scott.L.Erickson@HealthPartners.com (Scott Erickson)
Subject: Re: Globbing from a list
Message-Id: <35a26716.530651135@news.mr.net>

Previously, I wrote:

>Here is what I want to do: I want to apply a glob-like function to a
>list, not the current directory. I want the simplicity of basic
>filename expansion such that if I have a list of filenames, I can pull
>out only those that match a given pattern. I am trying to avoid using
>regular expressions as the pattern because this will be used by others
>who are weak with regards to regexs, but okay with filename expansion
>(i.e., *.jpg).

Well, I went to lunch and came back with a solution. My solution is
this:
convert the globbing pattern to a regex
grep the filenames from the list using the regex

To convert the globbing pattern to a regex, I iterate over every
character of the globbing pattern and convert it to the appropiate
regex thingy.

My code is as follows:

  # determine the length of the globbing pattern
  my $length = length $pattern;

  my ($index, $char);

  # wrap the regular expression in search delimiters
  my $regex = '/^';

  # loop over every char in the globbing pattern
  for ($index = 0; $index < $length; $index++) {

    # get a character from the pattern
    $char = substr $pattern, $index, 1;

    # if it is just an alphanumeric, then save it unchanged
    $regex .= $char if ($char =~ /\w/);

    # if it is a period (.), then escape it
    $regex .= '\.' if ($char =~ /\./);

    # if it is a asterisk (*), then replace it with a non-greedy match
anything
    $regex .= '.*?' if ($char =~ /\*/);

    # discard everything else

  } # end of for loop

  # finish wrapping the regular expression in search delimiters
  $regex .= '$/';

  # return the regex
  return $regex;

As can be seen, this code only allows for rather simple filename
globbing. I believe that it is sufficient for what I need, but I will
be meeting with my "customers" soon to better determine their needs.

If anyone as improvements to the code or alternative solutions, please
post them so that I and others may benefit from your ideas.

Scott.


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

Date: 7 Jul 1998 15:08:56 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: help I'm a beginner
Message-Id: <6ntro8$fll$1@monet.op.net>

In article <6nt6d4$sjt@tukki.cc.jyu.fi>,
Sami P. Poikonen <Sami.Poikonen@iki.fi> wrote:
>Well, how do I convert from string to number?

Wrong question.  You don't convert string to number in Perl.
If you use it in a numeric context, it's used like a number.

>I tried $num = 0 + $num, but it gives warning if I use -w switch
>and $num contains a string.

``Hi.  How do I drive my car over a bridge?  I tried doing it the
usual way, but there is a sign that says MAXIMUM BRIDGE LOAD: 28 TONS.''

The warning is advising you that you might be doing something wrong.
In this case, you know you're not doing anything wrong, so you should
ignore the warning.


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

Date: Tue, 7 Jul 1998 12:43:43 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: help I'm a beginner
Message-Id: <MPG.100c1a4e587b9cd49896ec@nntp.hpl.hp.com>

[This followup was posted to comp.lang.perl.misc and a copy was sent to 
the cited author.]

In article <6ntro8$fll$1@monet.op.net> on 7 Jul 1998 15:08:56 -0400, 
Mark-Jason Dominus <mjd@op.net> says...
> In article <6nt6d4$sjt@tukki.cc.jyu.fi>,
> Sami P. Poikonen <Sami.Poikonen@iki.fi> wrote:
 ...
> >I tried $num = 0 + $num, but it gives warning if I use -w switch
> >and $num contains a string.
> 
> ``Hi.  How do I drive my car over a bridge?  I tried doing it the
> usual way, but there is a sign that says MAXIMUM BRIDGE LOAD: 28 TONS.''
> 
> The warning is advising you that you might be doing something wrong.
> In this case, you know you're not doing anything wrong, so you should
> ignore the warning.

In the version of perl I use (5.004_03), the warning indicates that the 
conversion of $num from string to numeric was terminated by a character 
in the string that is neither part of a valid number nor white-space.  It  
probably should not be ignored.

If the submitter really wants to 'ignore' (suppress) the warning, he 
might try:

{ local $^W; $num += 0 }

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


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

Date: Tue, 07 Jul 1998 17:30:03 GMT
From: "Richard Robinson" <rar@rentrak.com>
Subject: Image::Magick and Global Color Table
Message-Id: <vWso1.6712$r73.5803649@news.teleport.com>

I have PerlMagick installed and it works just fine. I use it to create an
animated GIF of three frames. Only problem is that by default it seems to be
using a unique (or local) color table for each image.

I want to use a Global Color Table for all images. Any idea how I do this?

Reason I want to do this is size. The resultant animated GIF size is too
large by about 3 times. I can take each frame and create an animated GIF in
Adobe Photoshop with a Web color pallette that has a resultant size of 1/3.
Can't I do the same, programmatically, with Image::Magick?

Please email me as well as post to newsgroup. Thank you,

-- Richard Robinson
rar@rentrak.com






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

Date: Tue, 07 Jul 1998 15:35:00 -0400
From: John Chambers <jc@ral1.zko.dec.com>
Subject: Re: Is Perl through CGI enough for this?
Message-Id: <35A27864.58007172@ral1.zko.dec.com>

David Rouse wrote:
> 
> In article <359D8A4A.A997DB4F@fccj.org>, sneex@fccj.org wrote:
> 
> > Not wanting to state the obvious, but Perl is ONLY as good as your best
> >programmer.
> >
> 
> Thanks to all those who replied to my question. To make a long story
> short, all those who replied seemed to think that Perl is more than up to
> the task of a web based front end for a ads manifesting database.
> 
> So now I'm back to "Learning Perl" and lurking ...

While you're at it, checkout the comp.infosystems.www.* newsgroups, and
lurk there a while.  One of the things you'll soon discover:  You'll have
lots of questions along the lines of "How do I do <some CGI task> in perl?"
If you ask in the perl newsgroup, they'll tell you to to to the CGI group,
while the folks over in the CGI newsgroup will tell you to ask here because
it's a perl question.  It's called "the old runaround."  It's a little game
we play with newbies.  

Oh, and go look around in http://www.cpan.org/ a bit.  They have lots of
things that will help you with your job.  You can tell right off that it's
a site for serious productivity, by the lack of any flashy graphics.  You
want the CGI module and the libwww "bundle" for starters.  Or maybe you
just want the CGI_Lite module.


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

Date: 7 Jul 1998 18:29:02 GMT
From: curry@convex.hp.com (Curry Taylor)
Subject: Literal string evaluation question
Message-Id: <6ntpde$8lt$1@news.rsn.hp.com>


        I've got several variables defined which are similar to these:

$one = "(\S+)\s+(\S+)";
$two = "\s+(\S+)";
$three = "(\S+)";
 .
 .
 .

        They're just a bunch of pattern matching strings. Now, I'm wondering if there is a way to have the interpreter take these expressions and use them for pattern matching at run-time. Sort of like have it interpolate the string before using it. So instead of this:

        /$one/

        ..which would try to match the literal string "(\S+)\s+(\S+)", it would look appropriately for the non-WS, WS, non-WS pattern. Is there some interpolate function, something along the lines of this:

        /interpolate($one)/

        I thought of using eval to do this, but I don't think it could work exactly like I want it. Thanks for any help!

Curry



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

Date: 7 Jul 1998 15:02:09 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Literal string evaluation question
Message-Id: <6ntrbh$fj2$1@monet.op.net>


In article <6ntpde$8lt$1@news.rsn.hp.com>,
Curry Taylor <curry@convex.hp.com> wrote:
>$one = "(\S+)\s+(\S+)";
> instead of this...
>        /$one/
>
>        ..which would try to match the literal string
> "(\S+)\s+(\S+)",

It doesn't do that.

> it would look appropriately for the non-WS, WS, non-WS pattern.

That is what it does do.

It is already exactly the way you want.

Your problem is that \ is special in "double-quoted strings", so the
result is that $one doesn't contain what you think; instead it
contains

	(S+)s+(S+)

Try this:

	$one = "(\\S+)\\s+(\\S+)";

or

	$one = '(\S+)\s+(\S+)';



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

Date: Tue, 07 Jul 1998 12:04:09 -0700
From: Ramesh Nagarajan <ran@sgi.com>
Subject: locking in perl
Message-Id: <35A27129.DD0DCE2C@sgi.com>

Hi,
Does anyone know how to lock a part of a file?? I came across flock()
which locks the whole file but not a small chunk of code.

Thanks much in advance.

Ramesh



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

Date: 7 Jul 1998 19:31:42 GMT
From: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: Re: locking in perl
Message-Id: <6ntt2u$1i5@mozo.cc.purdue.edu>

Ramesh Nagarajan <ran@sgi.com> writes:

}Hi,
}Does anyone know how to lock a part of a file?? I came across flock()
}which locks the whole file but not a small chunk of code.

Assuming you're using Unix, the answer might be to use fcntl.  Read
the man pages, and I'd also suggest getting "Advanced Programming in
the UNIX environment" by Stevens which describes the usage.  The perl
function is little more than a wrapper to the underlying C call.
It's tricky to get it working, and it's far too ugly for this day and
age, but them's the breaks.

-- 
Mike Gebis  gebis@ecn.purdue.edu  mgebis@eternal.net


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

Date: Tue, 7 Jul 1998 15:22:27 -0400
From: "Teflon" <indy@NOSPAMdemobuilder.com>
Subject: Re: newbie q: populating array with interpolated scalar?
Message-Id: <6ntrt9$72v$1@nntp2.uunet.ca>

use

%names = split(",", $values);



Sweth Chandramouli wrote in message ...
>   i've got a perl script that ends up with a scalar ($values) that
>consists of a series of comma-separated values.  i want to use this to
>populate an associative array (%names), so that if $values contained
>"one,bob,two,joe,three,fred", %names would contain the three pairs
>(one,bob), (two,joe), and (three,fred).
>   i would assume, from the examples in the camel and llama books, that
>"%names = ($values)" would work, but it doesn't--it treats $values as one
>item, rather than six comma-separated items.
>   what am i missing here?
>
>   tia,
>   sweth.
>
>--
>Sweth Chandramouli
>IS Coordinator, The George Washington University
><sweth@gwu.edu> / (202) 994 - 8521 (V) / (202) 994 - 0458 (F)
><a href="http://astaroth.nit.gwu.edu/~sweth/disc.html">*</a>




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

Date: Tue, 07 Jul 1998 15:51:12 -0400
From: John Chambers <jc@ral1.zko.dec.com>
Subject: Re: Oh man, DO I love Perl ! (References to things that go out of scope)
Message-Id: <35A27C30.BD7A6242@ral1.zko.dec.com>

Dan Schmidt wrote:
> 
> John Chambers <jc@ral1.zko.dec.com> writes:
> 
> | The opaqueness of most of the OO documentation ("preaching to the
> | converted" comes to mind) is also a major culprit.  You can only
> | understand most of it if you already know all the rest.  Learning
> | how to use it requires a lot of dedication, with no obvious payoff
> | (other than becoming part of the OO in-crowd and being able to put
> | it on your resume ;-).  So it gets put off until there's spare time
> | to delve into the mysteries.
> 
> I also had a hard time with the OO documentation in the camel book,
> and I'm used to OO programming!

Yah.  I've on occasion used this chapter as a case-in-point for the
common problem of much OO documentation.  The camel book is generally
a very well-written and informative book.  It is clearly aimed at the
"experienced programmer", but for such people, picking up the language
is very easy by just reading the book.  Except.  Try reading the OO
chapter from the viewpoint of someone who doesn't know OO terminology.
It's utterly hopeless.  There's no way an OO novice (even an otherwise
expert programmer) can learn much of anything from this chapter.  It's
full of undefined terms that can't be found in the index.  It has few
examples, and they aren't complete.  And it has the tone of a tract, 
not a text.

This is very unfortunate, because it does a lot to scare off people who
could otherwise profit greatly from perl's OO stuff. And it's also right
in line with most of the other OO documentation that you'll run across,
overly preachy and underly informative.  "Jeez; if it's that complicated,
maybe I should just skip over it and get on with something that I can
understand."

In the next edition, they might do well to radically abbreviate this
chapter, and just refer people to the "Advanced" book.  Better to be
vague than to pretend to be instructional in a way that alienates most
of your prospective users.  Maybe a brief intro to the major points,
a few (complete) examples of some small but useful OO modules, and
"To learn more about OO programming in perl, see ..."


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

Date: 7 Jul 1998 18:01:00 GMT
From: hbamford@marconi.ih.lucent.com (Harold Bamford)
Subject: Re: open2 problems
Message-Id: <6ntnos$7cl@ssbunews.ih.lucent.com>

In article <6ntg3d$s6i$2@csnews.cs.colorado.edu>,
Tom Christiansen  <tchrist@mox.perl.com> wrote:

>In comp.lang.perl.misc, hbamford@lucent.com writes:
>>Perhaps a full working example of open2
>>and open3 should be put in the documentation.

>You mean the one in perlipc, which I just tested and which works?
>	use IPC::Open2;
>	$pid = open2( \*Reader, \*Writer, "cat -u -n" );
>	print Writer "stuff\n";
>	$got = <Reader>;
>	print "Got $got\n";

Works for you, but not me.  It just hangs there.  It may be a bug in
perl5 or (more likely) a mis-compilation of the binary.

And to answer the inevitable:

Output of perl -v:
	This is perl, version 5.004_03
	
	Copyright 1987-1997, Larry Wall
	
	Perl may be copied only under the terms of either the Artistic License or the
	GNU General Public License, which may be found in the Perl 5.0 source kit.

Output of perl -V:	
	Summary of my perl5 (5.0 patchlevel 4 subversion 3) configuration:
	  Platform:
	    osname=solaris, osvers=2.5.1, archname=sun4-solaris
	    uname='sunos nwsgpb 5.5.1 generic_103640-08 sun4u sparc sunw,ultra-2 '
	    hint=recommended, useposix=true, d_sigaction=define
	    bincompat3=y useperlio=undef d_sfio=undef
	  Compiler:
	    cc='cc', optimize='-O', gccversion=
	    cppflags='-I/opt/gnu/include'
	    ccflags ='-I/opt/gnu/include'
	    stdchar='unsigned char', d_stdstdio=define, usevfork=false
	    voidflags=15, castflags=0, d_casti32=define, d_castneg=define
	    intsize=4, alignbytes=8, usemymalloc=y, randbits=15
	  Linker and Libraries:
	    ld='cc', ldflags =' -L/opt/local/lib -L/opt/gnu/lib'
	    libpth=/opt/local/lib /opt/gnu/lib /lib /usr/lib /usr/ccs/lib
	    libs=-lsocket -lnsl -ldl -lm -lc -lcrypt
	    libc=/lib/libc.so, so=so
	    useshrplib=false, libperl=libperl.a
	  Dynamic Linking:
	    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
	    cccdlflags='-Kpic', lddlflags='-G -L/opt/local/lib -L/opt/gnu/lib'

	Characteristics of this binary (from libperl): 
	  Built under solaris
	  Compiled at Aug 28 1997 23:02:33
	  @INC:
	    /opt/nwstools/lib/perl5/sun4-solaris/5.00403
	    /opt/nwstools/lib/perl5
	    /opt/nwstools/lib/perl5/site_perl/sun4-solaris
	    /opt/nwstools/lib/perl5/site_perl
	    /opt/nwstools/lib/perl5/sun4-solaris
	    .
-- 
-- Harold Bamford
   mailto:hbamford@lucent.com
   (630)713-1351


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

Date: 7 Jul 1998 19:09:56 GMT
From: "Chris Crook" <chris@zucchini.linz.govt.nz>
Subject: Out of memory in sort
Message-Id: <01bda9da$b978ac60$45144290@pcxtmcc.linz.govt.nz>

Hi All

I am sorting a file of about 5 Mb size consisting of about 150000 approx 30
character records.  My first approach was to read the file into an array,
sort it, and write it out, ie

   open(F,'myfile');
   @data = <F>;
   close(F);

   @data = sort @data;

   open(F,'>myfile');
   print F @data;
   close(F);

This failed with an "Out of Memory error" when running on an Intel Pentium
machine with 80Mb RAM.  I tried both ActiveState 3.16 perl under Win 95 and
perl 5.004_? under linux with the same result (so it is probably a
consequence of perl memory management rather than OS memory management?) 

I have been able to get around this using

   # read file as before
   
   my @lineno = (0..$#data);
   @lineno = sort {$data[$a] cmp $data[$b]} @lineno;

   open(F,'>myfile');
   print F @data[@lineno];
   close(F);

But I am really curious as to why this works, and I'd be interested in
guesses as to
how big the data file could be in this scenario before it bombs out.

Thanks in advance for any suggestions

Chris Crook


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

Date: Tue, 7 Jul 1998 13:57:39 -0500
From: "Howard Dierking" <howard@vortexweb.com>
Subject: print multiline strings
Message-Id: <#7IVxgdq9GA.210@upnetnews05>

I'm using something like *print <<Lots_of_HTML* to print HTML with tables
and forms and all that--however, I wasn't really planning on using all of
the associated CGI.pm functions.  I was just going to try and print.  Now, I
know that I need to \" all of the quotes.  However, am I going to need to do
that for all "=", " &", ";"  -- I keep getting an error saying that it can't
find the *Lots_of_HTML* before EOF.  Thanks

howard




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

Date: 7 Jul 1998 14:53:33 -0500
From: tye@fohnix.metronet.com (Tye McQueen)
Subject: Re: question about objects
Message-Id: <6ntubt$a5g@fohnix.metronet.com>

) In comp.lang.perl.misc, 
)     charlie @antipope.org writes:
) :I dislike reliance on idiom; the implicit use of $_ and @_ in
) :particular. Yeah, they're handy -- but it's a royal pain in the ass
) :when you have to hand over code to someone who, in the phrase of
) :someone I had to deliver to, "has not yet been assimilated by the perl
) :hive mind".

Tom Christiansen <tchrist@mox.perl.com> writes:
) You are going to have to invent a better excuse than this.
) You don't have someone maintain your code who doesn't know
) the language.  That's like telling a C programming not to 
) use pointers, or a scheme programmer not to use closures,
) for fear that an untrained reader would be confused.  

Some people seem to think that programming Perl is like
programming DOS *.bat files.  They even want to set company policy
to prevent people from using confusing features of Perl that are
"of limited value", like qw(), ha!  Then they run off and make
extensive use of C<do> and write

    {  $XyZzY= $^W;  $^W= 0;  $arg= $ARGV[0];  $^W= $XyZzY;  }

to avoid the "uninitialized value" warning when no command-line
arguments are given.  It is a frustrating mindset.

Some of the same friendly aspects of Perl that allow non-programmers
to write web pages with it also allow programmers to use it without
bothering to learn it or even appreciate it.

So I can see where you run into places where they expect code to
be maintained by people who don't know the language.  It sucks and
shouldn't happen but I'm sure it happens all too often.  Fight it
when you can.

But as for writing

    while(<INPUT>) {
	print $_;
    }

I agree.  Defaulting $_ and @_ (or @ARGV, depending on context) is
most useful for writing extra-compact one-liners and save only 3
characters in non-trivial code while making the code less clear
and more error prone.

As a few examples,

    $val= shift;

will silently change meaning depending on where it is.


Changing where to want to print to in our first example can break
if we left off the implied C<$_>:

    my( $outfile )= @_;
    while(<INPUT>) {
	print $outfile $_;
    }

vs.

    my( $outfile )= @_;
    while(<INPUT>) {
	print $outfile;
    }

Perhaps worst of all is when you switch some code from C<$_> to
C<$line> because the code has become more complicated and now you
have to carefully read every single bit of code searching for the
hidden assumed C<$_>.  It would be really nice to have a specific
warning that you could turn on [not part of B<-w> nor C<use strict>
but perhaps something like C<use strict "implied">] that would
tell you when you've implied an argument so you could make code
maximally maintainable or just temporarilly turn it on to look
for spots where C<$_> was assumed because you decided to change
variable names.  No, I'm not offering a patch at the moment -- my
plate is full.  Perhaps someone else will be inspired.

But

    while( <INPUT> )
vs
    while(  defined( $_= <INPUT> )  )

is more of a win, especially if you want to do a lot of regular
expression processing of the input, but I'll still avoid it unless
the loop is small enough to be taken in with a single glance.
-- 
Tye McQueen    Nothing is obvious unless you are overlooking something
         http://www.metronet.com/~tye/ (scripts, links, nothing fancy)


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

Date: 7 Jul 98 17:17:10 GMT
From: sitaram@diac.com (Sitaram Chamarty)
Subject: Re: regexp s/// for removing tail end of string
Message-Id: <slrn6q4th1.1gh.sitaram@ltusitaram.diac.com>

On Sun, 5 Jul 1998 16:35:34 -0500, Jerry <jerry@fitzweb.com> wrote:

>I have a string that is a full path to a file, i.e.
>dir/subdir/subsubdir/file.ext  What I want to do is strip off the file name,
>leaving just the path info (with the final / ) in a string.  The paths will
>have a varying number of directories, so I don't think I can use split to
>just grab all the dirs, throw out the last one, and join the remainder
>together. (If this is the way to go, please show me I can't see it).
>
>I tried substitution, using this:
>$path =~ s/\/.*?$//;

I saw all the other responses to this question, and am wondering
if I'm losing my mind...?

    s/[^\/]+$//

works fine for me.  Am I missing something here?  Is this not what
was wanted?

Using rindex would work too:

    $_ = substr($_,0,rindex($_,"/")+1)

Neither of these will work if you do not have a single slash in
your input, but it doesnt seem like that's a problem for you.


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

Date: 7 Jul 1998 20:27:10 +0100
From: kh052@cks1.rz.uni-rostock.de (Kajetan Hinner)
Subject: serious bug in Time::Local?
Message-Id: <35a2687e.0@news.uni-rostock.de>


Hello.

Try the following:

use Time::Local;

my $time1;
my $time2;
my $time3;

$time1=timelocal(0,0,5,31,3,1998);
$time2=timelocal(0,0,5,1,4,1998);
$time3=timelocal(0,0,0,1,4,1998);

print ("$time1, $time2, $time3 \n");   

---------


we get:

893991600, 893991600, 893973600 

-----------

am i wrong? i think there's no difference between 31/3 and 1/4.

please answer also via mail

Kajetan Hinner



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

Date: Tue, 07 Jul 1998 21:10:00 -0700
From: Jan Krynicky <JKRY3025@comenius.ms.mff.cuni.cz>
Subject: Re: setting @INC in (ActiveState) Perl 5 for Win32
Message-Id: <35A2F117.77CD@comenius.ms.mff.cuni.cz>

Rik Blok wrote:
> 
> Can somebody tell me where I can set the @INC variable under
> ActiveState's Perl?  I want to set up a default library folder where I
> can put all my commonly "required" scripts.
> 
> I've looked in the registry but didn't see anything there.  Maybe in
> autoexec.bat?  Please help...
> 
> TIA, Rik.
> 

TIMTOWDI

1. system variable PERL5LIB - add as many directories you want,
separated by a semicolon

2. HKEY_LOCAL_MACHINE\SOFTWARE\ActiveWare\Perl5
    PRIVLIB
    SITELIB
   again as many directories you want, separated by a semicolon.
   <directory where you installed perl>\lib should be the last one in
PRIVLIB

If you have installed the version present in the Resource Kit, look
somewhere under
 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Resource Kit or maybe it was
 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Resource
Kit
or something like than.

You'd better upgrade though.

3. In the code :

	use lib 'c:\perl\mylib';

   or

	BEGIN { # you HAVE to use the BEGIN{} block !
	 push @INC, 'c:\perl\mylib';
	}

HTH, Jenda


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

Date: Tue, 07 Jul 1998 21:15:59 -0700
From: Jan Krynicky <JKRY3025@comenius.ms.mff.cuni.cz>
Subject: Re: SQL and apostrophe
Message-Id: <35A2F27F.2E90@comenius.ms.mff.cuni.cz>

pc01 wrote:
> 
> Hi to everybody,
> 
> I'm using the Perl module Win32::ODBC on an NT 4 server to update an MS
> Access 97 database from Web. When one field of the record inserted
> contains an apostrophe I get an "SQL failed" Error, so I should find a
> method to get harmless this apostrophe and  to insert it in the database
> all the same.
> Any suggestion?
> Thank you for your attention.
> 
> Massimo Seren - Euganea Telematic@

You have to double your apostrophes.

Either do something like

	$var =~ s/'/''/gm;
	$db->Sql("SELECT * FROM Table WHERE Name = '$var'");

or

	use Interpolation "'" => sub {$_=$_[0]; s/'/''/;"'".$_};
	 # http://www.plover.com/~mjd/perl/Interpolation/
	$db->Sql("SELECT * FROM Table WHERE Name = $'{$var}'");

The second solution leaves your variables intact!

HTH, Jenda


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

Date: Tue, 7 Jul 1998 16:42:25 -0400
From: Darren K Emge <emge@insulae.neurology.umab.edu>
Subject: syscall
Message-Id: <Pine.SGI.3.91.980707164028.11218A-100000@insulae.neurology.umab.edu>


Hello,

I am trying to write a scipt to go through and perform some file 
maintenance.  I am trying to use syscall but it does not appear to work.  
Here are some snippets from my scripts

require 'sys/syscall.ph';

$SYS_zip = "gzip -r";

syscall $SYS_zip, $DIR;


Any suggestions



Thanks

Darren



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

Date: Tue, 7 Jul 1998 15:16:01 -0400
From: "Teflon" <indy@NOSPAMdemobuilder.com>
Subject: Re: why won't my compare work
Message-Id: <6ntrj6$6vh$1@nntp2.uunet.ca>

The problem is that you need to chop($reg_key) after you read it if you want
a match.  Otherwise it contains a trailing "\n".

You should also break out of the while loop with a "last;" when you get a
match.




Howard Dierking wrote in message ...
>I am reading from a an outside file which contains a list of identifiers
and
>locations
>
>(example)
>beta
>http://www.url.com/file.html
>
>I haven't had a problem opening the file (at least I'm not getting an
>error), but no matter what, my $redirect_loc variable always ends up being
>the "wrong_id.html" string.  The code is posted below.  Any reason why?
>Thanks.
>
>howard
>
>-------------------
>#!/usr/bin/perl -w
>#
># validateid.pl
>$redirect_loc = "http://www.eventresponse.com/wrong_id.html";  #initialize
>variables
>print "Please enter the file handle: ";
>$reg_key = <STDIN>;
>open (LIST, "list.dat");      # open the data file
>while (defined ($line = <LIST>)){
>  chomp ($line);
>  if ($line eq $reg_key){
>    $line = <LIST>;
>    chomp ($line);
>    $redirect_loc = $line;
>  }
>  else{
>    $line = <LIST>;
>    chomp($line);
>  }
>}
>close (LIST);
>print "the address will be: $redirect_loc\n";
>
>




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

Date: Tue, 7 Jul 1998 15:16:01 -0400
From: "Teflon" <indy@NOSPAMdemobuilder.com>
Subject: Re: why won't my compare work
Message-Id: <6ntrm9$6vp$1@nntp2.uunet.ca>

The problem is that you need to chop($reg_key) after you read it if you want
a match.  Otherwise it contains a trailing "\n".

You should also break out of the while loop with a "last;" when you get a
match.




Howard Dierking wrote in message ...
>I am reading from a an outside file which contains a list of identifiers
and
>locations
>
>(example)
>beta
>http://www.url.com/file.html
>
>I haven't had a problem opening the file (at least I'm not getting an
>error), but no matter what, my $redirect_loc variable always ends up being
>the "wrong_id.html" string.  The code is posted below.  Any reason why?
>Thanks.
>
>howard
>
>-------------------
>#!/usr/bin/perl -w
>#
># validateid.pl
>$redirect_loc = "http://www.eventresponse.com/wrong_id.html";  #initialize
>variables
>print "Please enter the file handle: ";
>$reg_key = <STDIN>;
>open (LIST, "list.dat");      # open the data file
>while (defined ($line = <LIST>)){
>  chomp ($line);
>  if ($line eq $reg_key){
>    $line = <LIST>;
>    chomp ($line);
>    $redirect_loc = $line;
>  }
>  else{
>    $line = <LIST>;
>    chomp($line);
>  }
>}
>close (LIST);
>print "the address will be: $redirect_loc\n";
>
>




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

Date: Tue, 07 Jul 1998 11:03:44 -0700
From: josri <josri@postoffice.pacbell.net>
Subject: Win32::Internet
Message-Id: <35A26300.6E525781@postoffice.pacbell.net>

Hi,
I tried FetchURL() with the Internet module. But now, I want the file to
be uploaded to the same URL. How can I do that with perl and not using
HTML?
Thanks for any help

Regards
Josri




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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.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 3084
**************************************

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