[19622] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1817 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 25 21:05:37 2001

Date: Tue, 25 Sep 2001 18:05:08 -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: <1001466308-v10-i1817@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 25 Sep 2001     Volume: 10 Number: 1817

Today's topics:
        Blank Lines (MiKyung81)
    Re: Blank Lines (Chris Fedde)
    Re: Book Recommendations <godoy@conectiva.com>
    Re: Book Recommendations <ronh@iainc.com>
    Re: Book Recommendations (Chris Fedde)
    Re: Creating modules <goldbb2@earthlink.net>
    Re: emailing contents of text file <rob_13@excite.com>
    Re: How do I compare strings? <goldbb2@earthlink.net>
    Re: How to fetch all html files under a web directory (baobaoba)
    Re: how to set baud on serial port on linux box (David Efflandt)
        Is there a better way to do this?? <aperlprogrammer@yahoo.com>
        logical comparison <jhall@ifxonline.com>
    Re: logical comparison (David Efflandt)
    Re: logical comparison <jurgenex@hotmail.com>
    Re: logical comparison (Damian James)
    Re: Not sure what type of cgi script I need! (Marc Spitzer)
    Re: Problem with Socket and sysread() (Garry Williams)
    Re: quick question (Garry Williams)
        regex variable length look behind <jks@spam.me.not.akula.com>
        split causes empty elements <usenet@jschneider.de>
    Re: split causes empty elements (Mark Jason Dominus)
    Re: What's wrong with this code ? <uri@sysarch.com>
    Re: who said this? <dcorbit@connx.com>
    Re: Why use Sys::Hostname instead of just $ENV{SERVER_N (David Efflandt)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 25 Sep 2001 22:30:25 GMT
From: mikyung81@aol.com (MiKyung81)
Subject: Blank Lines
Message-Id: <20010925183025.01461.00000765@mb-fz.aol.com>

Hi,
    I'm trying to read from a file and would like to skip if it's just blank
line... I've tried it in many different ways but would get me into infinite
loop.  Any ideas??
Also, is there a one line command that would do...
while(EXPRESSION) {
  .
  .
  if (Expression)   #Fails, then goto the end of while stmt(message line)
  .
  .
  message();
}

Thank You for your help!!


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

Date: Tue, 25 Sep 2001 22:46:38 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Blank Lines
Message-Id: <iP7s7.671$Owe.299647488@news.frii.net>

In article <20010925183025.01461.00000765@mb-fz.aol.com>,
MiKyung81 <mikyung81@aol.com> wrote:
>Hi,
>    I'm trying to read from a file and would like to skip if it's just blank
>line... I've tried it in many different ways but would get me into infinite
>loop.  Any ideas??
>Also, is there a one line command that would do...
>while(EXPRESSION) {
>  .
>  .
>  if (Expression)   #Fails, then goto the end of while stmt(message line)
>  .
>  .
>  message();
>}
>
>Thank You for your help!!

while (<>) {
    print unless /^\s*$/;
}
-- 
    This space intentionally left blank


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

Date: Tue, 25 Sep 2001 19:25:27 -0300
From: Jorge Godoy <godoy@conectiva.com>
Subject: Re: Book Recommendations
Message-Id: <conectiva-linux.m33d5asyaw.fsf@godoy.laptop>

rojo@mindspring.com (RoJo) writes:

> I'd like to get a good book on PERL 5.  I've already got the Pocket
> Reference.  I can find my way around the pod documentation, but I need
> more.  I need  a book that emphasizes examples.  Suggestions?

For examples, buy the "Perl Cookbook". That's an O'Reilly book. 
ISBN 1-56592-243-3.

I'd also recommend the "Programmin Perl - 3rd Edition", ISBN
0-596-0027-8. 


See you,
-- 
Godoy. <godoy@conectiva.com>

Solutions Developer       - Conectiva Inc. - http://en.conectiva.com
Desenvolvedor de Soluções - Conectiva S.A. - http://www.conectiva.com.br


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

Date: Tue, 25 Sep 2001 22:24:52 GMT
From: "Ron Hartikka" <ronh@iainc.com>
Subject: Re: Book Recommendations
Message-Id: <Uu7s7.95814$Hm.1079976@typhoon.mw.mediaone.net>

Perl Cookbook. Many questions asked in this forum and not answered, by
example, in the documentation are answered in Perl Cookbook by Tom
Christiansen and Nathan Torkington.


"RoJo" <rojo@mindspring.com> wrote in message
news:3bb0fa58.73725471@news.mindspring.com...
>
> I'd like to get a good book on PERL 5.  I've already got the Pocket
> Reference.  I can find my way around the pod documentation, but I need
> more.  I need  a book that emphasizes examples.  Suggestions?




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

Date: Tue, 25 Sep 2001 22:41:29 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Book Recommendations
Message-Id: <tK7s7.670$Owe.324480000@news.frii.net>

In article <3bb0fa58.73725471@news.mindspring.com>,
RoJo <rojo@mindspring.com> wrote:
>
>I'd like to get a good book on PERL 5.  I've already got the Pocket
>Reference.  I can find my way around the pod documentation, but I need
>more.  I need  a book that emphasizes examples.  Suggestions?

Looking in the perl faq I see:

    perldoc -q book
    Found in /usr/local/lib/perl5/5.6.1/pod/perlfaq2.pod
       Perl Books

       A number of books on Perl and/or CGI programming are
       available.  A few of these are good, some are OK, but many
       aren't worth your money.  Tom Christiansen maintains a
       list of these books, some with extensive reviews, at
       http://www.perl.com/perl/critiques/index.html .


Though that URL is showing some age.

Good Luck
  

-- 
    This space intentionally left blank


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

Date: Tue, 25 Sep 2001 21:00:37 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Creating modules
Message-Id: <3BB128B5.48954EE9@earthlink.net>

Bart Lateur wrote:
> 
> nobull@mail.com wrote:
> 
> >+      *{"${callpkg}::EXPORT"} = \@{$arg{EXPORT} || []} ;
> >+      *{"${callpkg}::EXPORT_OK"} = \@{$arg{EXPORT_OK} || []};
> 
> This does not do what you think it does.
> 
>         $ref = [ qw(a b c)];
>         $\ = "\n";
>         print $ref;
>         print \@{$ref};
> -->
>         ARRAY(0x176f134)
>         ARRAY(0x176f134)
> 
> If you want a copy of the argument passed, by all means, make a copy;
> if not, keep it simple.
> 
> +    *{"${callpkg}::EXPORT"} = [ @{$arg{EXPORT} || [] } ];   # copy
> 
> +    *{"${callpkg}::EXPORT"} = $arg{EXPORT} || [];           # no copy

It's possible that it simply does not do what *you think* he thinks it
does.

In particular, if the user passes a string or a glob, then \@$foo will
create an arrayref out of it.  I can't think of too many situations when
this would be useful, but I don't see a problem with doing it.

Oh, I can sorta think of one... if somebody passes in something other
than an arrayref as an argument, doing this will catch that mistake by
raising an error.


-- 
"I think not," said Descartes, and promptly disappeared.


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

Date: Tue, 25 Sep 2001 23:24:58 GMT
From: "Rob - Rock13.com" <rob_13@excite.com>
Subject: Re: emailing contents of text file
Message-Id: <Xns9127C5732A414rock13com@64.8.1.227>

jcole <news:3bb013ab.66319894@nntp.ix.netcom.com>:

> for sendmail I'm getting
> command not found

Try which sendmail
then locate sendmail

-- 
Rob - http://rock13.com/
Web Stuff: http://rock13.com/webhelp/


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

Date: Tue, 25 Sep 2001 19:30:46 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: How do I compare strings?
Message-Id: <3BB113A6.6F1AF923@earthlink.net>

Dimitri wrote:
> 
> I have two very long strings, which I need to compare. I am looking
> for the position of the first mismatching character :
> 
> $str1: abcdefghijklmn....
> $str2: abcdefghiXklmn..
> $pos :          9
> 
> How can I find this position, short of writing a for loop that will go
> through each string and use substr to compare character by character?

	$pos = index( "$str1" ^ "$str2", "\0" );

Using index should be faster than using a regex.  Plus, this is a little
bit clearer.

-- 
"I think not," said Descartes, and promptly disappeared.


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

Date: 25 Sep 2001 15:21:30 -0700
From: baobaoba@yahoo.com (baobaoba)
Subject: Re: How to fetch all html files under a web directory
Message-Id: <25212a12.0109251421.1e986e0@posting.google.com>

Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote in message news:<3BB0CDB7.9010101@post.rwth-aachen.de>...
> baobaoba wrote:
> 
> > I am trying to download all html files from a website, suppose it is:
> > 
> > http://www.abc.com/some_directory/
> > 
> > I know there are a lot of html files under "some_directory", but I don't know
> > their names and how many there are. I just want grab them all to my local directory.
> > The HTTP::Request moudle requires actual URL, which looks not work for my case.
> > Does anybody have any idea how to do it?
> 
> 
> HTTP itself as the protocol in question does not support such a thing. 
> To get a particular document you have to explicitly name it.
> There may be the chance that a particular server has a robots.txt lying 
> around which you could then retrieve and examine its content. That's 
> what wget does when using the -r (recursive) switch.
> 
> 
> Tassilo

Is there a wget function? In which module? And any man page for that?
Thanks a lot.

baobaoba


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

Date: Tue, 25 Sep 2001 23:47:29 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: how to set baud on serial port on linux box
Message-Id: <slrn9r25sh.f8r.efflandt@typhoon.xnet.com>

On Tue, 25 Sep 2001 16:59:58 -0400, Tony Schliesser <aschlies@ezwv.com> wrote:
> Consider the following bit of code on a linux box:
> 
> if (open(PHONE,"/dev/$serial")) {
>     while (<PHONE>) {
> 
> 
> This works fine when the linux box decides to boot up and have the serial
> port setup for the right speed.  Ideally, I would like to set up the port
> for n81 at 2400 baud - however I am not sure how to accomplish this in perl.
> I don't consider myself a perl developer so please be gentle with any
> suggestions.  :)

Device::SerialPort module which is a Unix (Linux) port of
Win32::SerialPort.  It also allows you to communicate through the serial
port or with a modem (AT commands, etc.) besides setting things like baud
rate, bits, parity, stop bits.

Of course 'setserial' system command is used to set things like port and
irq if non-standard.

-- 
David Efflandt - All spam is ignored - http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Wed, 26 Sep 2001 00:51:47 GMT
From: Carlos C. Gonzalez <aperlprogrammer@yahoo.com>
Subject: Is there a better way to do this??
Message-Id: <MPG.161ad4b9f32e6afb9897a7@news.edmonton.telusplanet.net>

Hi everyone,

I have some code and I was wondering if anyone could suggest a better way 
to do what I do in it. 

The code:

if (not %data = found('jacky@ardvark.com')) {
  print "Nothing there!\n";
}
else {
  print $data{email_address};
}

I sort of don't like all the stuff that is happening inside the if 
statement.  

found() is a function which searches through a database for the email 
address passed as a parameter.  If the email address is there the found 
sub returns a hash with the values of the record's fields.  If not it 
returns an empty hash.  

I am a bit uncomfortable using found() like this because the %data hash 
is filled through the if statement.  It makes the code harder to follow 
since I may be using data from inside the %hash way down in the code.  If 
I look at the code 6 months from now I may have trouble finding where in 
the world it got initialized to and why sometimes it is initialized and 
sometimes not.  

Can anyone suggest a better way to do this?  I've thought of passing the 
%hash as a modifiable reference parameter into found().  But is there 
some other way?  Maybe I should break the found() into two subs.  One to 
strictly do a find operation and one to fill %hash with the values of the 
record.  Only this might involve two database operations.  

Any comments?

Thanks.

---
Carlos 
www.internetsuccess.ca (not operational yet)


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

Date: Tue, 25 Sep 2001 23:37:00 GMT
From: "John Hall" <jhall@ifxonline.com>
Subject: logical comparison
Message-Id: <wy8s7.32754$6c5.1328154@news1.rdc1.sdca.home.com>

Could someone point me in the right direction as to how I could simplify
this?

#!/usr/bin/perl

$filename = 'bob';

if ($filename eq 'james' || $filename eq 'bob') { print 'yes'; } else {
print 'no'; }


- Basically, I would like a very simple way of comparing one variable to
several values without resorting to a regex.




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

Date: Wed, 26 Sep 2001 00:05:00 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: logical comparison
Message-Id: <slrn9r26tc.f8r.efflandt@typhoon.xnet.com>

On Tue, 25 Sep 2001 23:37:00 GMT, John Hall <jhall@ifxonline.com> wrote:
> Could someone point me in the right direction as to how I could simplify
> this?
> 
> #!/usr/bin/perl
> 
> $filename = 'bob';
> 
> if ($filename eq 'james' || $filename eq 'bob') { print 'yes'; } else {
> print 'no'; }

Examples [unless printing something else on same line, you need newline I 
added or unbuffered output ($| = 1;)]:

print scalar ($filename eq 'james' || $filename eq 'bob') ? 'yes' : 'no',
"\n";

or pattern search:

print scalar ($filename =~ /^(james|bob)$/) ? 'yes' : 'no', "\n";

Note, the scalar prefix is only needed when this is at the beginning of 
the print statement so Perl does not mistake print as a function.  Not 
needed if something else before it like:

print 'matches: ', ($filename =~ /^(james|bob)$/) ? 'yes' : 'no', "\n";

-- 
David Efflandt - All spam is ignored - http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Tue, 25 Sep 2001 17:19:08 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: logical comparison
Message-Id: <3bb11efc$1@news.microsoft.com>

"John Hall" <jhall@ifxonline.com> wrote in message
news:wy8s7.32754$6c5.1328154@news1.rdc1.sdca.home.com...
> Could someone point me in the right direction as to how I could simplify
> this?
> $filename = 'bob';
> if ($filename eq 'james' || $filename eq 'bob') { print 'yes'; } else {
> print 'no'; }
> - Basically, I would like a very simple way of comparing one variable to
> several values without resorting to a regex.

If you put the names you want to check for in an array or a hash then the
search can be simplified to a "grep" or "exists" (untested, only for
concept):

@array = ('james', 'bob');
if (grep({$filename eq $_ }, @array)) {print 'yes';}

%hash= (james => 0, bob => 0);
if (exists($hash{$filename}) {print 'yes';}

In particular the hash solution should be very fast.

jue





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

Date: 26 Sep 2001 00:35:55 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: logical comparison
Message-Id: <slrn9r28im.cr1.damian@puma.qimr.edu.au>

On Tue, 25 Sep 2001 23:37:00 GMT, John Hall said:
>$filename = 'bob';
>if ($filename eq 'james' || $filename eq 'bob') { print 'yes'; } else {
>print 'no'; }
>
>- Basically, I would like a very simple way of comparing one variable to
>several values without resorting to a regex.

A way to generalise to an arbitrary number of possible candidates:
[untested]

#!/path/to/perl -w
use strict;

my @candidates = qw(james bob jim robert);
my $filename = 'bob';

my @matches = ( grep { $_ eq $filename } @candidates );
die "Too many matches - are the candidates corrupt?\n" if @matches > 1;

print scalar @matches? 'yes' : 'no', "\n";
	#or even:
my @answer = qw(no yes);
print $answer[scalar @matches], "\n";

HTH

Cheers,
Damian
-- 
@:=grep!(m!$/|#!..$|),split//,<DATA>;@;=0..$#:;while($:=@;){$;=rand
$:--,@;[$;,$:]=@;[$:,$;]while$:;push@|,shift@;if$;[0]==@|;select$,,
$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/}  __END__
Just another Perl Hacker,### http://home.pacific.net.au/~djames.hub


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

Date: Tue, 25 Sep 2001 22:08:22 GMT
From: marc@oscar.eng.cv.net (Marc Spitzer)
Subject: Re: Not sure what type of cgi script I need!
Message-Id: <slrn9r203i.1671.marc@oscar.eng.cv.net>

In article <ae7dfa3b.0109251327.19e776@posting.google.com>, Snipes wrote:
> Would anyone be kind enough to recommend a script for me to run on a
> web server at work? Every Friday an e-mail with 6 attachments are
> delivered to my e-mail account, they are small, simple .html files
> which contain the next weeks roster information for 6 different groups
> of people.
> 
> I then upload them to the webserver and make them available to anyone
> who wants to log on and download the particular file (ie, their
> roster) that they are interested in. Very few people if any, are
> interested in getting all 6.
> 
> I would like to be able to have a "mailing list" or something similar,
> that the users can subscribe to which allows them to select which of
> the 6 files they want to receive to their own e-mail. When the e-mail
> arrives on Friday to my account, I would like the server to run a
> script/program that takes each attachment and "forwards" or
> "auto-responds" it to the people who are looking for it.
> 
> 
> It is a mailing list I'm looking for? Or perhaps an e-mail manager, I
> honestly don't know myself and I need some help!
> 
> Anyone with any suggestions? Thank you for your time and I appreciate
> your help!
> 
> Regards,
> 
> Snipes.


gnu mailman might fit the bill, with a little work.

marc


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

Date: Wed, 26 Sep 2001 00:43:25 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Problem with Socket and sysread()
Message-Id: <slrn9r295c.9bs.garry@zfw.zvolve.net>

On Tue, 25 Sep 2001 21:09:41 +0200, Dirk Munzinger <d_munzinger@yahoo.de> wrote:
> I am using a TCP-Socket-connection in a program and would like to read a
> datastream with sysread() ($BUFSIZ is POSIX::BUFSIZ)
>  
> 	$rv = $src->sysread($data,$BUFSIZ,0);
> 
> This works fine in most cases but now I have found out that sometimes
> not all the data gets read and that sometime the $BUSIZ is ignored. In
> this case only a few bytes were read even if there where send more bytes
> from the server.

The length is not ignored.  A read on a socket doesn't have to return
a whole message.  You need to sysread() again.  

> Is there a problem with sysread (perl 5.6.1 on Linux) or is there a
> better way to read data (binarydata) from a socket or can I check
> somehow if all the data is read ?

No problem.  The manual page (perlfunc) tells you that sysread()
returns zero at end of file.  

-- 
Garry Williams


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

Date: Wed, 26 Sep 2001 00:57:18 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: quick question
Message-Id: <slrn9r29ve.9bs.garry@zfw.zvolve.net>

On Tue, 25 Sep 2001 17:27:58 +0100, NEWS <na> wrote:
> im very new to perl and programming.
> 
> i want to enter a number using standard input, assign that to a scalar and
> then another figure entered by standard input and multiply the scalars
> together,
> 
> my script goes something like
> 
> print "type a number?\t";
> $a = <STDIN>;
> chomp $a;
> 
> print "type another number\t";
> $b = <STDIN>;
> chomp $b;
> 
> $a*$b = $c;

  $c = $a * $b;

> print $c;
> 
> BUT it wont work, why ???

That's not very descriptive.  

Perl actually gave you an error message that describes the problem.
That error message has an explanation in the perldiag manual page,
too.  That can be printed automatically by perl, if you add use
diagnostics; to the top of your program.  

Also, a "very new to Perl and programming" person should begin every
Perl program with: 

  #!/usr/bin/perl -w
  use strict;

and not violate that rule until the "very new to Perl and programming"
person knows why.  

That would also mean that you would have to have declared your
variables before using them: 

  my ($a, $b, $c);

Finally, there is a reason that you probably want to choose a name
other than $a or $b for variables.  See the perlfunc manual page for
the sort() function to find out why.  This has nothing to do with your
error here, however.  

-- 
Garry Williams


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

Date: Tue, 25 Sep 2001 23:25:29 -0000
From: Joseph Shraibman <jks@spam.me.not.akula.com>
Subject: regex variable length look behind
Message-Id: <tr24j9n3dkf0dc@corp.supernews.com>

If I try to do this:
@companies = split /(?<!\&\w+);/ , $temp; 

I get:
/(?<!&\w+);/: variable length lookbehind not implemented at prnfeed.pl line 121.

I'm using version 5.005_03.  Will variable length look aheads/behinds 
be implemented soon?  Are there any workarounds?  This isn't the first 
time I have had this problem.

-- 
--
TuPari
Joseph Shraibman
jks(at)iname.com


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

Date: 25 Sep 2001 22:54:35 GMT
From: Julian Schneider <usenet@jschneider.de>
Subject: split causes empty elements
Message-Id: <9or1v9$eceb6$1@ID-36572.news.dfncis.de>

Hi,

I try to split up a $message into @messages at the last whitespace
within a certain range, eg. 20 chars: 

@messages = split /(.{1,20})\s+/, $message;

so I want to get from an array like this
$message="Lorem ipsum dolor sit amet, consectetuer adipiscing elit"

an array with 4 elements like 
@messages=("Lorem ipsum dolor", "sit amet,", "consectetuer",
"adipiscing elit"). 

Anyway, there is always an empty element added in front of each
element - I do get an array like 

@messages=("", "Lorem ipsum dolor", "", "sit amet,", "",
"consectetuer", "", "adipiscing elit"). 

This seems to me as if there would be a matching "nothing" - but I
don't know why and where. 

Could anyone explain this to me?

Thanks

Julian


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

Date: Tue, 25 Sep 2001 23:31:18 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: split causes empty elements
Message-Id: <3bb113c5.9d6$126@news.op.net>

[Mailed and posted]

In article <9or1v9$eceb6$1@ID-36572.news.dfncis.de>,
Julian Schneider  <usenet@jschneider.de> wrote:
>Hi,
>
>I try to split up a $message into @messages at the last whitespace
>within a certain range, eg. 20 chars: 
>
>@messages = split /(.{1,20})\s+/, $message;
>
>so I want to get from an array like this
>$message="Lorem ipsum dolor sit amet, consectetuer adipiscing elit"
>
>an array with 4 elements like 
>@messages=("Lorem ipsum dolor", "sit amet,", "consectetuer",
>"adipiscing elit"). 

Lately I've been using this:

        push @messages, $1 while $message =~ /(.{0,20})(\s+|$)/g;

which does produce the results you wanted.

>@messages=("", "Lorem ipsum dolor", "", "sit amet,", "",
>"consectetuer", "", "adipiscing elit"). 
>
>This seems to me as if there would be a matching "nothing" - but I
>don't know why and where. 

Not exactly.  Remeber that split locates *and removes* the delimiters,
and the /pattern/ says what is a delimiter.  It's not matching
'nothing'; it's matching (and removing) *everything*.

>Could anyone explain this to me?

First, look what happens with this 'split', which is almost the same
as yours:

        @messages = split /.{1,20}\s+/, $message;

You get back

        ('', '', '', '', 'elit')

Why is that?  Because split locates the delimiters *and discards
them*.  We said the delimiter was .{1,20}\s+, so it'll locate as many
characters as possible up to a space and *discard* them.  The only
things left are the empty strings between the delimiters, and the
'elit' at the end, which isn't part of a delimiter because is doesn't
include a space.

Second, look at this section of the split() manual page:

	    If the PATTERN contains parentheses, additional list elements
	    are created from each matching substring in the delimiter.

		split(/([,-])/, "1-10,20", 3);

	    produces the list value

		(1, '-', 10, ',', 20)

You did:

        @messages = split /(.{1,20})\s+/, $message;

The .{1,20} is in parentheses now, which means you get extra list
elements created from the parts of the delimiters that match the
 .{1,20}.  So you get the five items  from the previous example, with the
non-space parts of the delimiters inserted in between them:

        ('', 'Lorem ipsum dolor', '', 'sit amet,', '', 'consectetuer',
         '', 'adipiscing', 'elit')

I hope this helps.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Tue, 25 Sep 2001 22:10:14 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: What's wrong with this code ?
Message-Id: <x78zf2c467.fsf@home.sysarch.com>

>>>>> "DW" == David Wall <darkon@one.net> writes:

  DW> I suppose I should have polished it a bit.  How's this?

  DW> while ( <DATA> ) {
  DW>     if ( my @names = m/(name-\S+)/g ) {
  DW>         for my $name (@names) {
  DW>             $_ = <DATA>;
  DW>             if ( /^service\s+(\S+)/ ) {
  DW>                 print "name    = $name\nservice = $1\n";
  DW>             }
  DW>             else {
  DW>                 next;
  DW>             }
  DW>         }
  DW>     }
  DW> }

much better. a style trick i like is when you have a conditional clause
with next/last is to make a statement modifier instead. it saves those
precious braces and indents:

	next unless my @names = m/(name-\S+)/g ;

	for my $name (@names) {

		next unless /^service\s+(\S+)/ ;
		print "name    = $name\nservice = $1\n";
	}

  DW> It still makes lots of assumptions, though.

yes, and that is the OP's problem.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs  --------------------------  http://jobs.perl.org


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

Date: Tue, 25 Sep 2001 16:39:31 -0700
From: "Dann Corbit" <dcorbit@connx.com>
Subject: Re: who said this?
Message-Id: <9or4j1025db@enews3.newsguy.com>

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge. 

--Peter J. Schoenster 
-- 
C-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
 "The C-FAQ Book" ISBN 0-201-84519-9
C.A.P. FAQ: ftp://cap.connx.com/pub/Chess%20Analysis%20Project%20FAQ.htm




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

Date: Wed, 26 Sep 2001 00:29:30 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Why use Sys::Hostname instead of just $ENV{SERVER_NAME} with inet_ntoa(scalar gethostbyname($ENV{SERVER_NAME} || 'localhost'))
Message-Id: <slrn9r28ba.f8r.efflandt@typhoon.xnet.com>

On 25 Sep 2001 11:06:46 -0700, Justin <amiwebguy@yahoo.com> wrote:
> I'm concearned about speed in my script where I'm trying to find the
> IP of the web server. Can anyone please expand on why i should/not use
> Sys::Hostname instead of just $ENV{SERVER_NAME} with inet_ntoa(scalar
> gethostbyname($ENV{SERVER_NAME} || 'localhost')) to get the IP?

The system hostname may differ from the SERVER_NAME, especially if the box 
is behind a firewall.

You should probably use HTTP_HOST which should reflect the requested
hostname and only fall back to SERVER_NAME if that is empty. Otherwise the
IP for each can sometimes differ.  Browsers have supported the Host header 
for a long time, which is required for certain virtual hosts.

-- 
David Efflandt - All spam is ignored - http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

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


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