report format and use strict

M

man-wai chang

format CD_REPORT =

^<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<< $@###.##
$album, $artist, $price
~~^<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<
$album, $artist
..

if I turn on use strict, it will complain about the variable names in
the format definition. How should I declare the format?
 
S

Shawn Corey

man-wai chang said:
format CD_REPORT =

^<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<< $@###.##
$album, $artist, $price
~~^<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<
$album, $artist
.

if I turn on use strict, it will complain about the variable names in
the format definition. How should I declare the format?

Declare the variables before the format:

my ( $album, $artist, $price );
format CD_REPORT = ...

BTW, printf is preferred over formats. See:
perldoc -f printf
perldoc Text::Wrap


--- Shawn
 
F

Fabian Pilkowski

* man-wai chang said:
format CD_REPORT =

^<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<< $@###.##
$album, $artist, $price
~~^<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<
$album, $artist
.

if I turn on use strict, it will complain about the variable names in
the format definition. How should I declare the format?

You want to declare those vars with my() before declaring your format to
use lexical vars:

my( $album, $artist, $price );

If this results in scoping problems between declaring your format and
calling write() try out to use the vars pragma like:

use vars qw( $album $artist $price );

But remember, in that latter case those vars are declared as "global" .
And using such vars isn't welcome everywhere.

regards,
fabian
 
M

man-wai chang

Declare the variables before the format:

my ( $album, $artist, $price );
format CD_REPORT = ...

I tried your way, now the errors become:

"my" variable $total masks earlier declaration in same scope at
report.pl line 53.
Use of uninitialized value in formline at report.pl line 11.
 
M

man-wai chang

man-wai chang said:
I tried your way, now the errors become:

"my" variable $total masks earlier declaration in same scope at
report.pl line 53.
Use of uninitialized value in formline at report.pl line 11.
fixed. I privated the variables twice ith my()
 

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

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top