[10806] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4407 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 11 20:07:32 1998

Date: Fri, 11 Dec 98 17:00:18 -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           Fri, 11 Dec 1998     Volume: 8 Number: 4407

Today's topics:
    Re: `Scripting languages' are marketing deceipts (was:  (Chris Fedde)
    Re: Assigning to dummy variables in split command <stampes@xilinx.com>
    Re: CGI.pm vs. old way I'm used to? (I R A Aggie)
    Re: Help on s/// !!! <r28629@email.sps.mot.com>
    Re: how check string whether numeric value? (Erik)
    Re: HTML Embedded in Perl <aqumsieh@matrox.com>
    Re: Learning Perl, 2nd edition, exercise 7.1b <r28629@email.sps.mot.com>
        ls -l in perl? <kin@symmetrycomm.com>
    Re: ls -l in perl? (Matthew Bafford)
    Re: PELRSHOP - not recognising SSI (Tad McClellan)
        Perl Cookbook - Praise and question <christopher.kuhi@stud.uni-muenchen.de>
    Re: Perl Floating Point Rounding Algorithm? (Ilya Zakharevich)
        Perl multithread/multiprocess socket server example? (Kyle Cordes)
        Reading/Performing actions from files on another server (Jim Matzdorff)
        rounding numbers <jhill@shamrockmedia.com>
        Script displaying in DOS box on NT server <tdsoft@halcyon.com>
    Re: Script displaying in DOS box on NT server (Erik)
        socket question: to wait or not to wait kos@tdd.hbo.nec.com
    Re: specify password in a ftp URL? (Sam Curren)
    Re: Splitting a string at a certain point <baliga@synopsys.com>
    Re: Splitting a string at a certain point <r28629@email.sps.mot.com>
    Re: Splitting a string at a certain point (Craig Berry)
    Re: Splitting a string at a certain point (Matthew Bafford)
    Re: Splitting a string at a certain point (Tad McClellan)
    Re: STANDARD PERL for WIN 95/NT EXECUTABLE <Allan@Due.net>
    Re: STANDARD PERL for WIN 95/NT EXECUTABLE (Matthew Bafford)
        typeglob (*) VS (\%) direct pass-by-ref <chrisre@ecpi.com>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 11 Dec 1998 16:13:29 -0700
From: cfedde@cfedde.corp.infobeat.com (Chris Fedde)
Subject: Re: `Scripting languages' are marketing deceipts (was: Y2K and Programmer Denial)
Message-Id: <74s8up$ol$1@cfedde.corp.infobeat.com>

In article <73vg2h$ci5$1@csnews.cs.colorado.edu>,
Tom Christiansen  <tchrist@mox.perl.com> wrote:
> [courtesy cc of this posting sent to cited author via email]
>
>In comp.lang.perl.misc, finsol@ts.co.nz writes:
>: The distinctions between programming languages, scripting languages,
>
>There is no such distinction.  It is a myth.
>
>--tom
>-- 
>    X-Windows: Complex nonsolutions to simple nonproblems.
>	--Jamie Zawinski

Paraphrasing a comment once attributed to Larry Wall
    "A script is what you give to the actors,
	a program is what you give to the audience"

chris
--


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

Date: Fri, 11 Dec 1998 14:58:59 -0700
From: Jeff Stampes <stampes@xilinx.com>
Subject: Re: Assigning to dummy variables in split command
Message-Id: <367195A3.D9E2FBBF@xilinx.com>

Larry Rosler wrote:
> There are two ways, equally appropriate.  Using your example:
> 
>   ($karl, $paul, undef, $suzi, undef, undef, $other) =
>      split(/ +/,$linein);
> 
>   ($karl, $paul, $suzi, $other) = (split(/ +/,$linein))[0, 1, 3, 6];

Personally I prefer #2.  If you want to use #1, you have to predeclare
your
variables if you're being careful, otherwise:

stampes@huckin [6] !!
perl
$foo = 'Boulder Colorado 80303 USA';
my ($city,$state,undef,$country) = split /\s/,$foo;
Can't declare undef operator in my at - line 2, near ") ="


-Jeff


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

Date: Fri, 11 Dec 1998 17:48:07 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: CGI.pm vs. old way I'm used to?
Message-Id: <fl_aggie-1112981748070001@aggie.coaps.fsu.edu>

In article <3671945C.D164FB9D@gusun.georgetown.edu>, Dave Stephens
<stepherd@gusun.georgetown.edu> wrote:

