[19018] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1213 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 28 18:10:37 2001

Date: Thu, 28 Jun 2001 15:10:15 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <993766215-v10-i1213@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 28 Jun 2001     Volume: 10 Number: 1213

Today's topics:
    Re: passing variables the 'right' way (Alex)
    Re: passing variables the 'right' way (Anno Siegel)
    Re: passing variables the 'right' way <mjcarman@home.com>
    Re: passing variables the 'right' way <sumus@aut.dk>
    Re: Perl 6:   ->   vs  . (Tad McClellan)
    Re: Perl variable <chrekh@chello.se>
    Re: perl/Expect.pm's interact function escape squence t (Roland Giersig)
        Processing command line <lhswartw@ichips.intel.com>
        reading the first line off the file <lfzhang@lbl.gov>
    Re: reading the first line off the file (Anno Siegel)
    Re: reading the first line off the file <ren@tivoli.com>
    Re: reading the first line off the file <lfzhang@lbl.gov>
        Remote logging mechanism <shino_korah@yahoo.com>
    Re: Remote logging mechanism <uri@sysarch.com>
        Safe temp file removal <dpk@no-spam.egr.msu.edu>
        Settings locale failed (les ander)
    Re: Settings locale failed (Andy Dougherty)
    Re: Settings locale failed (Anno Siegel)
        Split without delimiter? (Johan M. Andersen)
    Re: Split without delimiter? <uri@sysarch.com>
    Re: Split without delimiter? <ren@tivoli.com>
    Re: Split without delimiter? <EvR@compuserve.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 28 Jun 2001 11:27:32 -0700
From: samara_biz@hotmail.com (Alex)
Subject: Re: passing variables the 'right' way
Message-Id: <c7d9d63c.0106281027.5630b381@posting.google.com>

> The main reason for my ( $param ) = @_; is usually clarity and the only
> sane reason for my $param = shift; is if you wanna alter @_

What's the difference between
   my ($param) = @_;
and
   my $param = shift(@_);

I always thought that was the same thing. Does the fact that you have
parentheses around $param do anything???

Thanks,

Alex


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

Date: 28 Jun 2001 19:49:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: passing variables the 'right' way
Message-Id: <9hg1o0$njg$3@mamenchi.zrz.TU-Berlin.DE>

According to Alex <samara_biz@hotmail.com>:
> > The main reason for my ( $param ) = @_; is usually clarity and the only
> > sane reason for my $param = shift; is if you wanna alter @_
> 
> What's the difference between
>    my ($param) = @_;
> and
>    my $param = shift(@_);
> 
> I always thought that was the same thing.

Not at all. shift() removes things from @_ while ($param) = @_ leaves
@_ intact.

>                                            Does the fact that you have
> parentheses around $param do anything???

The parens are necessary to put the assignment in list context
(otherwise $param would become the *number* of parameters).  It
has nothing to do with the difference between the two.

I prefer shift() to say "lets get this thing out of the way", and
list assignment when I want a clear naming of parameters.  In OO
methods, the two combine nicely:

    sub meth {
        my $self = shift;
        my ( $foo, $bar, $baz) = @_; # the way they appear in the call
        ...

Anno




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

Date: Thu, 28 Jun 2001 14:06:20 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: passing variables the 'right' way
Message-Id: <3B3B802C.37AC3A55@home.com>

Alex wrote:
> 
> What's the difference between
>    my ($param) = @_;
> and
>    my $param = shift(@_);
> 
> I always thought that was the same thing.

$param is the same in either case, but the way it gets set is not.

my ($param) = @_;

copies the first element of @_ into $param. @_ itself is unchanged.

my $param = shift(@_);

removes the first element from @_ and puts it into $param.

> Does the fact that you have parentheses around $param 
> do anything???

Yes, it forces list context. Without them,

my $param = @_;

would evaluate @_ in scalar context, and store its length in $param.

-mjc


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

Date: 28 Jun 2001 22:35:18 +0200
From: Jakob Schmidt <sumus@aut.dk>
Subject: Re: passing variables the 'right' way
Message-Id: <m2els4jqbd.fsf@pocketlife.dk>

Michael Carman <mjcarman@home.com> writes:

> Jakob Schmidt wrote:
> > 
> > This also saves me, since my $x = shift; as an idiom is still silly
> > then :-)
>
> I wouldn't call it silly, I'd call it a sytle issue. I almost always

