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

Map: The Basics

by jeffa (Bishop)
on Jun 30, 2000 at 02:00 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: perltutorial [id://20505]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-03-28 16:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found