printing contents of an array

Posted on 2004-11-06
Last Modified: 2010-03-05
i'm trying to print the contents of an array but i keep getting errors:
here is my code:
use strict;
use warnings;
      next unless /^ATOM/;
      my @flds = split;
      push @x, $flds[6];
      push @y, $flds[7];
      push @z,$flds[8];
for($i = 0; $i< @x;++$i)
      print $x[$i]"\n";

the error i'm getting is:
Global syhsmbol "$i" requires explcit package name
what do i need to do to solve this?
Question by:vonster
    1 Comment
    LVL 18

    Accepted Solution

    you need to localise the variable:

        for(my $i=0 ...

    However, a more perlish way to write that would be

        foreach my $element(@x) {
            print $element, "\n";

    although I would shorten that to:

        print $_,$/ foreach @x;

    or this is even cooler:

            local $, = "\n";
            print @x;

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
    In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now