+ BUT, I see everyone referring to CGI.PM as the greatest thing ever. So
+ I'm
+ wondering, what am I missing?

A lot?

For one thing, something I love dearly, is that you can run your CGI
from a command line for the debug stage. Running yoru code gives you
this:

(offline mode: enter name=value pairs on standard input)

You could also use a file to simulate the CGI input.

James


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

Date: Fri, 11 Dec 1998 18:09:42 -0600
From: Tk Soh <r28629@email.sps.mot.com>
To: Uri Guttman <uri@ibnets.com>
Subject: Re: Help on s/// !!!
Message-Id: <3671B446.107A6C36@email.sps.mot.com>

[posted to c.l.p.m and copy emailed]

Uri Guttman wrote:
> 
> >>>>> "TS" == Tk Soh <r28629@email.sps.mot.com> writes:
> 
>   TS> $line=~s/(?<=<!--increment here-->)(\d+)/$1+1/e;
> 
>   TS> The (?<=...) is a zero-width lookbehind expression. I personally
>   TS> feel it makes the rhs of s/// look cleaner.
> 
> it is very slow. maybe ilya has sped it up recently but i dropped a use
> of lookbehind because of speed. just grouping both strings like i posted
> before would get you the cleanup you liked:
> 
> $line =~ s/(<!--increment here-->)(\d+)/$1 . ($2+1)/e;
> 
> white space always helps too. :-)

In case someone is wondering:

#!/usr/local/bin/perl -w
use Benchmark;
$line = '.....blablabla.....<TD><!--increment here-->1</TD>....';

timethese(50000, {
      lookbehind => sub {
         $_ = $line;
         s/(?<=<!--increment here-->)(\d+)/$1+1/e;
      },
      uri => sub {
         $_ = $line;
         s/(<!--increment here-->)(\d+)/$1 . ($2+1)/e;
      },
   }
);

Benchmark: timing 50000 iterations of lookbehind, uri...
lookbehind: 12 wallclock secs ( 8.87 usr +  0.02 sys =  8.89 CPU)
       uri:  6 wallclock secs ( 6.10 usr +  0.01 sys =  6.11 CPU)


-TK


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

Date: 11 Dec 1998 22:10:48 GMT
From: eln@cyberhighway.net (Erik)
Subject: Re: how check string whether numeric value?
Message-Id: <74s598$etv$1@news.cyberhighway.net>

In article <36719448.69B1174A@synopsys.com>,
	Yogish Baliga <baliga@synopsys.com> writes:
> if( $x !~ m/^[0-9]+$/ ) {
>    print  "$x is not a valid integer \n";
> }

You should also check for a "-" as the first character for valid integers,
of course.  s/[0-9]/\d/ would be nice in your solution as well, and it
doesn't provide for a lot of cases of valid integers.  Not to mention
the original question was referring to numeric values, not necessarily
just integers.

Of course, this is also a FAQ:
How do I determine whether a scalar is a number/whole/integer/float? 
in perlfaq4.  perldoc perlfaq4.  Pick whichever one you want (it'll depend
on what kind of numbers you expect to get).

-- 
Erik Nielsen, Cyberhighway Internet Services NOC
AFAIR, being insane is usually a pre-requisite for becoming a sysadmin.
In the few cases where it's not pre-requisite, it's certainly going to
be a bonus.
             -- SIggi the Underpaid in a.s.r.


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

Date: Fri, 11 Dec 1998 13:50:11 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
To: nhoop@centuryinter.net (JuNat)
Subject: Re: HTML Embedded in Perl
Message-Id: <x3ysoem5x9a.fsf@tigre.matrox.com>


[posted and mailed]

nhoop@centuryinter.net (JuNat) writes:

> 
> >Any suggestions?
> >
> >
> >   I suggest checking the Perl FAQ before posting.
> 
> That's a mean suggestion. Dang! How quickly these "Experts" forget what
> it's like to be a beginner. It's an unfortunate attitude that seem to be
> endemic in the Perl community. I made the mistake of asking for help in the
> wrong place and got roundly flamed for it.

Nothing mean about reading the FAQs.
Being a beginner does not mean asking questions for every small
problem you encounter. That is being an irresponsible beginner
that only wants people to rush in and solve his/her problem just because
he/she asked although that type of question has been answered millions
of times before and is readily available for everyone.

