Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Map: The Basics

by jeffa (Chancellor)
on Jun 30, 2000 at 02:00 UTC ( #20505=perltutorial: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
        open (FILE, "foo.txt");
        my @lines = <FILE>;
        close FILE;
    
  2. or download this
        open (FILE, "foo.txt");
        my @words = map { split } <FILE>;
        close FILE;
    
  3. or download this
        my @words = map { split(' ', $_) } <FILE>;
    
  4. or download this
    s/[.,!\?]\B//g
    
  5. or download this
        open (FILE, "foo.txt");
        my @words = map { s/[.,!\?]\B//g; split; } <FILE>;
        close FILE;
    
  6. or download this
        open (FILE, "foo.txt");
        my @lines = map { s/[.,!\?]\B//g } <FILE>;
        close FILE;
    
  7. or download this
        open (FILE, "foo.txt");
        my @lines = map { s/[.,!\?]\B//g; $_; } <FILE>;
        close FILE;
    
  8. or download this
        open (FILE, "foo.txt");
        my @lines = map { chomp; $_; } <FILE>;
        close FILE;
    
  9. or download this
        open (FILE, "foo.txt");
        my @lines = <FILE>;
        chomp(@lines);
        close FILE;
    
  10. or download this
    Benchmark: timing 100 iterations of chomp, map...
        chomp: 31 wallclock secs (29.17 usr +  0.54 sys = 29.71 CPU)
          map: 37 wallclock secs (34.63 usr +  0.59 sys = 35.22 CPU)
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perltutorial [id://20505]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2014-09-17 12:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (76 votes), past polls