in reply to Returning arrays from a package
Hi,
This is what you were trying to write
#!/usr/bin/perl -- package xyz; require Exporter; *import = \&Exporter::import; use strict; use warnings; our @EXPORT_OK = qw(@overall @electronics @safety); our @products = ( [ "MG-20", 1, 2, 3 ], [ "JU-54", 2, 3, 1 ], [ "HY-21", 3, 1, 2 ], [ "OK-34", 4, 10, 5 ], [ "GT-75", 9, 6, 0 ], [ "KJ-23", 6, 8, 7 ], [ "PO-65", 7, 5, 10 ], [ "HN-34", 8, 6, 9 ], [ "ED-23", 9, 7, 4 ], [ "FR-98", 10, 4, 8 ], ); our( @overall, @electronics, @safety ); { for my $i ( 0 .. @products ) { push @overall, $products[$i][1] . ":" . $products[$i][0]; push @electronics, $products[$i][2] . ":" . $products[$i][0]; push @safety, $products[$i][3] . ":" . $products[$i][0]; } } 1; __END__
Actually this is what you were trying to write
#!/usr/bin/perl -- package xyz; require Exporter; *import = \&Exporter::import; use strict; use warnings; our @EXPORT_OK = qw(@overall @electronics @safety); our @products = ( [ "MG-20", 1, 2, 3 ], [ "JU-54", 2, 3, 1 ], [ "HY-21", 3, 1, 2 ], [ "OK-34", 4, 10, 5 ], [ "GT-75", 9, 6, 0 ], [ "KJ-23", 6, 8, 7 ], [ "PO-65", 7, 5, 10 ], [ "HN-34", 8, 6, 9 ], [ "ED-23", 9, 7, 4 ], [ "FR-98", 10, 4, 8 ], ); our @overall = map { $_->[1] . ':' . $_->[0] } @products; our @electronics = map { $_->[2] . ':' . $_->[0] } @products; our @safety = map { $_->[3] . ':' . $_->[0] } @products; 1; __END__
So that you could write something like this (no exporting required)
use Data::Dump qw/ dd/; use xyz qw/ @safety /;; dd( \@safety , \@xyz::safety ); __END__do { my $a = [ "3:MG-20", "1:JU-54", "2:HY-21", "5:OK-34", "0:GT-75", "7:KJ-23", "10:PO-65", "9:HN-34", "4:ED-23", "8:FR-98", ]; ($a, $a); }
Also, all lowercase names are reserved for pragmas . You can find much much more discussions on naming modules in Re: RFC: Automatic logger module
Sherab_Inc::xyz Sherab_LLC::products Xyz_LLC::products MySherabApp::xyz SherabApp::products ...
|
|---|