[PS. The above was a long sentence, although it's nothing
compared to tchrist's postings!]

Sure you can ask for help. But think before you do. If you think that
your problem is a definite FAQ, then it would be faster for you to
just check the FAQs (which should be installed on your machine) and
get your answer. You might even encounter some other hints and nifty
tricks in the process which might be valuable. If, after you checked
the FAQs, you don't find a satisfactory answer, then you can post and
I (among others) will be glad to help.

I am not an expert, but I find it irritating to read this newsgroup
and find at least 50 posting per day that could have been avoided if
the poster had took the time to read the FAQs. A simple grep is all
you need to get your answer .. in just a few seconds. You should
actually applaud all the Perl experts on clp* that put up with such
postings and are still present to help us. I am proud to
say that I haven't posted anything to this ng or any other Perl
related group before I completely read:

1) The Llama
2) The Camel
3) The FAQs
4) Perl 5 Interactive Course

Why should I put in the effort and time to read the above (I read 3
more Perl books since then) and supply you with your answers, when you
don't even want to check the documentation that is installed in your
own system??



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

Date: Fri, 11 Dec 1998 15:57:18 -0600
From: Tk Soh <r28629@email.sps.mot.com>
Subject: Re: Learning Perl, 2nd edition, exercise 7.1b
Message-Id: <3671953E.79DF28A4@email.sps.mot.com>

David Christensen wrote:
> 
> Hello, World!
> 
> I'm working my way through the above book, and everything was rosy
> until I met exercise 7.1b.  My attempt at a solution is as
> follows:

what's the question? I only have the pink llama ;-)

-TK


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

Date: 11 Dec 1998 14:23:48 +0000
From: Kin Cho <kin@symmetrycomm.com>
Subject: ls -l in perl?
Message-Id: <uiufi21vv.fsf@server3.symmetrycomm.com>

Does someone has some handy code sniplets to emulate a "ls -l"
listing purely in Perl?

Or is there perhaps a LS module?

I did check out Find and find.pl etc....

Thanks.

-kin



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

Date: Fri, 11 Dec 1998 19:07:27 -0500
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: ls -l in perl?
Message-Id: <MPG.10db7dccabe42050989757@news.scescape.net>

In article <uiufi21vv.fsf@server3.symmetrycomm.com>, kin@symmetrycomm.com 
says...
=> Does someone has some handy code sniplets to emulate a "ls -l"
=> listing purely in Perl?
=> 
=> Or is there perhaps a LS module?
=> 
=> I did check out Find and find.pl etc....

If there is one, it (sh|w)ould be listed at:

     http://www.perl.com/CPAN/CPAN.html

Or, if that doesn't work out, you could roll your own using a combination 
of stat, opendir, readdir, and closedir (and of course print).

And, when you are done, you could submit the module! :)

=> Thanks.

Hope This Help(s|ed)!

=> -kin

--Matthew


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

Date: Fri, 11 Dec 1998 18:34:15 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: PELRSHOP - not recognising SSI
Message-Id: <7mds47.oh8.ln@magna.metronet.com>

Robby Coleman (robc@AmericanMeter.com) wrote:
: This caught me too.  The solution is simple though.  You simply need a space
: before the final "-->".


   That's what I said, I think...


: I figured this out when I looked at the regular expression (the thing you
: called "ugly").


   I definitely said that. Because it _is_ ugly.


: Tad McClellan wrote in message ...
: >jira@my-dejanews.com wrote:

: >: if (
: >:
: /\<!\-\-\#(include|fsize|flastmod|config|echo|exec)\s+(file|virtual|errmsg|s
: i
: >: zef mt|timefmt|var|cmd|cgi)\s*\=\s*\"(.*?)\" \-\-\>/i )

: >   That is pretty darn ugly.


   So let's pretty it up, and only escape characters 
   that need to be escaped, and take the space out of 'sizef mt':


if (
   /<!--\#
    (include|fsize|flastmod|config|echo|exec)
    \s+
    (file|virtual|errmsg|sizefmt|timefmt|var|cmd|cgi)
    \s*
    =
    \s*
    "
    (.*?)
    "
    [ ]
    -->
   /ix )


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


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

Date: Sat, 12 Dec 1998 01:53:41 +0100
From: Chris <christopher.kuhi@stud.uni-muenchen.de>
Subject: Perl Cookbook - Praise and question
Message-Id: <3671BE95.1A6ECE8E@stud.uni-muenchen.de>

