develooper Front page | perl.beginners | Postings from April 2002

RE: Creating variables of a string

Thread Previous | Thread Next
From:
Nikola Janceski
Date:
April 2, 2002 13:05
Subject:
RE: Creating variables of a string
Message ID:
1449413DA482D311B67000508B5A12F50592DFD0@NYEXCHANGE01
Forgot about leading whitespace...
Assuming we don't do that... there really is no diff. 
Thanx for clearing that up, but I still think it's confusing.

From the perlfunc pages:
As a special case, specifying a PATTERN of space (' ') will split on
white space just as split with no arguments does.  Thus, split(' ') can
be used to emulate awk's default behavior, whereas split(/ /)
will give you as many null initial fields as there are leading spaces.
A split on /\s+/ is like a split(' ') except that any leading
whitespace produces a null first field.  A split with no arguments
really does a split(' ', $_) internally.


> -----Original Message-----
> From: John W. Krahn [mailto:krahnj@acm.org]
> Sent: Tuesday, April 02, 2002 3:54 PM
> To: beginners@perl.org
> Subject: Re: Creating variables of a string
> 
> 
> Nikola Janceski wrote:
> > 
> > That always confused me, by default split splits by /\s+/ 
> so why confuse us
> > more by making " " and ' ' magical.
> 
> No, the default is NOT /\s+/, the following are all equivalent:
> 
> @words = split;
> @words = split ' ';
> @words = split ' ', $_;
> 
> 
> John
> -- 
> use Perl;
> program
> fulfillment
> 
> -- 
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> 

----------------------------------------------------------------------------
--------------------
The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About