joe_fubar has asked for the wisdom of the Perl Monks concerning the following question:

Hi, i've problems to read a array, data::dumper gives me:
$VAR1 = [ 'BNJ', 'CGN', 'DUS', 'ESS', 'MGL', 'SGE' ];
But this doesn't work:
foreach my $records (@geo){ print "$records\n"; }
$records doesnt contain the array element, how can i get them? many thanks - joe

Replies are listed 'Best First'.
Re: Reading arrays
by GrandFather (Saint) on Feb 26, 2011 at 21:26 UTC

    Show us sufficient code to run and demonstrate the problem you are having. What you do show is inconsistent with the problem you describe so there is more to the story than you are telling.

    True laziness is hard work

      Further to GrandFather's reply: This is what I get from my interpretation of the OP:

      >perl -wMstrict -le "use Data::Dumper; ;; my @geo = qw(BNJ CGN DUS ESS MGL SGE); print Dumper \@geo; ;; for my $records (@geo) { print qq{[$records]} } " $VAR1 = [ 'BNJ', 'CGN', 'DUS', 'ESS', 'MGL', 'SGE' ]; [BNJ] [CGN] [DUS] [ESS] [MGL] [SGE]

      joe_fubar: How does this "not work" for you?

Re: Reading arrays
by bart (Canon) on Feb 27, 2011 at 12:42 UTC
    It's hard to guess what you've got, but I'm thinking perhaps you've got an array ref in a variable and you're trying to read the data from a plain array.

    In that case you'll have to dereference the array ref. Perl will never automatically dereference for you.

    @geo = @$geo;

      Hi Folks,

      thanks realy much for helping, dereference the array did the trick, this is what i have, maybe not very fashioned but it works:

      #! /usr/bin/perl use strict; use warnings; use Data::Dumper; my @final; my @geo; my $derefrecord; use Win32::OLE; #Used for Geosearch and Currency my $fso = Win32::OLE->new("HHCOM.GeoSearch.CircleRangeSearch"); @geo = $fso->FindLocationsInCircleRange("CGN",75) ; print Dumper(@geo); foreach my $records (@geo){ print "=>@$records<=\n"; $derefrecord="@$records"; } print "$derefrecord\n"; my @GEORECORD = split(" ", $derefrecord); foreach (@GEORECORD){ print "$_\n"; } Output of print Dumper(@geo); $VAR1 = [ 'BNJ', 'CGN', 'DUS', 'ESS', 'GKE', 'MGL', 'SGE', 'WID' ];

      Output of print "=>@$records<=\n";

      =>BNJ CGN DUS ESS GKE MGL SGE WID<=

      Output foreach (@GEORECORD){print "$_\n"; ...

      BNJ CGN DUS ESS GKE MGL SGE WID

      Thanks again Joe

Re: Reading arrays
by joe_fubar (Initiate) on Feb 26, 2011 at 21:41 UTC
    I'm trying to read a list of elements through a windows com+ application, the application is returning a list of words with 3 chars each in a csv format, i would expect someting like "abc','def',ghi" and so on. Code: ------
    #! /usr/bin/perl -w use Data::Dumper; use Win32::OLE; my $fso = Win32::OLE->new("HHCOM.GeoSearch.CircleRangeSearch"); @geo = $fso->FindLocationsInCircleRange("CGN",70) ; print Dumper(@geo); foreach my $records (@geo){ print "$records\n"; }
    ------ the output of $result doesnt show me the elements where i'm lookking for. Dumper(@geo) returns: gives me:
    $VAR1 = [ 'BNJ', 'CGN', 'DUS', 'ESS', 'MGL', 'SGE' ];
    How can i read them?

      Most likely FindLocationsInCircleRange returns an array reference so you need:

      #! /usr/bin/perl use strict; use warnings; use Data::Dumper; use Win32::OLE; my $fso = Win32::OLE->new ("HHCOM.GeoSearch.CircleRangeSearch"); my $geo = $fso->FindLocationsInCircleRange ("CGN", 70); print Dumper ($geo); for my $records (@$geo) { print "$records\n"; }
      True laziness is hard work