Hi!
I4m relativley new to Perl (first heard of it A year ago, first tried it
in April) and this is my first question posted to a Perl news group. 
I4ve been reading through the Perl Cookbook (is there an abreviation for
it yet? Somehow 4The Sheep Book4 doesn4t sound quite right :) and first
of all I have to say to anyone out there who wants to DO... ANYTHING...
with Perl and can4t seem to do it: BUY THIS BOOK! I have been digesting
morsels from this book nonstop since I picked it up, and all the stuff
I4ve read about in other Perl literature just seems to come together for
me here; Tom and Nathan have done a fantastic job.

That said, I have a little question which is hopefully not better suited
to a unix group:

On p. 494 The authors state that a race condition could be opened up
using the DBM library.  They explain that, though it might be quicker to
delete a file and create it than resetting the file, the former would
open up this race condition.  So my question (purely theoretical at this
point) is, would it avoid this condition if you create another file and
use 4mv4 to rename it to the desired file?  Or would that follow the
link also?  Maybe this question is naive but I4m just curious. Thanks in
advance,

Chris Kuhi


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

Date: 11 Dec 1998 22:40:25 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Perl Floating Point Rounding Algorithm?
Message-Id: <74s70p$oet$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Harry P Bloomberg
<hpb+@pitt.edu>],
who wrote in article <74onm0$ovu$1@usenet01.srv.cis.pitt.edu>:
>    I'm using Version 5.004_04 (according to perl -v) which I think
> qualifies as modern.

What makes you think so?

Ilya


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

Date: Fri, 11 Dec 1998 23:08:02 GMT
From: kyle@kylecordes.com (Kyle Cordes)
Subject: Perl multithread/multiprocess socket server example?
Message-Id: <74s8ki$q0aa_002@news.anet-stl.com>

Hi...

I'm looking to build a rather simple server application in Perl.  The tricky 
part is that I want it to be a multitasking/threading/whatever server, so 
that each incoming connection spawns another process to handle the request, 
so more than one can be processes concurrently.

I'm thinking that such a thing should already exist, waiting for me to plug in 
my actual service code.  However, searching CPAN, DejaNews, etc. has led me 
nowhere.

I have found a few examples of single-threaded servers, always with a note 
that this is a very simple example, and a real app would probably want to be 
able to service more than one request at once.

Ideas?


[* kyle@kylecordes.com       | For Delphi  |  BDE Alternatives Guide  *]
[* http://www.kylecordes.com | developers: | MIDAS Alternatives Guide *]


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

Date: 11 Dec 1998 15:35:09 -0800
From: syran@shell1.ncal.verio.com (Jim Matzdorff)
Subject: Reading/Performing actions from files on another server...
Message-Id: <74sa7d$jsp$1@shell1.ncal.verio.com>

Ok, I've looked in all the usual places, but couldn't find anything to address this.

I am trying to learn some information on a file.  Now, i understand (and use when appropriate)
the file commands.  However I have an instance where a file I need to look at is on a
different server, one that I can't access without telneting to. I thought I could use the
Telnet module, but there is no way to access the information I need with that file (that I
know of).  

I then thought maybe the stat module, but I can't find many references on how to use that
module, let alone use it to do what I want.

Essentially, i want to be able to perform the following commands (or their equivalents) on a
file that I have to telnet to (inside the script):

if ( ! -e $the_file )            

and

if ( -M $the_file > 0 )
(i also rest $^T to the current time for further iterations of a loop, in case the file has
changed but yet again)

I thought doing a directory listing in the telnet session and looking at the inode, but that
doesn't seem to work (or i'm not instituting it correctly).  and looking at last modification
time doesn't work as the smallest denominator is minutes.

Is it possible?

--jim


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

Date: Fri, 11 Dec 1998 15:38:24 -0800
From: Jeff Hill <jhill@shamrockmedia.com>
Subject: rounding numbers
Message-Id: <3671ACEF.159B7FE2@shamrockmedia.com>

Here is my dilemna;

This algorithm is supposed to convert seconds into Minutes, Seconds.
 here is what I have so far.

#!/usr/bin/perl -w

$total_seconds = 125;                 #obviously its 2:05
$raw = $total_seconds / 60;
($min,$sec) = split(/\./, $raw);    #splits the left side of the decimal
into minutes, but the
$sec = $sec * .60;                    #right side gets a "percentage of
a minute".  Multiply that
                                                 #by .60 and you get the
