Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: How do I use the map command for this?

by Marshall (Canon)
on Jun 20, 2022 at 23:15 UTC ( [id://11144885]=note: print w/replies, xml ) Need Help??


in reply to How do I use the map command for this?

"How do I use the map command for this?"
"I am pretty sure I need to use the map command"

The map statement is just a short-hand way of writing a simple "for" loop.
ALL map's can be expressed as "for" (foreach) loops.
Perl generates the same code for a "map" as the equivalent "foreach" loop.

map{} is not your issue.

I think looking at Bio::Perl will lead to some suggestions for you. There are many routines optimized for the FASTA format.

Replies are listed 'Best First'.
Re^2: How do I use the map command for this?
by Anonymous Monk on Jun 21, 2022 at 05:38 UTC
    Perl generates the same code for a "map" as the equivalent "foreach" loop.

    wrong

      Would certainly enjoy being educated. I probably should have said "similar". A map is a looping statement.

        Both for and map iterate over lists, but the latter has the extra purpose that it returns a transformed copy of the list. There's been optimizations that make map in void context efficient (or at least not as inefficicent as it used to be) so you could use  map { do_something( $_ ) @list in place of for (@list) { do_something( $_ ) }, but it's clearer/cleaner to use for for iteration and map for transformation and not muddle the two.

        The cake is a lie.
        The cake is a lie.
        The cake is a lie.

        > A map is a looping statement.

        map is a built-in function used as expression, not a statement

        you are right that most uses can be transformed, but there are differences in syntax and implementation

        as an example, for - like most non-simple statements - doesn't return values.

        edit
        see also Re: why does Perl eval have a strange terminator?

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11144885]
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: (4)
As of 2024-04-25 17:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found