Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: printing all elements of arrays

by drock (Beadle)
on Jul 13, 2004 at 01:26 UTC ( [id://373798]=note: print w/replies, xml ) Need Help??


in reply to Re: printing all elements of arrays
in thread printing all elements of arrays

what does the print map state? what perldoc can I read about the map call?

Replies are listed 'Best First'.
Re^3: printing all elements of arrays
by FoxtrotUniform (Prior) on Jul 13, 2004 at 01:32 UTC
    what does the print map state?

    Okay,

    print join("\n", @array), "\n";
    says "Stick a newline between each element in @array, return that as a string, print it, and print a newline at the end." On the other hand,
    print map {$_ . "\n"} @array;
    says "Build a list whose elements are the elements of @array with "\n" appended to them, then print that list."

    what perldoc can I read about the map call?

    You can read about any function with perldoc -f func_name.

    --
    F o x t r o t U n i f o r m
    Found a typo in this node? /msg me
    % man 3 strfry

      Here is another way to print the elements of an array on separate lines, using the $, variable (see perlvar:

      #!/usr/bin/perl use strict; use warnings; my @array = (1..10); local $, = "\n"; print @array;
Re^3: printing all elements of arrays
by ysth (Canon) on Jul 13, 2004 at 01:30 UTC
    perldoc -f map.

    map is a list-transformer; you give it a block of code and a list, and it applies the code to each element of the list, and returns a list made up of what the code returned for each element.

Re^3: printing all elements of arrays
by beable (Friar) on Jul 13, 2004 at 01:40 UTC
    You can read perlfunc to find out about map. Also, the easiest way to print all the elements of an array is:

    print "@array\n";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-24 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found