number of seconds.

print "$min:$sec";

The problem lies in the fact that I need it to print "2:05", instead of
2:4999999999999.8
I can't seem to find any info on "sprintf" or "printf", (How does %i
differ from %s or %d) but I am guessing they are the answer.  I can't
find anything useful in the Camel Book.  Help please.



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

Date: Fri, 11 Dec 1998 14:22:03 -0800
From: "Trevor" <tdsoft@halcyon.com>
Subject: Script displaying in DOS box on NT server
Message-Id: <74s61s$ave$1@brokaw.wa.com>

Please help!

I've installed Perl32 on an NT server following all the directions, triple
checked them, but when the script executes, it is displayed in a DOS box
when executed on the server rather than being sent to the browser. These
scripts were originally written for and successfully tested on a UNIX
system. I've even created the most basic "hello world" script and still
displays in a DOS box.

These same scripts will give a HTTP error 501 when executed across the
internet.

Any ideas?

tdsoft@halcyon.com




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

Date: 11 Dec 1998 23:02:33 GMT
From: eln@cyberhighway.net (Erik)
Subject: Re: Script displaying in DOS box on NT server
Message-Id: <74s8a9$huu$3@news.cyberhighway.net>

In article <74s61s$ave$1@brokaw.wa.com>,
	"Trevor" <tdsoft@halcyon.com> writes:
[probably the most FA of all the FAQs]

perldoc perlfaq9:
       My CGI script runs from the command line but not the
       browser.   (500 Server Error)

HTH!

-- 
Erik Nielsen, Cyberhighway Internet Services NOC
It's hard to tune heavily tuned code.  :-)
             -- Larry Wall in <199801141725.JAA07555@wall.org>


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

Date: Fri, 11 Dec 1998 22:11:20 GMT
From: kos@tdd.hbo.nec.com
Subject: socket question: to wait or not to wait
Message-Id: <74s5a7$dqv$1@nnrp1.dejanews.com>

We are trying to have two processes talking to each other.  It seems that
socket is the choice that first come to our mind.  However, we couldn't
figure out how the client process can check, without pending for input,  if
there is anything in the input socket.  If there is something in the socket,
the client process reads it.  If not, the client process continues its
execution.

Of course, we don't have to use socket.  What I am looking for is the the
ability of receiving a semaphore or message with a user-specified timeout
(including "no wait").

Our current platform is NT.  In the future, we would like to have the same
program also running on Solaris.  We use ActivePerl.

Any suggestion?  Thanks in advance.

Shang Ko
Eluminant Technologies

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


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

Date: Fri, 11 Dec 1998 14:43:23 -0800
From: samc@empirewest.com (Sam Curren)
Subject: Re: specify password in a ftp URL?
Message-Id: <MPG.10db3fe31f4100a39896b9@news.sonic.net>

Correct syntax for a login and password embedded into an ftp url:

ftp://login:password@ftp.host.com/

this works even with an '@' sign in the login, like so:

ftp://anonymous:user@host.com@ftp.host.com/

HTH

-Sam

In article <36717726.43603661@web-enrichment.com>, mbehr@web-
enrichment.com says...
> Kin Cho wrote:
> 
> > I'm trying to use mirror in LWP::Simple to
> > access a ftp site that requires password access.
> > What does the URL look like?
> > I tried:
> >
> > ftp://me@foo.com:password/bar.html
> >
> > without success.
> >
> > I'm aware of Net::FTP but I'm trying to keep things simple.
> >
> > Thanks.
> >
> > -kin
> 
> Try ftp://me:password@foo.com/bar.html
> 
> --
> Marc D. Behr                            mbehr@web-enrichment.com
> PGP Key ID: 0x1F1920BC
> Fingerprint20 = 7DC2 3B63 EEB4 9328 0D44  7AC6 7E73 BCBF 1F19 20BC
> 
> It was a book to kill time for those who liked it better dead.
> 
> 
> 
> 


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

Date: Fri, 11 Dec 1998 14:00:16 -0800
From: Yogish Baliga <baliga@synopsys.com>
To: Kenny Weng <kenny@weng.dk>
Subject: Re: Splitting a string at a certain point
Message-Id: <367195F0.2F37E59A@synopsys.com>

2 methods.

 1st one is using Regular Expression.

  $string =~ m/(.{20})(.{20})(.*)/g;
