Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

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

You values are being stored in the array exactly how you want them. The problem you are seeing comes simply in the output stage.

When you print out an array using code like:

print @out;

All the elements in the array are printed out with nothing between them. You can change this default behaviour by changing the value in $,. Perl prints the value of this variable inbetween the elements of an array. For example:

{ local $, = ':'; print @out; }

This prints the array elements separated with colons. Notice that I've localised the change to $, by putting it in a naked block. This is good practice for whenever you change the value of one of Perl's special variables.

Another technique you could use is to print the array in a double quoted dtring like this:

print "@out";

In this case, the default is to print the values separated by spaces. Once again this behaviour can be changed. In this case you need to chages the value of the $" variable, like this:

{ local $" = "\n"; print "@out"; }

In this case, the elements of @out will be separated by newline characters.

--
<http://www.dave.org.uk>

"The first rule of Perl club is you don't talk about Perl club."


In reply to Re: I'm so confused by davorg
in thread I'm so confused by st4k

Title:
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (None)
    As of 2021-10-16 11:46 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My first memorable Perl project was:







      Results (69 votes). Check out past polls.

      Notices?