report format and use strict

Discussion in 'Perl Misc' started by man-wai chang, Mar 10, 2005.

  1. 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
    man-wai chang, Mar 10, 2005
    #1
    1. Advertising

  2. man-wai chang

    Shawn Corey Guest

    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
    Shawn Corey, Mar 10, 2005
    #2
    1. Advertising

  3. * 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
    Fabian Pilkowski, Mar 10, 2005
    #3

  4. > 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
    man-wai chang, Mar 10, 2005
    #4
  5. 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
    man-wai chang, Mar 10, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. H. Wade Minter
    Replies:
    8
    Views:
    292
    Robin
    Apr 25, 2004
  2. Martina

    why is important to use : use strict?

    Martina, Sep 19, 2005, in forum: Perl Misc
    Replies:
    6
    Views:
    99
    J├╝rgen Exner
    Sep 20, 2005
  3. Ting Wang
    Replies:
    5
    Views:
    173
    John Bokma
    Oct 6, 2005
  4. Peng Yu

    When to use "use strict;"?

    Peng Yu, Jan 25, 2010, in forum: Perl Misc
    Replies:
    14
    Views:
    176
    John Bokma
    Jan 27, 2010
  5. Marius Gavrilescu

    Re: use strict; use warnings;

    Marius Gavrilescu, Feb 24, 2014, in forum: Perl Misc
    Replies:
    152
    Views:
    498
    $Bill
    Mar 11, 2014
Loading...

Share This Page