[10808] in Perl-Users-Digest
Perl-Users Digest, Issue: 4409 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 12 12:07:18 1998
Date: Sat, 12 Dec 98 09:00:20 -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 Sat, 12 Dec 1998 Volume: 8 Number: 4409
Today's topics:
Re: 3 perl cgi questions... (Clay Irving)
=?iso-8859-1?Q?s:_script_f=FCr_newsheader_Auswahl?= <NFilus@gmx.net>
Re: a simple puzzle (I suspect) <ddvddv@earthlink.net>
Re: a simple puzzle (I suspect) (Ronald J Kimball)
Re: Apache <-> Informix <-> Perl <gellyfish@btinternet.com>
array initialisation <michaelr@lndn.tensor.pgs.com>
Re: Beginner Book? <gellyfish@btinternet.com>
Re: CGI.pm vs. old way I'm used to? (Ronald J Kimball)
Copying files in Perl <crewsys@nbnet.nb.ca>
Re: Diagnostic Scrolls by <r_larsen@image.dk>
Re: Fastest way to search through an array? (Stefan Scholl)
Re: Functions in a template file. (Bart Lateur)
Re: how check string whether numeric value? <r_larsen@image.dk>
Re: how to get screen size? <gellyfish@btinternet.com>
Re: ls -l in perl? (Ronald J Kimball)
Re: LWP problem/question (Ronald J Kimball)
Re: Perl and Zip (Clay Irving)
Re: Perl Modules, DOCS? <gellyfish@btinternet.com>
Re: Splitting a string at a certain point (David Alan Black)
Re: Splitting a string at a certain point (Bart Lateur)
Re: Splitting a string at a certain point <rick.delaney@home.com>
Re: Splitting a string at a certain point <Allan@Due.net>
Re: typeglob (*) VS (\%) direct pass-by-ref <chrisre@ecpi.com>
Why Is Perl not a Language? (Thomas Brian Holdren)
won't execute exec(...); <WeAreUs@Ibm.net>
Re: won't execute exec(...); <Allan@Due.net>
Re: y2k and killing creativity (was Re: Y2K potential p <Russell_Schulz@locutus.ofB.ORG>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 12 Dec 1998 11:05:49 -0500
From: clay@panix.com (Clay Irving)
Subject: Re: 3 perl cgi questions...
Message-Id: <74u48t$okb@panix.com>
In <74rti9$94n$1@usenet01.srv.cis.pitt.edu> "mark reed" <marst96@pitt.edu> writes:
>>2) Is it possible to check the dimensions of an image
>>file (width x height)?
>depends on file type, you can search for documentation on gif and jpg files,
>and it will tell you where in the
>file the width and height are saved, and then you can load in the file, and
>look at the width and height, (they will robably be near the beginning of
>the file) But i have never loaded in binary files with perl, so cant tell ya
>how to grab the correct bytes let alone put them together, as they are
>probably stored as 16bits or 32. someone else might :)
Then again... Perl Modules are your friend.
Image::Size
http://www.perl.com/CPAN/modules/by-module/Image
Image::Size is a library based on the image-sizing code in the
wwwimagesize script, a tool that analyzes HTML files and adds
HEIGHT and WIDTH tags to IMG directives. Image::Size has
generalized that code to return a raw (X, Y) pair, and included
wrappers to pre-format that output into either HTML or a set of
attribute pairs suitable for the CGI.pm library by Lincoln Stein.
Currently, Image::Size can size images in XPM, XBM, GIF, JPEG,
TIFF, PNG and the PPM family of formats (PPM/PGM/PBM).
--
Clay Irving
clay@panix.com
------------------------------
Date: Sat, 12 Dec 1998 15:35:50 +0100
From: "Nikolaus Filus" <NFilus@gmx.net>
Subject: =?iso-8859-1?Q?s:_script_f=FCr_newsheader_Auswahl?=
Message-Id: <74tvkd$bm3$3@carp.emsnet.de>
Hi,
I heard about a script for ignoring 'newbie' postings in USENET. Where can
I get it ?
Thanx.
Nikolaus
------------------------------
Date: Sat, 12 Dec 1998 06:20:15 -0800
From: Dan DeVries <ddvddv@earthlink.net>
Subject: Re: a simple puzzle (I suspect)
Message-Id: <36727B9F.2BFCE49B@earthlink.net>
I do appreciate it. Too simple. It was late, and I was stuck, but as
usual with perl, I was making it much too hard.
Dan.
(feeling stupid...)
Uri Guttman wrote:
> >>>>> "DD" == Dan DeVries <ddvddv@earthlink.net> writes:
>
> BTW comp.lang.perl is no longer a real group. i dropped it from the
> followups
>
> DD> I need to downcase a string that WILL be quoted by () and MAY be
> DD> quoted by "" if it follows a particular string. For example, if
> DD> that string is CELL:
>
> DD> CELL(XYZ) => CELL(xyz)
> DD> CELL("XYZ") => CELL("xyz")
>
> i would normally first ask you for what code you have tried and failed
> but i am feeling generous tonight.
>
> this works fine. it doesn't check for the "" at all. it uses the
> required () to find the upper case string. if the prefix is fixed you
> can use it instead of $pre in both parts.
>
> s/$pre\((.+?)\)/$pre(\L$1)/;
>
> 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: Sat, 12 Dec 1998 10:43:51 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: a simple puzzle (I suspect)
Message-Id: <1djx59m.1l1en4812dhanoN@bay1-104.quincy.ziplink.net>
Uri Guttman <uri@sysarch.com> wrote:
> this works fine. it doesn't check for the "" at all. it uses the
> required () to find the upper case string. if the prefix is fixed you
> can use it instead of $pre in both parts.
>
> s/$pre\((.+?)\)/$pre(\L$1)/;
Change that to:
s/$pre\((.*?)\)/$pre(\L$1)/;
In case the parentheses following $pre are empty.
--
_ / ' _ / - aka - rjk@linguist.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: 12 Dec 1998 14:07:06 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Apache <-> Informix <-> Perl
Message-Id: <74ttaa$q2$1@gellyfish.btinternet.com>
In comp.lang.perl.misc Dirk Schumacher <Dirk.Schumacher@depot147.dpd.de> wrote:
> Hi
> i have some problem:
>
> I have a Linux-Server 5.3 with Apache 1.3.0 and Informix working.
>
> I have a perlscript witch contact to the database corectly from the
> Shell, but when i start the Script from my Browser an error occurded.
> (Look at the End of the text)
>
> I have installed this perl-Scripts:
>
> Storable-0.6@3
> pRPC-modules-0.1005
> DBI-1_02
> DBD-Informix-0.58
>
> 2. problem:
>
> On Linux 5.2 i have set variables in file httpd.conf with "SetEnv DBPATH
> /u/informix" ....
>
> But on 5.3 it goes wrong with this error:
>
> Invalid command 'SetEnv', perhaps mis-spelled or defined by a module not
> included in the server configurationd
>
> How can i set variables under 5.3 in the httpd.conf
This is not really a Perl or Informix question but one about the configuration
of the Apache server.
However I seem to recall that it is something to do with the Apache mod_env
it is probable that the precompiled version of Apache with your system has
omitted this module - you can include it by recompiling Apache with the
appropriate configuration.
I cant seen any reason though that you shouldnt do
$ENV{'DBPATH'} = $ENV{'DBPATH'} . ":/path/to/database";
in your program although I havent got Informix on this machine so I cant
test it out.
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Fri, 11 Dec 1998 11:34:38 +0000
From: Michael Renshaw <michaelr@lndn.tensor.pgs.com>
Subject: array initialisation
Message-Id: <3671034E.18E6@lndn.tensor.pgs.com>
does anyone know how to preallocate an array size within a hash array ?
i tried doing this:
$#array{$key} = 100; didnt like it
but this was OK:
$#array = 100;
any ideas on how to get around this one ?
cheers
Mike
------------------------------
Date: 12 Dec 1998 14:37:33 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Beginner Book?
Message-Id: <74tv3d$q6$1@gellyfish.btinternet.com>
On Sat, 12 Dec 1998 06:15:09 GMT gwynne@utkux.utk.edu wrote:
> In article <rdm-1711980047340001@140.174.42.30>,
> rdm@cfcl.com (Rich Morin) wrote:
>> In article <36512724.396404058@news.online.no>, tore@forumnett.no wrote:
>>
>> > On Mon, 16 Nov 1998 19:12:10 GMT, jeff.kennedy@natdecsys.com (Jeff
>> > Kennedy) wrote:
>> > > I need a book geared to an ABSOLUTE BEGINNER! No perl experience, no
>> > > programming experience, no real shell scripting experience.
>> >
>> > "Learning Perl, 2nd Edition" should work out just fine. When
>> > finished reading it, proceed with "Programming Perl, 2nd Edition".
>>
>> "Learning Perl" is a bit ungentle for a real beginner. Although it's
>> geared towards MacPerl, you might try "MacPerl: Power and Ease". An
>> HTML copy is available at http://www.ptf.com/macperl/ptf_book/HTML/
>>
>
> MacPerl:Power and Ease does not have enough exercises and is not basic
> enough. I suggest Perl 5 Interactive Course by Jon Orwant. It is basic and
> has many exercises. Learning Perl is aimed at people who already know C,
> Python, etc. I also suggest that you try C How to Program or C++ How to
> Program by Deitel and Deitel. They are college-type texts and have many
> exercises. One cannot learn a computer language well without working with the
> language--in this case: completing many exercises and altering and
> experimenting with them. Knowledge of C should be a prerequisite to learning
> Perl. Only then would Learning Perl or MacPerl: Power and Ease be useful.
>
Whilst it may be true that many of those who write in Perl do have a
background in C it is equally true that many have used Lisp, COBOL, BASIC or
whatever or indeed it might be that it is their first programming language
(I agree however that Perl is perhaps not an ideal first language). At
present I am passing on some of my Perl knowledge to colleagues who are
largely COBOL programmers and I dont see that as a real hindrance. Where
some C experience does help is when using the Perl functions that are
modelled on their C library equivalents such as the socket functions and
the four argument select (to name but a few).
I think it would be a shame to preclude people from learning Perl for the
lack of C in their language repertoire - and possibly embracing a variety
of backgrounds brings a richness to the Perl community that otherwise
would be lacking.
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Sat, 12 Dec 1998 10:43:56 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: CGI.pm vs. old way I'm used to?
Message-Id: <1djx5e8.1u9luq010d2txcN@bay1-104.quincy.ziplink.net>
Dave Stephens <stepherd@gusun.georgetown.edu> wrote:
> $value =~ s/<!--(.|\n)*-->//g;
Definitely not the best way to remove comments.
If you don't need to save a subexpression, use non-capturing
parentheses:
s/<!--(?:.|\n)*-->//g;
If you want . to match \n, use /s:
s/<!--.*-->//gs;
If you don't want to match from the first <!-- to the last --> (and you
don't; test your regex with "text 1 <!-- comment --> text 2 <!-- comment
--> text 3") use non-greedy matching:
s/<!--.*?-->//gs;
If you want to match real comments, according to the HTML spec... There
can be whitespace after the final --. <! > can contain multiple comment
parts, each one delimited by -- (as in <!-- comment -- -- comment -- >).
Do you really have comments in your form submission values, anyway? :-)
--
_ / ' _ / - aka - rjk@linguist.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: Sat, 12 Dec 1998 12:05:12 -0400
From: "Bryan Duchesne" <crewsys@nbnet.nb.ca>
Subject: Copying files in Perl
Message-Id: <74u46f$76e$1@smtp2.nbnet.nb.ca>
I want to be able to read a file on a local PC and copy a specified file to
a web directory. The program would be run from a web site with the local
file name entered in a TEXT box on a form.
Can this be done and if so, how do I reference the local PC file in the Perl
program? Do I use forward or back slashes in the file path. (I assume it
has to be / ) ?
Any help would be appreciated (Email preferred).
Bryan
------------------------------
Date: Sat, 12 Dec 1998 15:45:20 +0100
From: R. A. Larsen <r_larsen@image.dk>
Subject: Re: Diagnostic Scrolls by
Message-Id: <VA.00000090.00083a96@octo>
gemhound@gemhound.com wrote:
>
> I decided to use the statement "use diagnostics;" but now long diagostic
> messages scroll right by in the DOS screen (I'm using win32 perl by
> Activestate), so that I only see the bottom part of the message. I tried
> redirecting by using "perl myprogram.pl > diagfile" but for some reason
> redirection doesn't work -- they still scroll by on the screen too quickly to
> see.
>
> Is there any way I can see the whole message?
I had the same problem. I remembered I had installed DJGPP and one of the
utilities was a program named 'redir'. It does exactly what you want. I usually
say something like:
redir -e errors.txt perl -cw test.pl
and now the STDERR is redirected to the file 'errors.txt', so I have a chance to
look at all of the error messages.
Reni
--
Using Virtual Access
http://www.vamail.com
------------------------------
Date: 12 Dec 1998 13:55:20 GMT
From: stesch@parsec.rhein-neckar.de (Stefan Scholl)
Subject: Re: Fastest way to search through an array?
Message-Id: <slrn774te8.qi1.stesch@parsec.rhein-neckar.de>
On 4 Dec 1998 18:36:53 GMT, Tom Christiansen <tchrist@mox.perl.com> wrote:
> [courtesy cc of this posting sent to cited author via email]
>
> In comp.lang.perl.misc, jhill22@csc.com writes stuff.
>
> The lesson is that arrays aren't for searching; hashes are.
Hashes aren't for searching. They are for finding. :-)
------------------------------
Date: Sat, 12 Dec 1998 14:22:11 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Functions in a template file.
Message-Id: <367267dd.2280540@news.skynet.be>
Alexei Alexandrov wrote:
>The question is can i use in a template file perl functions like this:
>
><html>
>bla-bla
><%
> if ($i > 0) { print "Ok" } else { print "No" }
>%>
></html>
You could. First, extract the code segment, and then eval it.
Just make sure that you don't confuse the template terminator with
anything inside the code segment.
Just a thought: I'd prefer to use code that would leaves a string as a
result, not code that actually prints.
><html>
>bla-bla
><%
> $i>0?"Ok":"No"
>%>
></html>
Maybe this snippet will work.
s/<%(.*?)%>/eval $1/se;
HTH,
Bart.
------------------------------
Date: Sat, 12 Dec 1998 15:45:21 +0100
From: R. A. Larsen <r_larsen@image.dk>
Subject: Re: how check string whether numeric value?
Message-Id: <VA.00000091.00083ea2@octo>
Helmut.Richter@lrz-muenchen.de (Helmut Richter) wrote:
[how check string whether numeric value?]
How about checking for existence of anything but digits?
Reni
--
Using Virtual Access
http://www.vamail.com
------------------------------
Date: 12 Dec 1998 13:49:45 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: how to get screen size?
Message-Id: <74ts9p$pr$1@gellyfish.btinternet.com>
On 9 Dec 1998 21:07:04 GMT Greg Ward <gward@thrak.cnri.reston.va.us> wrote:
> Rollo Chan <rollo@hknet.com> wrote:
>> I am a 'fresh guy' of using perl.....I would like to ask....while using
>> perl under UNIX...how to get the current terminal screen size by
>> perl??.......I mean how to get the column number of the screen in order
>> to adjust the output to fit the screen...thanks of all of your help.....
>
> A couple of ideas: the Term::Cap module comes with Perl; you ought to be
> able to get that information out of the termcap database, but it's not
> entirely clear to me how that would work. (The Term::Cap module is,
> shall we say, minimally documented.) If you're more stubborn than
> me you might be able to figure it out.
Term::Cap is documented as it is because the missing stuff is in the
termcap(5) manpage to which Term::Cap is an interface. You might find
however that for some terminal definitions (such as xterm on this machine)
that the screen dimensions are not defined and some other method is required
to obtain them.
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Sat, 12 Dec 1998 10:43:59 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: ls -l in perl?
Message-Id: <1djx64c.1j7p8z512wfzi8N@bay1-104.quincy.ziplink.net>
Kin Cho <kin@symmetrycomm.com> wrote:
> Does someone has some handy code sniplets to emulate a "ls -l"
> listing purely in Perl?
Note that this is an extra credit question on the current homework
assignment for a current Perl training course. I hope that Kin Cho is
asking for this because he actually needs it in a production program,
and not because he is looking for someone else to do his homework for
him. :-)
--
_ / ' _ / - aka - rjk@linguist.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: Sat, 12 Dec 1998 10:44:00 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: LWP problem/question
Message-Id: <1djx684.1645byv1sddr8hN@bay1-104.quincy.ziplink.net>
Chris Hobbs <chobbs@silvervalley.k12.ca.us> wrote:
> 1: use strict;
> 2: use LWP::Simple qw/get/;
> 3: use CGI qw/:form :html param header/;
> 4:
> 5: my $b_and_n_top =
> "http://shop.barnesandnoble.com/bookSearch/isbnInquiry.asp?isbn=";
> 6: my $isbn = param("isbn");
> 7:
> 8: my $b_and_n_page = get ($b_and_n_top . $isbn);
> 9: print p("B & N Page should begin here...");
> 10: print $b_and_n_page; # TEST TO MAKE SURE PAGE IS RETRIEVED!
> 11: print p("...and it should stop here!");
>
> The problem is that line 10 prints only half the time
> (approximately...), and thus I can't parse the price. However,
> whenever
> I click the link I create, it works perfectly. You may try the
> script at
print will never execute "only half the time". If sometimes it does not
give any output, then it must be because it had nothing to print. In
other words, $b_and_n_page must be empty at those times.
Checking LWP::Simple's documentation, I see that get() returns undef
when it is unable to get the page. You should make sure that
$b_and_n_page is defined().
> I know it's sort of ugly (I'm new, OK? :-), but I am impressed that it
> works so well for what I've learned so far. If I can just figure out why I
> can't load in that B & N page, it'll be wonderful.
Note that to check the response code from the remote server, you will
have to use the full LWP interface.
--
_ / ' _ / - aka - rjk@linguist.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: 12 Dec 1998 11:20:13 -0500
From: clay@panix.com (Clay Irving)
Subject: Re: Perl and Zip
Message-Id: <74u53t$pd6@panix.com>
In <36717d61.609910596@news1.alterdial.uu.net> beimer@uu.net (Barry Eimer) writes:
>Are there any Perl modules that provide an interface to Zip and Unzip
>functions? Or does anyone have any good routines for handling Zip and
>Unzip files.
Compress::Zlib
http://www.perl.com/CPAN-local/modules/by-module/Compress/
Provides a Perl interface to part of the info-zip zlib compression
library. See:
http://www.cdrom.com/pub/infozip/zlib/
for information on zlib.
--
Clay Irving
clay@panix.com
------------------------------
Date: 12 Dec 1998 13:31:19 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Perl Modules, DOCS?
Message-Id: <74tr77$ou$1@gellyfish.btinternet.com>
On Wed, 09 Dec 1998 06:29:00 GMT backslashxt@yahoo.com wrote:
> Hi,
>
> I'm reading up on the standard modules included in Perl and I'm wondering if
> there's any sources on the web for detailed documentation. I learn mostly by
> example and through the .pm files, I have trouble trying to understand the
> details and flexibility of the modules and what we can do with them. Any
> additional resources would be of help ;)
>
The majority of well made Modules come with good documentation and a fair few
of them come with example code as well. Depending on your system setup
you should be able to type (for instance):
perldoc HTML::Parser
and the documentation for the module will be displayed.
ActivePerl from activestate install HTML documentation in a fairly well
organized manner - although this is alleged not to work on any new modules
that might be added.
You could if you wished create HTML documentation from the module files
using pod2html.
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 12 Dec 1998 08:16:02 -0500
From: dblack@pilot.njin.net (David Alan Black)
Subject: Re: Splitting a string at a certain point
Message-Id: <74tqai$84$1@pilot.njin.net>
Hello -
bart.lateur@skynet.be (Bart Lateur) writes:
>Craig Berry wrote:
>> @pieces = $longstring =~ /.{1,20}/g;
>I think you forgot the parentheses.
> @pieces = $longstring =~ /(.{1,20})/g;
> Bart.
The parentheses capture to $1,$2, etc. That isn't needed here:
candle:~/hacking/perl$ perl -w
my $longstring
= "883170453681783178637391547125611486947630234234";
@pieces = $longstring =~ /.{1,20}/g;
print join "\n", @pieces;
^D
88317045368178317863
73915471256114869476
30234234
David Black
dblack@pilot.njin.net
------------------------------
Date: Sat, 12 Dec 1998 14:29:02 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Splitting a string at a certain point
Message-Id: <36757d37.7745248@news.skynet.be>
David Alan Black wrote:
>>I think you forgot the parentheses.
>> @pieces = $longstring =~ /(.{1,20})/g;
>The parentheses capture to $1,$2, etc. That isn't needed here:
>candle:~/hacking/perl$ perl -w
>my $longstring
> = "883170453681783178637391547125611486947630234234";
>@pieces = $longstring =~ /.{1,20}/g;
>print join "\n", @pieces;
>
>^D
>88317045368178317863
>73915471256114869476
>30234234
That's strange. What exactly does it capture then?
@pieces = $longstring =~ /.{1,10}.{0,10}/g;
print join "\n", @pieces;
88317045368178317863
73915471256114869476
30234234
@pieces = $longstring =~ /(.{1,10})(.{0,10})/g;
print join "\n", @pieces;
8831704536
8178317863
7391547125
6114869476
30234234
Bart.
------------------------------
Date: Sat, 12 Dec 1998 16:32:11 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Splitting a string at a certain point
Message-Id: <36729C38.2A11C230@home.com>
[posted & mailed]
Bart Lateur wrote:
>
> David Alan Black wrote:
> >
> > Bart Lateur wrote:
> >>
> >>I think you forgot the parentheses.
>
> >> @pieces = $longstring =~ /(.{1,20})/g;
>
> >The parentheses capture to $1,$2, etc. That isn't needed here:
>
>
> That's strange. What exactly does it capture then?
>
>From perldoc perlop:
m/PATTERN/gimosx
/PATTERN/gimosx
...
The /g modifier specifies global pattern matching--that is, matching
as many times as possible within the string. How it behaves depends
on the context. In a list context, it returns a list of all the
substrings matched by all the parentheses in the regular expression.
If there are no parentheses, it returns a list of all the matched
strings, as if there were parentheses around the whole pattern.
Note that this is slightly different than m// in a list context without
/g. In that case, the list (1) is returned if there is a successful
match and there are no parentheses. This is mentioned in perlop a
little earlier than the preceding quoted paragraph.
--
Rick Delaney
rick.delaney@shaw.wave.ca
------------------------------
Date: 12 Dec 1998 16:40:28 GMT
From: "Allan M. Due" <Allan@Due.net>
Subject: Re: Splitting a string at a certain point
Message-Id: <74u69s$97e$0@206.165.167.208>
Matthew Bafford wrote in message ...
>In article <74s2rc$49fi$1@news-inn.inet.tele.dk>, kenny@weng.dk says...
>=> I want to split a string (42 characters):
>=>
>=> 883170453681783178637391547125611486947630
>=>
>=> into 2 strings (2 x 20 characters) and the "rest"
>=>
>=> 88317045368178317863 (20)
>=>
>=> 73915471256114869476 (20)
>=>
>=> 30 (rest is 2 characters, maybe 4 other times)
>=>
>=> How do I do this?
>
[script snipped because repeated below]
> control: 7 wallclock secs ( 6.92 usr + 0.00 sys = 6.92 CPU)
> regex1: 34 wallclock secs (34.11 usr + 0.00 sys = 34.11 CPU)
> regex2: 32 wallclock secs (32.57 usr + 0.00 sys = 32.57 CPU)
> substr: 26 wallclock secs (26.47 usr + 0.00 sys = 26.47 CPU)
> unpack: 26 wallclock secs (26.91 usr + 0.00 sys = 26.91 CPU)
>
>Hope This Helps!
>--Matthew
Here is a pointless addition using map that is not any faster (as expected).
Just riding the TIMTOWTDI bandwagon.
AmD
Matthew scripts plus a map and a foreach:
#!/usr/bin/perl -w
use strict;
my $before = '883170453681783178637391547125611486947630';
sub _regex1 {
my @after;
@after = $before =~ /(.{1,20})/g;
}
sub _regex2 {
my @after;
@after = ($before =~ /^(.{1,20})(.{1,20})(.*)$/);
}
sub _substr {
my @after;
$after[0] = substr($before, 00, 20);
$after[1] = substr($before, 20, 20);
$after[2] = substr($before, 40 );
}
sub _unpack {
my @after;
@after = unpack('A20A20A*', $before);
}
sub _control {
my @after;
@after = ();
}
sub _foreach {
my @after;
foreach $start (0,20,40) {
push (@after,substr($before,$_,20))
}
}
sub _map {
my @after;
@fter = map {substr($before,$_,20)} (0,20,40);
}
use Benchmark;
timethese(100000, {
'regex1' => \&_regex1,
'regex2' => \&_regex2,
'substr' => \&_substr,
'unpack' => \&_unpack,
'control' => \&_control,
'foreach' => \&_foreach,
'map' => \&_map
});
__END__
Benchmark: timing 100000 iterations of control, foreach, map, regex1,
regex2, substr, unpack...
control: 5 wallclock secs ( 4.24 usr + 0.00 sys = 4.24 CPU)
foreach: 24 wallclock secs (23.40 usr + 0.00 sys = 23.40 CPU)
map: 24 wallclock secs (23.56 usr + 0.00 sys = 23.56 CPU)
regex1: 23 wallclock secs (22.69 usr + 0.00 sys = 22.69 CPU)
regex2: 22 wallclock secs (20.66 usr + 0.00 sys = 20.66 CPU)
substr: 18 wallclock secs (17.97 usr + 0.00 sys = 17.97 CPU)
unpack: 14 wallclock secs (15.06 usr + 0.00 sys = 15.06 CPU)
------------------------------
Date: Sat, 12 Dec 1998 09:29:42 -0600
From: "Chris Reickenbacker" <chrisre@ecpi.com>
Subject: Re: typeglob (*) VS (\%) direct pass-by-ref
Message-Id: <74u04v$bmh$1@nntp.smartdna.com>
my $hashRef = shift;
Mark-Jason Dominus <mjd@op.net> wrote in message
news:74sg1u$qbb$1@monet.op.net...
>In article <74s90s$767$1@nntp.smartdna.com>,
>Chris Reickenbacker <chrisre@ecpi.com> wrote:
>>But that aint why the glob is losing scope. Any ideas ?
>
>When you pass an argument to a function, the function has to receive
>the arguments, and the two have to match. You showed us the code that
>passes, but not the code that receives.
>
>That makes it difficult to explain why the arguments are not being
>properly received.
>
------------------------------
Date: 12 Dec 1998 16:09:45 GMT
From: irc_addict@hotmail.com (Thomas Brian Holdren)
Subject: Why Is Perl not a Language?
Message-Id: <74u4g9$as3$1@cletus.bright.net>
Dear Guru's,
Yeah, I'm a perl baby-talker. Bought my first camel book last week. I still
sometimes use the $_ variable (gasp). I was previously a BASIC programmer (you
may snicker), and had some shell scripting experience (ksh). My question is:
Why is perl not a "programming language"?
For example, why is C or BASIC a "programming language", and perl is just a
"scripting language". Is it because you don't explicitly compile perl
(although the perl interpreter, from what I understand, compiles it at
run-time)? Maybe it's because C can do more things with memory and data and
such.
But, everything I could do in BASIC, I can do in perl (albeit a lot quicker in
perl). Sting manipulation, the reading in of files into memory, etc. So if
someone could please explain the difference between a "programming language"
and a "scripting language", I would surely appreciate it.
Regards,
-Thomas Brian Holdren
"I like the phrase 'feeping creaturism'. One day I hope to understand it."
-Me
ps. Why is the perl mascot a camel? (Versatility?)
------------------------------
Date: Sat, 12 Dec 1998 15:38:23 GMT
From: "Warren Baker" <WeAreUs@Ibm.net>
Subject: won't execute exec(...);
Message-Id: <P5wc2.6691$DO1.3585@news.rdc1.bc.wave.home.com>
Hi All!
The little script below works with the exception of the last part, which
says exec("STUFF.cgi"); (I SHOULD have a use strict in the beginning, too
and will add it later. . .) Why won't it execute the other cgi file??
Thanks heaps!
--Warren
#!/usr/local/bin/perl -w
$|=1;
print "HTTP/1.0 200 OK";
print "Content-type: text/html", "\n";
print "Set-Cookie: BooBoo=Boo; expires=Sun, 13-Dec-98 10:10:10 GMT path=/;
domain=.warrenb.com";
foreach (split(/; /, $ENV{'HTTP_COOKIE'}))
{
# split cookie at each ; (cookie format is name=value; name=value;
etc...)
# Convert plus to space (in case of encoding (not necessary, but
recommended)
s/\+/ /g;
# Split into key and value.
($chip, $val) = split(/=/,$_,2); # splits on the first =.
# Convert %XX from hex numbers to alphanumeric
$chip =~ s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge;
$val =~ s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge;
# Associate key and value
$cookie{$chip} .= "\1" if (defined($cookie{$chip})); # \1 is the
multiple separator
$cookie{$chip} .= $val;
}
print "\n\n";
print " ";
print " $chip $val\n"; #prints the LAST cookie set (but that is all we
need. . .)
exec("STUFF.cgi");
quit;
------------------------------
Date: 12 Dec 1998 16:54:36 GMT
From: "Allan M. Due" <Allan@Due.net>
Subject: Re: won't execute exec(...);
Message-Id: <74u74c$asl$0@206.165.167.208>
Warren Baker wrote in message ...
>Hi All!
>
>The little script below works with the exception of the last part, which
>says exec("STUFF.cgi"); (I SHOULD have a use strict in the beginning, too
>and will add it later. . .) Why won't it execute the other cgi file??
>
>Thanks heaps!
>
>--Warren
[snip the script]
>exec("STUFF.cgi");
>quit;
>From perlfunc:
The exec() function executes a system command AND NEVER RETURNS, unless the
command does not exist and is executed directly instead of via your system's
command shell (see below). Use system() instead of exec() if you want it to
return.
In your system is STUFF.cgi a system command? Because it is not on mine.
Getting exec to run STUFF.cgi will vary a bit system to system. In my much
detested Windoze world you could:
exec('perl','STUFF.cgi')
HTH
AmD
------------------------------
Date: Sat, 12 Dec 1998 00:32:40 -0500
From: Russell Schulz <Russell_Schulz@locutus.ofB.ORG>
Subject: Re: y2k and killing creativity (was Re: Y2K potential problem in localtime())
Message-Id: <19981212.003240.9x5.rnr.w164w@locutus.ofB.ORG>
fl_aggie@thepentagon.com (I R A Aggie) writes:
>>> James - time for a Larry Wall-ism:
>>>
>>> Many computer scientists have fallen into the trap of trying to define
>>> languages like George Orwell's Newspeak, in which it is impossible to
>>> think bad thoughts. What they end up doing is killing the creativity
>>> of programming. -- Larry Wall
>>
>> please tell me you didn't think this was related in any way to the
>> year-1900 silliness or to reading documentation.
>
> Yes, actually.
you think reading documentation kills creativity. or not reading
documentation kills creativity.
whichever, I think that's the stupidest thing I've read all week.
how about this one?
] a night of mindless hacking can save 10 minutes of reading the manual
--
Russell_Schulz@locutus.ofB.ORG Shad 86c
------------------------------
Date: 12 Dec 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 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 4409
**************************************