Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Tutorial suggestion: split and join

by davido (Archbishop)
on Aug 28, 2003 at 22:23 UTC ( #287544=perlmeditation: 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",
                    "Simpson:Marge:1-800-111-1111:38:F",
    ...
            ( $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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://287544]
Approved by enoch
Front-paged by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2015-07-31 03:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls