Re: HoA building



M. Lewis wrote:

John W. Krahn wrote:
M. Lewis wrote:

my ($prod, $flavor) = split /\s/, $ln, 2;

You probably should use ' ' instead of /\s/ as the first argument to
split:

my ($prod, $flavor) = split ' ', $ln, 2;

Ok, but why? Are they not the same?

No.

$ perl -le'
my $ln = " one two three four ";
print map " *$_* ", split /\s/, $ln, 2;
print map " *$_* ", split " ", $ln, 2;
'
** * one two three four *
*one* *two three four *

$ perl -le'
my $ln = "one two three four ";
print map " *$_* ", split /\s/, $ln, 2;
print map " *$_* ", split " ", $ln, 2;
'
*one* * two three four *
*one* *two three four *


/\s/ matches a single whitespace character, ' ' matches one or more whitespace
characters.




John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
.



Relevant Pages

  • Re: Perl style examples (summary)
    ... For CGI: http://users.easystreet.com/ovid/cgi_course/ (John W. Krahn) ... "Perl Best Practices" by Damian Conway ... Janet Goldstein, Christian Winter, Adrian Howard. ...
    (comp.lang.perl.moderated)
  • Re: Passing command line arguments
    ... On Friday 15 April 2005 12:18 am, John W. Krahn wrote: ... >> You could paste the two arguments together in perl, ... Prev by Date: ...
    (perl.beginners)
  • Re: How to deal with binary file?
    ... Tony Winslow wrote: ... John W. Krahn wrote: ... Perl is binary clean, so this shouldn't be a problem. ...
    (comp.unix.shell)
  • Re: Extracting Date using Regular Expressions
    ... John W. Krahn wrote: ... I need some help in regular expressions.... ... Perl isn't a toolbox, but a small machine shop where you can special-order ...
    (comp.lang.perl.misc)
  • Re: How do I create this string?
    ... Flemming Greve Skovengaard wrote: ... John W. Krahn wrote: ... makes no sense so perl converts the value of the index to an integer so the ...
    (perl.beginners)