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

Re: Can't / won't print pipe delimiter?

by talexb (Chancellor)
on May 18, 2009 at 17:45 UTC ( [id://764688]=note: print w/replies, xml ) Need Help??


in reply to Can't / won't print pipe delimiter?

I would just have used map to make that a lot more simple:

print map { "$_|" } @my_list

And a design pattern that you should start to recognize is that as soon as you see the concatenation operator, you should be thinking about changing that to a list. So

$my_id_list .= $my_list[$i]."|";
should change to
push ( @my_id, "$my_list[$i]|" );
Later, after you're done with the loop, you can join all of the list elements together.

And if your code also removes the last "|" from the strong that you're building, then you can do

push ( @my_id, $my_list[$i] );
during the loop and
join('|',@my_id);
at the end of the loop to get the same result.

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Replies are listed 'Best First'.
Re^2: Can't / won't print pipe delimiter?
by punch_card_don (Curate) on May 18, 2009 at 18:39 UTC
    Create an array, multiple pushes, then a join, instead of multiple appends and a regex - - - ya, it certainly codes cleaner.

    Aren't you supposed to be in the backyard barbecuing?

        Aren't you supposed to be in the backyard barbecuing?

      Just came back from a nice long bike ride. The steaks are defrosting on the counter. Red wine is open. Grill at 6pm, then .. hockey's on at 730pm. Happy May 24!!

      Alex / talexb / Toronto

      "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-23 20:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found