Re: HoA building



John W. Krahn 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

Thanks very much John and Chad. Excellent information and examples!

Thank you!


--

IBM: It's Been Malfunctioning
01:35:01 up 13 days, 22:26, 0 users, load average: 0.52, 0.55, 0.46

Linux Registered User #241685 http://counter.li.org
.



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: regular expression
    ... Thanks John. ... > I am looking for help on a PERL regular expression that can do the ... Make sure that the string is 20 chars or else match should fail. ... If you are not the intended recipient, ...
    (perl.beginners)
  • Re: how to pass array and varaible
    ... John and Gunnar, ... > Any arguments passed in show up in the array @_. ... > of Perl created the element whether or not the element was assigned to.) ... > Assigning to the whole array @_ removes that aliasing, ...
    (perl.beginners)
  • Re: combining array refs
    ... > John W. Krahn wrote: ... >>> what is the most effecient way to combine multiple array refs into one ... > You might want to Benchmark this. ... > I know from the perl cookbook that joining two hashes can be done this ...
    (perl.beginners)
  • Re: Kanjidic parser revisited
    ... > I'm also writing some other Japanese language things in Perl, ... Them guys is likely me and John Chew. ... too old to learn a new programming language. ...
    (sci.lang.japan)