format

J

James

if i have an array how can i print all element in the array in a format
block when i don't know the length of the array until run time?

by format block i mean

format = STDOUT
number = @#####
$num
name = @<<<<<<<<<
$name
..
that sort of thing.
 
A

Anno Siegel

James said:
if i have an array how can i print all element in the array in a format
block when i don't know the length of the array until run time?

You set $num and name to their successive values and call "write". Have
you read "perldoc -f format" and "perldoc perlform"? It doesn't look like
you did.
by format block i mean

No, you don't.
format = STDOUT
number = @#####
$num
name = @<<<<<<<<<
$name
.
that sort of thing.

That sort of thing is a syntax error. The "=" in the format-line is
misplaced. Please don't re-type code, copy/paste it.

my @names = qw( John Mary Edward Jane);

my ( $num, $name) = 0;
for $name ( @names ) { write }

format STDOUT =
number = @#####
++ $num
name = @<<<<<<<<<
$name
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,076
Latest member
OrderKetoBeez

Latest Threads

Top