Don't get me wrong. Of course it's a style (like your style of spelling
just that word, BTW :-) issue - that's also why I moderated "stupid" to
silly.

We all want to write code in a way that we consider easy to understand. But
we have different preferences. To me the shifting game hurts my feelings
because it seems foolish to alter @_ if you don't need the altered version
for some specific purpose.

So shifting blurs the semantic in my view, because it kinda indicates
that you want to alter @_ when that's not really the case at all.

Maybe that's just me.

> For me, it's visually cleaner and makes maintenance easier. It's more
> flexible too:
>
> sub mysub {
>     my $alpha = shift;
>     my @beta  = map {$_ + 1} split /:/, shift;
>     my $gamma = shift || 42;

Fair enough - I can see your point, but in my opinion getting the params
in place at first and then using them is _much_ clearer and _much_ less
vulnerable to change:

sub mysub {
    my ( $alpha, $betafields, $gamma ) = @_;
    my @beta  = map { $_ + 1 } split /:/, $betafields;
    my $gamma ||= 42;
 ...

I'm sure you disagree, and let's just leave it that way.

I don't mean to put anybody down for using the shift movement. If calling
it "silly" is an offense to you guys, please accept my apology.

> My perl wan't compiled with debugging, so I can't tell you what the byte
> code is doing as Abigail did, but any real-world timing differences are
> pretty negligable. If you're *that* concerned about speed, you shouldn't
> be using Perl.

Yes, well you're getting me wrong. You're right that I used speed as
a discriminator, but clarity and beauty is what matters. As a rule I
find that wastefulness reduces beauty - but certainly not always.

> It's fine to use "my ($alpha, $beta, $gamma) = @_" if you prefer it, but
> calling it a performance enhancement is nothing more than misguided
> microoptimization.

I absolutely agree that the time complexity aspect of this specific
issue is not of great importance. Nor is the issue as a whole. Unless
you love code and style. But as I said, optimization (of time complexity)
is not really in the picture.

Had speed been the main issue, I might have tried to avoid moving data
around by using $_[ 0 ] and $_[ 1 ] in stead of named lexicals. Oh and
don't tell me that you can't imagine a setup in which two microseconds
per invocation _does_ make a very real difference(?).

-- 
Jakob


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

Date: Thu, 28 Jun 2001 13:34:29 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl 6:   ->   vs  .
Message-Id: <slrn9jmql5.mel.tadmc@tadmc26.august.net>

Jim Melanson <jim@perlservices.com> wrote:
>The traffic lights article:
>http://www.perl.com/pub/2001/05/22/trafficlights.html#1
>
>by Michael Schwern says that in Perl 6 


Discussion of perl6 will be _much_ more rewarding if done on the
'perl6-language' mailing list. That's where the folks that know
about such things hang out. Only a smattering of them hang out
in the clpmisc swamp.


>the -> operator for method calls is
>going to be replaced by the period (.). (See the footnotes).
>
>Does anyone know if they are keeping backwards compatability 


No, perl6 will not be keeping backwards compatability with regard
to the arrow operator.


>or we going to
>have to re-write all our modules and scripts for Perl 6??


All perl5 modules/programs will need to be rewritten for perl6,
but _people_ won't have to do much of the rewriting. perl6 will
ship with a 'p52p6' program that will convert most p5 code into
p6 code.

There may also be a "use Perl5" type of thing to run p5 unchanged in p6.


[ *35* lines of signature is profoundly presumptious, you should
  consider shortening it...
]


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 28 Jun 2001 21:08:10 GMT
From: Christer Ekholm <chrekh@chello.se>
Subject: Re: Perl variable
Message-Id: <86y9qcco5e.fsf@jane.localdomain>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:

> According to Bart Lateur  <bart.lateur@skynet.be>:
> > Thierry wrote:
> > 
> > >with shell:
> > >$ nb=`ps -ef|grep toto| wc -l`
> > >$ echo $nb
> > >3
> > >
> > >with perl ???
> > >something like nb=system(ps -ef|grep toto|wc -l)
> > That would be 
> > 
> > 	$nb=system("ps -ef|grep toto|wc -l");
> > 
> > but you loose all info sent to STDOUT from the program, as system()
> > doesn't catch it. Instead, use
> > 
> > 	$nb=`ps -ef|grep toto| wc -l`;
> 
> ...or use grep's ability to count:
> 
>         $nb=`ps -ef|grep -c toto`
> 
> Anno

 ...or use Perl's ability to grep and count:

        $nb = grep(/toto/,`ps -ef`);


~~~   ~~~   ~~~   ~~~   ~~~   ~~~   ~~~   ~~~   ~~~
Christer Ekholm                che@init.se
Init System Management         0709 - 909 551
Engelbrektsgatan 7             08 - 407 01 00
Box 5618
114 86 Stockholm


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

Date: 28 Jun 2001 14:24:14 -0700
From: RGiersig@cpan.org (Roland Giersig)
Subject: Re: perl/Expect.pm's interact function escape squence timer
Message-Id: <717195e0.0106281324.3651cc2b@posting.google.com>

keith@aztek-eng.com (Keith) wrote in message news:<8683bf68.0106151414.6642aa6@posting.google.com>...
> The Expect.pm documentation for the interact() function reads:
> 
> 'Interaction ceases when $escape_sequence is read from FILEHANDLE'
> 
> I have an perl script using the Expect.pm module.  I want to allow the user to 
> change from a manual interaction state to a automation state.  When the 
> '$escape_sequence' is read from 'FILEHANDLE' it takes ~15 seconds to move
> back to automation mode or out of the interaction mode.( I think this is to 
> allow for processes to die? I'm not sure)  This seems very
> ineffiecient to me.  Is there some way to speed up this process?  Can I modify 
> any internal timers in Expect.pm?

There is a bug in the current implementation regarding terminating
interact with an escape sequence.  This will be fixed in the next
release, which is overdue (unfortunately, my work workload is quite
high at them moment).  So if you can live with that bug for another
few weeks...

Hope this helps,

Roland
--
RGiersig@cpan.org


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

Date: Thu, 28 Jun 2001 14:17:47 -0700
From: "Swanthog" <lhswartw@ichips.intel.com>
Subject: Processing command line
Message-Id: <9hg6tr$chf@news.or.intel.com>

Hi all,

I'm using GetOpt::Long and want to parse a command switch like:
>script.pl --host host_1 host_2 host_3 host_n

Using GetOpt I only get host_1. I can see the other hosts in @ARGV but I
really need a way to know that they were passed with the --host switch.

Any ideas on how to do this? Keep in mind that the host names can be just
about anything and are not limited to the host_n format I illustrated above.

Thanks,
Larry S.




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

Date: Thu, 28 Jun 2001 11:36:26 -0700
From: Matthew Zhang da LBNL <lfzhang@lbl.gov>
Subject: reading the first line off the file
Message-Id: <3B3B792A.4A71AADB@lbl.gov>

I have this problem to tackle:
Suppose I have a file of an email to be send.  The first line of the
file is assumed to be the subject, the rest is the body, and I attend to
use system("mailx email@address -s subject") to send out the mail, so I
need to get the first line off the file and the redirect the rest of
file to standard input...
1) is the following code correct for reading the firstline?
if (<FILE>){
  $subject = $_;
}

2) I can do:
system("mailx " . $address " -s " $subject " < " .$argv[1])
where $argv[1] is the filename for the email body...but this way, the
subject line (first line of the file) would also be included as body and
I obviously want them separated.  If I were in cpp, I would use stream
to direct the rest of the file to an inputstream, o well, I am in perl,
any ideas?




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

Date: 28 Jun 2001 19:13:40 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: reading the first line off the file
Message-Id: <9hfvl4$mkm$1@mamenchi.zrz.TU-Berlin.DE>

According to Matthew Zhang da LBNL  <lfzhang@lbl.gov>:
> I have this problem to tackle:
> Suppose I have a file of an email to be send.  The first line of the
> file is assumed to be the subject, the rest is the body, and I attend to
> use system("mailx email@address -s subject") to send out the mail, so I
> need to get the first line off the file and the redirect the rest of
> file to standard input...
> 1) is the following code correct for reading the firstline?
> if (<FILE>){
>   $subject = $_;
> }
 
