develooper Front page | perl.perl5.porters | Postings from April 2000

format problem in both 5.005.03 and 5.6.0

From:
H.Merijn Brand
Date:
April 25, 2000 13:58
Subject:
format problem in both 5.005.03 and 5.6.0
Message ID:
20000425224219.210E.H.M.BRAND@hccnet.nl
As I wanted to replace symbolic references in an old perl5 script in
order to be able to anable 'use strict', I ran into a strange problem
with format.

In the old version, the variables where dynamically created and afterwards
used in a required script where the format was defined. Since the naming
of the variable was quite well suited for a re-write to an array of anonymous
hashes, that was chosen as an approach.

    while (<INPUT>) {
        chomp;
        my ($cat, $elem, $data) = split m/\s*\|\s*/, $_, 3;

        # The old way
        my $e = "e$cat$elem";
        $$e = $data;

        # The new way
        $e[$cat]{$elem} = $data;

        :
        }

Now look at using these kind of variables within formats:

Script started on Fri Apr 21 16:49:45 2000
$ cat fmt-bug.pl
#!/usr/bin/perl -w

use strict;

use diagnostics;

my ($e010101, $e020202) = ("Value 1", "Value 2");
my @e;


$e[1]{101} = $e010101;
$e[2]{202} = $e020202;

format OLD0 =
@<<<<<<<<<< @<<<<<<<<<<
$e010101,   $e020202
.

format OLD1 =
@<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<
$e010101,   $e020202,   "$e010101 $e020202"
.

format OLD2 =
@<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<
$e010101,   $e020202,   uc ($e010101)
.

format NEW0 =
@<<<<<<<<<< @<<<<<<<<<<
$e[1]{101},   $e[2]{202}
.

format NEW1 =
@<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<
$e[1]{101}, $e[2]{202}, "$e[1]{101} $e[2]{202}"
.

