Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: Read/Create files

by TANYALYNN82 (Initiate)
on Mar 25, 2015 at 19:23 UTC ( [id://1121329]=note: print w/replies, xml ) Need Help??


in reply to Re: Read/Create files
in thread Read/Create files

Thank you all for your help. I added the $ and now it gives this message: Global symbol "@indexfiles" requires explicit package name at index.pl What does this error mean? Thanks!

Replies are listed 'Best First'.
Re^3: Read/Create files
by Athanasius (Archbishop) on Mar 26, 2015 at 08:18 UTC

    Hello TANYALYNN82,

    You must have done more than just add $ to i, or you would be getting different warning messages. My guess is that you also removed this line:

    my @indexfiles;

    which would account for the error message you report. The point to understand is that $indexfiles and @indexfiles are two different variables, the first a scalar, the second an array. Changing one has no affect on the other. Now, when you say:

    $indexfiles[$i] = ...

    you are accessing the element at the $ith index of the array @indexfiles. If you haven’t declared it first (via my @indexfiles) then use strict will generate the error message you are seeing.

    But even when you do declare @indexfiles, the code shown in the OP won’t do what you want, because the scalar variable $indexfiles, which is printed at the end of the foreach loop, is never changed, and so each print will result in a warning like this:

    Use of uninitialized value $indexfiles in print at index.pl line...

    I don’t know what you are trying to do here, so I can’t advise you further; but please read perlintro, especially Perl variable types.

    Two additional points:

    • $parts[0] == 'ABC' attempts to compare whatever is in $parts[0] with the string 'ABC' using the numerical comparison operator ==. You should use eq instead.

    • While not strictly wrong in this instance, having two lexical variables named $build is certainly confusing. It would be better to choose a different name for the foreach variable.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Re^3: Read/Create files
by Mr. Muskrat (Canon) on Mar 26, 2015 at 19:18 UTC

    Are you sure it didn't complain about $indexfiles? (Athanasius mentioned it but did not offer a suggestion.)

    This: print $indexfiles, "\n";

    Should be: print $indexfiles[$i], "\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1121329]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-04-23 20:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found