This will read the first line, but it doesn't put it in $_.  Only
while is special that way.

  if ( defined $subject = <FILE> ) {
      chomp $subject;
      ...

> 2) I can do:
> system("mailx " . $address " -s " $subject " < " .$argv[1])
> where $argv[1] is the filename for the email body...but this way, the
> subject line (first line of the file) would also be included as body and
> I obviously want them separated.  If I were in cpp, I would use stream
> to direct the rest of the file to an inputstream, o well, I am in perl,
> any ideas?

Yes.  Open the mailx command as a pipe (see perldoc open).  Then
print the rest of FILE to the command, it will become its standard
input:

    open MAIL, "| mailx $address -s '$subject'" or die "Can't fork: $!\n";
    print MAIL while <FILE>;
    close MAIL or die "Error running mailx: $?\n";

Note how $subject is enclosed in single quotes in the mailx command,
it it likely to contain blanks.

Anno


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

Date: 28 Jun 2001 14:08:42 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: reading the first line off the file
Message-Id: <m3bsn8toat.fsf@dhcp9-173.support.tivoli.com>

On Thu, 28 Jun 2001, lfzhang@lbl.gov wrote:

> I have this problem to tackle:
> Suppose I have a file of an email to be send.  The first line of the
> file is assumed to be the subject, the rest is the body, and I attend to
> use system("mailx email@address -s subject") to send out the mail, so I
> need to get the first line off the file and the redirect the rest of
> file to standard input...
> 1) is the following code correct for reading the firstline?
> if (<FILE>){
>   $subject = $_;
> }

