Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > report format and use strict

Reply
Thread Tools

report format and use strict

 
 
man-wai chang
Guest
Posts: n/a
 
      03-10-2005

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?

--
.~. Might, Courage, Vision. http://www.linux-sxs.org
/ v \
/( _ )\ Linux 2.4.29
^ ^ 10:02am up 15:16 1 user 1.53 1.30
 
Reply With Quote
 
 
 
 
Shawn Corey
Guest
Posts: n/a
 
      03-10-2005
man-wai chang wrote:
>
> 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
 
Reply With Quote
 
 
 
 
Fabian Pilkowski
Guest
Posts: n/a
 
      03-10-2005
* man-wai chang wrote:
>
> 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
 
Reply With Quote
 
man-wai chang
Guest
Posts: n/a
 
      03-10-2005

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


--
.~. Might, Courage, Vision. http://www.linux-sxs.org
/ v \
/( _ )\ Linux 2.4.29
^ ^ 12:24pm up 17:38 1 user 1.24 1.34
 
Reply With Quote
 
man-wai chang
Guest
Posts: n/a
 
      03-10-2005
man-wai chang wrote:
>> 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.
>
>

fixed. I privated the variables twice ith my()

--
.~. Might, Courage, Vision. http://www.linux-sxs.org
/ v \
/( _ )\ Linux 2.4.29
^ ^ 12:26pm up 17:40 1 user 1.15 1.29
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
When to use "use strict;"? Peng Yu Perl Misc 14 01-27-2010 10:53 PM
How can I use switch -s and 'use strict' at the same time Ting Wang Perl Misc 5 10-06-2005 02:03 PM
why is important to use : use strict? Martina Perl Misc 6 09-20-2005 12:14 AM
Proper way to use an imported constant under 'use strict'? H. Wade Minter Perl Misc 8 04-25-2004 12:58 AM
separate require files for common routines, our, and use strict question Bill Perl Misc 4 01-19-2004 01:39 PM



Advertisments