Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: I'm so confused

by davorg (Chancellor)
on Nov 24, 2001 at 14:22 UTC ( #127257=note: print w/replies, xml ) Need Help??


in reply to I'm so confused

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."

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2021-10-23 18:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (88 votes). Check out past polls.

    Notices?