in reply to Re: Loading data into an array from a file problem
in thread Loading data into an array from a file problem

oops why does the first work and the second don't
@Names = (1,2,3); @Names = ($same_as_above_pulled_from_file);

Replies are listed 'Best First'.
Re^3: Loading data into an array from a file problem
by davido (Cardinal) on Apr 20, 2006 at 22:45 UTC

    Because (1,2,3) is three elements, and ($same_as_above_pulled_from_file) is just a single scalar value, not a list of several values.

    Maybe you mean:

    @names = split /,\s*/, $same_as_above_pulled_from_file;

    ...chomp and fiddle with split to get the desired results.


    Dave

      Yes that did the trick thank you.

        Be warned though, splitting on commas can only take you so far. For example, if you're dealing with quoted strings, any of which might actually contained embeded commas that should be treated as textual punctuation rather than delimiters, you'll get into trouble really fast. If it turns out that your dataset is more complex, use Text::CSV, or some other similar-purposed module.


        Dave

Re^3: Loading data into an array from a file problem
by eric256 (Parson) on Apr 20, 2006 at 22:42 UTC

    In order to recieve help you will need to put a little more work than that in ;) Show us both the working and the non working versions (the whole version so we can run it and see what it does) and explain what "works" and "doesn't work" mean to you. Your expectations and ours may differ greatly so the more you say explicitly the less there is for us to guess about.


    ___________
    Eric Hodges