Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Greetings, fellow monks,

I'm trying to come up with a clever way to solve the following problem and am convinced that I should be able to do it in one line (or thereabouts), but the gray matter isn't working up to full snuff. What I've got so far is:

my @x = (4, 4, 2); my @y; my $pref = 'XX'; foreach my $chunk (1 .. @x) { my $loc = sprintf("$pref%02d:", $chunk); push @y, map {$loc . $_} ( 1 .. $x[$chunk-1] ); }

That gives me:

@y = qw(XX01:1 XX01:2 XX01:3 XX01:4 XX02:1 XX02:2 XX02:3 XX02:4 XX03:1 XX03:2);

which is the right output, but I feel there should be a better way to achieve the end...

In reply to Clever map / foreach algorithm sought by bmcatt

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2022-07-06 13:42 GMT
Find Nodes?
    Voting Booth?

    No recent polls found