$1 = 1st 20 characters
$2 = 2nd 20 Characters
$3 = rest of characters

2nd Method is faster and use substr function.

   $first = substr( $string, 0, 20 );
   $second = substr( $string, 20, 20 );
   $rest = substr( $string, 40 );

Hope this help to solve your problem.

-- Baliga




Kenny Weng wrote:

> 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?
>
> Please answer at kenny@weng.dk also
> Kenny Weng



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

Date: Fri, 11 Dec 1998 15:53:33 -0600
From: Tk Soh <r28629@email.sps.mot.com>
To: Kenny Weng <kenny@weng.dk>
Subject: Re: Splitting a string at a certain point
Message-Id: <3671945D.B434222@email.sps.mot.com>

[posted c.l.p.m and copy emailed]

Kenny Weng wrote:
> 
> 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?

  DB<5> $before =  '883170453681783178637391547125611486947630'

  DB<6> @after = $before =~ /(.{1,20})/g

  DB<7> X after
@after = (
   0  88317045368178317863
   1  73915471256114869476
   2  30
)

Is this question in the faq's ?

-TK


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

Date: 11 Dec 1998 23:36:14 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Splitting a string at a certain point
Message-Id: <74sa9e$o9q$1@marina.cinenet.net>

Kenny Weng (kenny@weng.dk) wrote:
: 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?

As usual, there's more than one way.  Here's how I'd do it, off the top of
my head:

  @pieces = $longstring =~ /.{1,20}/g;

That quantifier {1,20}, being greedy, will take as many 20-character
chunks as it can, then whatever is left over, putting each chunk
sequentially into @pieces.

-- 
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      "The hills were burning, and the wind was raging; and the
       clock struck midnight in the Garden of Allah."


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

Date: Fri, 11 Dec 1998 19:00:34 -0500
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: Splitting a string at a certain point
Message-Id: <MPG.10db7bf8e421fac8989756@news.scescape.net>

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

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?

1)

$before   = '883170453681783178637391547125611486947630';
@after    = $before =~ /(.{1,20})/g;

2)

$before   = '883170453681783178637391547125611486947630';
@after    = ($before =~ /^(.{1,20})(.{1,20})(.*)$/);

3)

$before   = '883170453681783178637391547125611486947630';
$after[0] = substr($before, 00, 20);
$after[1] = substr($before, 20, 20);
$after[2] = substr($before, 40    );

4)

$before   = '883170453681783178637391547125611486947630';
@after    = unpack('A20A20A*', $before);


And, since Larry is just sooooooo tired:

#!/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    = ();
}

use Benchmark;

timethese(shift, {
	'regex1'  => \&_regex1,
	'regex2'  => \&_regex2,
	'substr'  => \&_substr,
	'unpack'  => \&_unpack,
	'control' => \&_control
});
__END__

Benchmark: timing 500000 iterations of control, regex1, regex2, substr, 
unpack..
 .
   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!

=> Kenny Weng

--Matthew


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

Date: Fri, 11 Dec 1998 18:25:21 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Splitting a string at a certain point
Message-Id: <h5ds47.oh8.ln@magna.metronet.com>

Kenny Weng (kenny@weng.dk) wrote:
: I want to split a string (42 characters):

:     883170453681783178637391547125611486947630

: into 2 strings (2 x 20 characters) and the "rest"

: How do I do this?


   ($p1, $p2, $rest) = $_ =~ /(.{1,20})/g;

   or

   $p1 = substr($_, 0,20);
   $p2 = substr($_, 20,20);
   $rest = substr($_, 40,20);


: Please answer at kenny@weng.dk also


   Ask it here, get the answer here.


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


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

Date: 11 Dec 1998 23:34:04 GMT
From: "Allan M. Due" <Allan@Due.net>
Subject: Re: STANDARD PERL for WIN 95/NT EXECUTABLE
Message-Id: <74sa5c$5mo$0@206.165.167.235>

Johannes Poehlmann wrote in message
<76d9Tp03UkB@link-n-j.poehlmann.link-n.cl.sub.de>...
> (Weekly posting to comp.lang.perl.misc and de.lang.perl)
>_Where to find the *STANDARD* windows 95/NT port of perl (binary) ?_
>(The "standard" has a number of advantages over Microsoft's "Activeware"
>port.

Microsoft?  Am I missing something here?

> E.g. you can install perl modules  not contained in the binary
>distribution. As long as these  Modules do not use C-code you do not need a
>C-
>compiler )


