Presumably one would call this as follows:sub max_v_local { local (*a, *b) = @_; my $n = @a > @b ? @a : @b; my @result; for( my $i = 0; $i < $n; $i++ ) { push @result, $a[$i] > $b[$i] ? $a[$i] : $b[$i]; } @result; }
Can I use this typeglob trick with 'use strict'? If so then read on...my @answer = max_v_local( \@mylist, \@yourlist );
I thought this would be great to use in other circumstances but I keep running into problems. Here's some example code (The typeglob is near the middle in the foreach block; This snippet reads in a CSV file and generates an XML file; @c describes the CSV file; For the curious, grbr is an internal identifier).
Which gives me the following errors: Note that I have use strict and use warnings and that the code above starts on line 92:sub test_xml_writer { my( @array, $aref ); my $io = new IO::File '<test.txt' or die( "IO Failure" ); my $csv = new Text::CSV_XS; while( 1 ) { $aref = $csv->getline( $io ); $#{ $aref } > -1 ? push @array, $aref : last; } $io->close(); $io = new IO::File '>test-out.xml' or die "Could not open output f +ile"; my $w = new XML::Writer( OUTPUT => $io, DATA_MODE => 1, DATA_INDEN +T => 2 ); $w->xmlDecl( undef , 1 ); $w->startTag( 'assets' ); foreach ( @array ) { $w->startTag( 'machine' ); my @c = qw( name ip_address snmp_community grbr model_serial ) +; local *a = $_; # my @a = @{$_}; $w->dataElement( $c[0], $a[0], src => 'netview' ) if defined $ +a[0]; $w->dataElement( $c[1], $a[1] ) if defined $a[1]; $w->dataElement( $c[2], $a[2], type => 'rw' ) if defined $a[2] +; $w->dataElement( $c[3], $a[3], src => 'data' ) if defined $a[3 +]; $w->dataElement( $c[4], $a[4], src => 'data' ) if defined $a[4 +]; $w->endTag(); } $w->endTag(); $w->end(); $io->close(); }
Variable "@a" is not imported at ./test.pl line 112. Variable "@a" is not imported at ./test.pl line 112. Variable "@a" is not imported at ./test.pl line 113. Variable "@a" is not imported at ./test.pl line 113. Variable "@a" is not imported at ./test.pl line 114. Variable "@a" is not imported at ./test.pl line 114. Variable "@a" is not imported at ./test.pl line 115. Variable "@a" is not imported at ./test.pl line 115. Variable "@a" is not imported at ./test.pl line 116. Variable "@a" is not imported at ./test.pl line 116. Global symbol "@a" requires explicit package name at ./test.pl line 11 +2. Global symbol "@a" requires explicit package name at ./test.pl line 11 +2. Global symbol "@a" requires explicit package name at ./test.pl line 11 +3. Global symbol "@a" requires explicit package name at ./test.pl line 11 +3. Global symbol "@a" requires explicit package name at ./test.pl line 11 +4. Global symbol "@a" requires explicit package name at ./test.pl line 11 +4. Global symbol "@a" requires explicit package name at ./test.pl line 11 +5. Global symbol "@a" requires explicit package name at ./test.pl line 11 +5. Global symbol "@a" requires explicit package name at ./test.pl line 11 +6. Global symbol "@a" requires explicit package name at ./test.pl line 11 +6. Execution of ./test.pl aborted due to compilation errors.
What am I doing wrong? -- Argel
In reply to Confused about typeglobs and references by Argel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |