Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Using qw

by GrandFather (Saint)
on Nov 18, 2005 at 01:52 UTC ( [id://509666]=note: print w/replies, xml ) Need Help??


in reply to Using qw

In both cases you have an array and print does not insert any extra characters between the elements of an array. You can use join to do that however:

use strict; my @days; @days = qw(Monday Tuesday Wednesday Thursday Friday Saturday Sunday); print ((join ' ', @days), "\n"); print join ' ', qw(Monday Tuesday Wednesday Thursday Friday), "\n";

Prints:

Monday Tuesday Wednesday Thursday Friday Saturday Sunday Monday Tuesday Wednesday Thursday Friday

To see why I put the brackets in try these two lines:

print ((join ' ', @days), "x\n"); print join ' ', @days, "x\n"; #prints: Monday Tuesday Wednesday Thursday Friday Saturday Sundayx Monday Tuesday Wednesday Thursday Friday Saturday Sunday x

Note the space before the x in the second line because @days, "x\n" is a list that join acts on, rather than the paraneter for join followed by a parameter for print.


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: Using qw
by Tech77 (Novice) on Nov 18, 2005 at 19:15 UTC
    Excellent explanation GrandFather. Thank you and thank you to everyone else who wrote in. I am working through your examples.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-18 19:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found