if(<FILE>) doesn't have the magical while(<FILE>) behavior of sticking
the result in $_, so that isn't going to work.  You should probably
just use:

$subject = <FILE>;   # First line is subject

> 2) I can do:
> system("mailx " . $address " -s " $subject " < " .$argv[1])
> where $argv[1] is the filename for the email body...but this way, the
> subject line (first line of the file) would also be included as body and
> I obviously want them separated.  If I were in cpp, I would use stream
> to direct the rest of the file to an inputstream, o well, I am in perl,
> any ideas?

Basically the same thing -- have Perl read the file and send the data
to the command.

$subject = <FILE>;   # First line is subject
open MAIL, "|mailx -s $subject $address" or die "Could not fork: $!\n";
print MAIL <FILE>;
close MAIL or die "Problem with mailx: $!\n";

Note that this is not a particularly robust way to handle mail.  I
believe there are some modules on CPAN that are better for this
purpose.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Thu, 28 Jun 2001 13:15:02 -0700
From: Matthew Zhang da LBNL <lfzhang@lbl.gov>
Subject: Re: reading the first line off the file
Message-Id: <3B3B9046.D8738FA7@lbl.gov>


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

> This will read the first line, but it doesn't put it in $_.  Only
> while is special that way.
>
>   if ( defined $subject = <FILE> ) {
>       chomp $subject;
>       ...

the if line gives me the following error:
"can't modify defined operator in scalar assignment at automail line 15, near
"<FILE>"
Execution of automail aborted due to compilation errors.

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

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>

<blockquote TYPE=CITE><tt>This will read the first line, but it doesn't
put it in $_.&nbsp; Only</tt>
<br><tt>while is special that way.</tt><tt></tt>
<p><tt>&nbsp; if ( defined $subject = &lt;FILE> ) {</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chomp $subject;</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...</tt></blockquote>
the if line gives me the following error:
<br>"can't modify defined operator in scalar assignment at automail line
15, near "&lt;FILE>"
<br>Execution of automail aborted due to compilation errors.</html>

--------------C025ED53D882C8CE4BD02DFE--



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

Date: Thu, 28 Jun 2001 13:45:08 -0700
From: "terminalsplash" <shino_korah@yahoo.com>
Subject: Remote logging mechanism
Message-Id: <9hg50p$b8s@news.or.intel.com>

Hi,

Can anyone suggest a remote loging mechanism which i can use inside my perl
program,which will enable me to run some commands in the new machine?

Thnaks




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

Date: Thu, 28 Jun 2001 20:52:57 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Remote logging mechanism
Message-Id: <x7vglg8gyd.fsf@home.sysarch.com>

>>>>> "t" == terminalsplash  <shino_korah@yahoo.com> writes:

  t> Can anyone suggest a remote loging mechanism which i can use inside
  t> my perl program,which will enable me to run some commands in the
  t> new machine?

that is remote execution, not logging. maybe you thought about remote
logging in, which is not the same.

there are many ways of doing this and most are outside of perl.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: 28 Jun 2001 19:07:49 GMT
From: Dpk <dpk@no-spam.egr.msu.edu>
Subject: Safe temp file removal
Message-Id: <9hfva5$1drg$1@msunews.cl.msu.edu>

I read an article on the web a few months ago (can't seem to find it
to give the author some credit) about using a chroot environment for
safely removing tmp files.  While I did not use his source, I used his
concept and added logging capabilities via pipes.  Since I am far from
a programming genius, I think it is only practical for my own use
(although it can be used under the GPL); however, I am interested in
constructive criticism, specifically on how secure it really would be:

   http://www.egr.msu.edu/~dpk/perl/Cleantmp.pm

Thanks in advance,
Dennis Kelly


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

Date: 28 Jun 2001 11:08:12 -0700
From: les_ander@yahoo.com (les ander)
Subject: Settings locale failed
Message-Id: <a2972632.0106281008.38edf409@posting.google.com>

Hi, 



I don't know what i did to cause this but i don't know how to correct it.



Every time i run perl scipts, i get the following error



perl: warning: Setting locale failed.

perl: warning: Please check that your locale settings:

	LANGUAGE = (unset),

	LC_ALL = (unset),

	LANG = "en_US"

    are supported and installed on your system.

perl: warning: Falling back to the standard locale ("C").



how can i fix it?

i am using  redhat 7.1



thanks


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

Date: Thu, 28 Jun 2001 18:16:02 -0000
From: doughera@maxwell.phys.lafayette.edu (Andy Dougherty)
Subject: Re: Settings locale failed
Message-Id: <slrn9jmt5k.6en.doughera@maxwell.phys.lafayette.edu>

In article <a2972632.0106281008.38edf409@posting.google.com>, les ander wrote:
>Hi, 

>perl: warning: Setting locale failed.

[etc.]

Try 
	man perllocale

and check out the section "LOCALE PROBLEMS".

-- 
    Andy Dougherty		doughera@lafayette.edu
    Dept. of Physics
    Lafayette College, Easton PA 18042


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

Date: 28 Jun 2001 19:54:24 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Settings locale failed
Message-Id: <9hg21g$njg$4@mamenchi.zrz.TU-Berlin.DE>

According to Andy Dougherty <doughera@maxwell.phys.lafayette.edu>:
> In article <a2972632.0106281008.38edf409@posting.google.com>, les ander wrote:
> >Hi, 
> 
> >perl: warning: Setting locale failed.
> 
> [etc.]
> 
> Try 
> 	man perllocale
> 
> and check out the section "LOCALE PROBLEMS".

 ...or, if you don't really care about the locale, just unset the $LANG
environment variable in your shell setup.

Anno


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

Date: 28 Jun 2001 14:18:01 -0400
From: johan@columbia.edu (Johan M. Andersen)
Subject: Split without delimiter?
Message-Id: <o04ofr8lb8m.fsf@valhalla.cc.columbia.edu>

So I'm trying to take a really long line and split it into an arbitrary
number of 8 character tokens. Right now, I do something like this...

for($_=shift;$token=substr($_,$offset,8);$offset+=8) {
	# blah blah blah
}

Is there a better way to do this? I couldn't figure out how to make split
work with no delimiters, or do a regexp that returns all the matches as an
array. Thanks!

/johan


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

Date: Thu, 28 Jun 2001 18:39:14 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Split without delimiter?
Message-Id: <x73d8ka1po.fsf@home.sysarch.com>

>>>>> "JMA" == Johan M Andersen <johan@columbia.edu> writes:

  JMA> So I'm trying to take a really long line and split it into an arbitrary
  JMA> number of 8 character tokens. Right now, I do something like this...

  JMA> for($_=shift;$token=substr($_,$offset,8);$offset+=8) {
  JMA> 	# blah blah blah
  JMA> }

  JMA> Is there a better way to do this? I couldn't figure out how to
  JMA> make split work with no delimiters, or do a regexp that returns
  JMA> all the matches as an array. Thanks!

@eights = /.{8}/g ;

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: 28 Jun 2001 13:37:57 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Split without delimiter?
Message-Id: <m3g0cktpq2.fsf@dhcp9-173.support.tivoli.com>

On 28 Jun 2001, johan@columbia.edu wrote:

> So I'm trying to take a really long line and split it into an
> arbitrary number of 8 character tokens. Right now, I do something
> like this...
> 
> for($_=shift;$token=substr($_,$offset,8);$offset+=8) {
> 	# blah blah blah
> }
> 
> Is there a better way to do this? I couldn't figure out how to make
> split work with no delimiters, or do a regexp that returns all the
> matches as an array. Thanks!

@pieces = /.{8}/g;

-- 
Ren Maddox
ren@tivoli.com


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

Date: Thu, 28 Jun 2001 14:58:22 -0600
From: "Richard A. Evans" <EvR@compuserve.com>
Subject: Re: Split without delimiter?
Message-Id: <9hg5mm$c5b$1@suaar1ab.prod.compuserve.com>

I suggest that you use

$string = "abcdefghijklmnopqrstuvwxyzABCDEFGHI";
@chunks = $string =~ /.{1,8}/g;
print join "\n", @chunks;

The difference between this approach and the others given is that it deals
with the 'leftover' characters.  That is, if the string length is not evenly
divisible by 8, the remaining chunk is saved in the final element of the
array.  The output of the script above is:

abcdefgh
ijklmnop
qrstuvwx
yzABCDEF
GHI


Regards,

Rick Evans

"Johan M. Andersen" <johan@columbia.edu> wrote in message
news:o04ofr8lb8m.fsf@valhalla.cc.columbia.edu...
> So I'm trying to take a really long line and split it into an arbitrary
> number of 8 character tokens. Right now, I do something like this...
>
> for($_=shift;$token=substr($_,$offset,8);$offset+=8) {
> # blah blah blah
> }
>
> Is there a better way to do this? I couldn't figure out how to make split
> work with no delimiters, or do a regexp that returns all the matches as an
> array. Thanks!
>
> /johan




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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 1213
***************************************


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