Um, what?  This is your only advantage?  Last time I looked you could
install perl modules with the Activeware version.  Are there many Perl
modules which contain "C-code"?  Inquiring minds want to know.

>Worldwide (Redirecting you to a "near" site )
>    ftp://ftp.perl.com/pub/CPAN/ports/win32/Standard/x86/


[snip]

>You find the Files in alternative subdirectories:    /authors/
>Gurusamy_Sarathy/

You know he works for Activeware don't you?

AmD




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

Date: Fri, 11 Dec 1998 19:00:31 -0500
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: STANDARD PERL for WIN 95/NT EXECUTABLE
Message-Id: <MPG.10db78dd66682246989755@news.scescape.net>

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

In article <76d9Tp03UkB@link-n-j.poehlmann.link-n.cl.sub.de>, 
j.poehlmann@link-n.cl.sub.de says...
=> 	(Weekly posting to comp.lang.perl.misc and de.lang.perl)
             ^ false
=> _Where to find the *STANDARD* windows 95/NT port of perl (binary) ?_

Other people have already tried, but maybe my response will be the last 
stick on the camel's back.  Doubtful, though.

The most *RECENT* port is the *STANDARD* port.

And, since AS's release is 5.005_02, and GS's is only 5.004_02 (IIRC, 
over a years span between the two), I'd say AS's is much more recent than 
GS's.

Since it's more recent, that makes it the *STANDARD* port.

=> (The "standard" has a number of advantages over Microsoft's "Activeware"  
=> port. E.g. you can install perl modules  not contained in the binary  
=> distribution. As long as these  Modules do not use C-code you do not need a C- 
=> compiler )

This comment was true during the days when AS (or whatever they were 
called) didn't support MakeMaker.  Now that they do, you are able to use 
any non C module with AS's release just as easily as you can with GS's.

=> Worldwide (Redirecting you to a "near" site )
=>     ftp://ftp.perl.com/pub/CPAN/ports/win32/Standard/x86/

The ftp site does not redirect you.

=>     Look for a File like
=>           perl5.00402-bindist04-bc.zip
=>     there is a new Version (perl 5.005 ) released

No, there is not.

[snip]

=> #------------------------------------
=> #  find here Gurusamy Sarathy's readme file
=> #------------------------------------

Find here GS's comment about the perl.5.00402-bindist04-bc.*:

perl5.00402-bindist04-bc.zip
perl5.00402-bindist04-bc.tar.gz
    A popular binary distribution of Perl for the Win32 platform (intel).
    Comes with many widely-used modules and all the tools for adding
    new ones from CPAN.  This distribution is rather aged; see
    www.activestate.com for binaries built around Perl 5.005.  I plan to
    update this distribution with Perl 5.004_05 when that maintenance
    update of Perl becomes available.  There are no current plans to make
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    5.005 binaries, but I may make one if there is sufficient interest
    ^^^^^^^^^^^^^^
    and/or the ActiveState offering doesn't cut it, for some reason that
    they're unwilling to fix.


And, since he now WORKS for ActiveState, AS's port should be considered 
the *STANDARD*.

[snip]

=> Enjoy!
=> 
=> 
=> Gurusamy Sarathy (Just Another Perl Porter)
=> gsar@umich.edu
=> 08-AUG-1997

You know, it's fairly rude to sign a message with someone else's name.  

Hope This Helps!

--Matthew


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

Date: Fri, 11 Dec 1998 17:48:59 -0600
From: "Chris Reickenbacker" <chrisre@ecpi.com>
Subject: typeglob (*) VS (\%) direct pass-by-ref
Message-Id: <74s90s$767$1@nntp.smartdna.com>

I think this is a symbol / namespace issue but am unsure as to the exact
cause of the error:

This breaks when I create an instance of the object in any perl package,

my %TransResults = $obj->TransmitData(*TransInfo); # <- typeglob as has ref

This works,

my %TransResults = $obj->TransmitData(\%TransInfo); # <- direct hash ref

 ...but both typeglob and direct ref work fine if used in the context of a
non-package !! The TransmitData() sub is just a wrapper for LWP, it does a
CGI form POST to another CGI (this CGI is on a different machine than the
http client) which returns, in effect, name/value pairs that I stuff back
into a hash. Sort of a poor mans interprocess communication using http. ;)
But that aint why the glob is losing scope. Any ideas ?

Thanks,

Chris






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

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

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