format NEW2 =
@<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<
$e[1]{101}, $e[2]{202}, uc ($e[1]{101})
.
$ perl -c fmt-bug.pl
syntax error at fmt-bug.pl line 39, near "format NEW2 "
Missing right bracket at fmt-bug.pl line 42, at end of line
fmt-bug.pl had compilation errors (#1)
    
    (F) The final summary message when a perl -c fails.
    
Uncaught exception from user code:
	fmt-bug.pl had compilation errors.
$ perl5.6.0 -c fmt-bug.pl
syntax error at fmt-bug.pl line 39, near "format NEW2 " (#1)
    
    (F) Probably means you had a syntax error.  Common reasons include:
    
        A keyword is misspelled.
        A semicolon is missing.
        A comma is missing.
        An opening or closing parenthesis is missing.
        An opening or closing brace is missing.
        A closing quote is missing.
    
    Often there will be another error message associated with the syntax
    error giving more information.  (Sometimes it helps to turn on -w.)
    The error message itself often tells you where it was in the line when
    it decided to give up.  Sometimes the actual error is several tokens
    before this, because Perl is good at understanding random input.
    Occasionally the line number may be misleading, and once in a blue moon
    the only way to figure out what's triggering the error is to call
    perl -c repeatedly, chopping away half the program each time to see
    if the error went away.  Sort of the cybernetic version of S<20 questions>.
    
Missing right curly or square bracket at fmt-bug.pl line 42, at end of line (#2)
    
    (F) The lexer counted more opening curly or square brackets than
    closing ones.  As a general rule, you'll find it's missing near the place
    you were last editing.
    
fmt-bug.pl had compilation errors (#3)
    
    (F) The final summary message when a perl -c fails.
    
Uncaught exception from user code:
	fmt-bug.pl had compilation errors.

The whole problem could be reduced to:
--8<---
#!/usr/bin/perl -w
use strict;

my @e = (undef, { 101 => "Bicycle" });

# "$e[1]{101}" seems to be a legal string.
my $a = "$e[1]{101}";

# "$e[1]{101}" is illegal here.
# Note that $e[1]{101} is okay, as is "".$e[1]{101}
format NEW =
@<<<<<<<<<<
"$e[1]{101}"
.
-->8---
(Thanks to Johan Vromans who also wonders what the script's length is:
% perl5.6 -w fmt-bug.pl
syntax error at fmt-bug.pl line 14, at EOF
Missing right curly or square bracket at fmt-bug.pl line 14, at end of line
Execution of fmt-bug.pl aborted due to compilation errors.
% perl5.00503 -w fmt-bug.pl
syntax error at fmt-bug.pl line 15, at EOF
Missing right bracket at fmt-bug.pl line 15, at end of line
Execution of fmt-bug.pl aborted due to compilation errors.


$ perl -V
Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:
  Platform:
    osname=hpux, osvers=11.00, archname=PA-RISC2.0
    uname='hp-ux d3 b.11.00 e 9000800 2015358431 8-user license '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useperlio=undef d_sfio=undef
  Compiler:
    cc='cc', optimize='+O2 +Onolimit', gccversion=
    cppflags='-DDEBUGGING -D_HPUX_SOURCE -Ae -I/pro/local/include'
    ccflags ='-DDEBUGGING -D_HPUX_SOURCE -Ae -I/pro/local/include'
    stdchar='unsigned char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    alignbytes=8, usemymalloc=y, prototype=define
  Linker and Libraries:
    ld='ld', ldflags =' -L/pro/local/lib'
    libpth=/pro/local/lib /lib/pa1.1 /lib /usr/lib /usr/ccs/lib
    libs=-lnsl -lnm -lndbm -lgdbm -ldld -lm -lc -lndir -lcrypt
    libc=/lib/libc.sl, so=sl, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_hpux.xs, dlext=sl, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-B,deferred '
    cccdlflags='+z', lddlflags='-b -L/pro/local/lib'


Characteristics of this binary (from libperl): 
  Compile-time options: DEBUGGING
  Built under hpux
  Compiled at Mar 16 2000 15:14:01
  @INC:
    /pro/lib/perl5/5.00503/PA-RISC2.0
    /pro/lib/perl5/5.00503
    /pro/lib/perl5/site_perl/5.005/PA-RISC2.0
    /pro/lib/perl5/site_perl/5.005
    .
$ perl5.6.0 -V
Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:
  Platform:
    osname=hpux, osvers=11.00, archname=PA-RISC2.0
    uname='hp-ux l1 b.11.00 u 9000800 527706567 unlimited-user license '
    config_args='-ds'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define 
    use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef
  Compiler:
    cc='cc', optimize='+O2 +Onolimit', gccversion=
    cppflags='-DDEBUGGING -Ae -D_HPUX_SOURCE -I/pro/local/include'
    ccflags =' -DDEBUGGING -Ae -D_HPUX_SOURCE -I/pro/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 '
    stdchar='unsigned char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, usemymalloc=y, prototype=define
  Linker and Libraries:
    ld='ld', ldflags ='-L/pro/local/lib -Wl,+vnocompatwarnings'
    libpth=/pro/local/lib /lib /usr/lib /usr/ccs/lib /usr/local/lib
    libs=-lnsl -lnm -lndbm -lgdbm -ldb -ldld -lm -lc -lndir -lcrypt -lsec
    libc=/lib/libc.sl, so=sl, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_hpux.xs, dlext=sl, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-B,deferred '
    cccdlflags='+z', lddlflags='-b +vnocompatwarnings -L/pro/local/lib'


Characteristics of this binary (from libperl): 
  Compile-time options: DEBUGGING USE_LARGE_FILES
  Built under hpux
  Compiled at Mar 29 2000 20:34:00
  @INC:
    /pro/lib/perl5/5.6.0/PA-RISC2.0
    /pro/lib/perl5/5.6.0
    /pro/lib/perl5/site_perl/5.6.0/PA-RISC2.0
    /pro/lib/perl5/site_perl/5.6.0
    /pro/lib/perl5/site_perl/5.005/PA-RISC2.0
    /pro/lib/perl5/site_perl/5.005
    /pro/lib/perl5/site_perl
    .
$ 

script done on Fri Apr 21 16:50:51 2000

-- 
H.Merijn Brand
using perl5.005.03 and 5.6.0 on HP-UX 10.20, HP-UX 11.00, AIX 4.2, AIX 4.3,
  DEC OSF/1 4.0 and WinNT 4.0 SP-6a,  often with Tk800.020 and/or DBD-Unify
ftp://ftp.funet.fi/pub/languages/perl/CPAN/authors/id/H/HM/HMBRAND/
Member of Amsterdam Perl Mongers (http://www.amsterdam.pm.org/)




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About