Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Understanding Split and Join

by davido (Archbishop)
on Dec 28, 2006 at 07:05 UTC ( #591988=perltutorial: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download

  1. or download this
        $line = "Bart  Lisa Maggie Marge Homer";
        @simpsons = split ( /\s/, $line ); 
            # Splits line and uses single whitespaces 
            # as the delimiter.
  2. or download this
        @simpsons = split ( /\s+/, $line ); 
        #Now splits on one-or-more whitespaces.
  3. or download this
        $string = "Just humilityanother humilityPerl humilityhacker.";
        @japh = split ( /humility/, $string );
  4. or download this
        $string = "alpha-bravo-charlie-delta-echo-foxtrot";
        @list = split ( /(-)/, $string );
  5. or download this
        $string = "Monk";
        @letters = split ( //, $string );
  6. or download this
        @mydata = ( "Simpson:Homer:1-800-000-0000:40:M",
            ( $last, $first, $phone, $age ) = split ( /:/ ); 
            print "You may call $age year old $first $last at $phone.\n";
  7. or download this
        ( $last, $first, $everything_else) = split ( /:/, $_, 3 );
  8. or download this
        $string = "Hello world!";
        @letters = split ( /\s*/, $string );
  9. or download this
        my @list = split /\s+/, $string;
        my @list = $string =~ /(\S+)/g;
  10. or download this
        my @bignumbers = $string =~ /(\d{4,})/g;
  11. or download this
        $string = join ( ':', $last, $first, $phone, $age, $sex );
  12. or download this
        $string = join ( ':', @array );
  13. or download this
        $string = join ( '', @array );
  14. or download this
        $string = join ( '*', "My", "Name", "Is", "Dave" );
  15. or download this
        $string = join ( 'humility', ( qw/My name is Dave/ ) );

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perltutorial [id://591988]
[Corion]: Meh. I think I have now the parts down that I want from a simple Javascript frontend for single-page- applications with a aPerl backend. But it seems that all Javascript templating modules either don't support two-way binding (which would be nice) or ...
[Corion]: ... don't support server-side precompilation (which means the client has to compile all templates to Javascript themselves), or are giant frameworks that expect to do everything (which is not what I want)
[Corion]: I feel that there is a talk somewhere in there, either about the structure and parts, or how I used several parts to get a complete whole.
[Corion]: Maybe I can still find something that is compatible with handlebars.js (which has JS precompilation) but allows for two-way data binding (which is great for the UI)

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2017-03-30 07:50 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (355 votes). Check out past polls.