Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Reading CSV Function

by jwkrahn (Abbot)
on Jun 15, 2021 at 03:39 UTC ( [id://11133878]=note: print w/replies, xml ) Need Help??


in reply to Reading CSV Function

my @headerArray = "a,b,c,d,e,f,g,h,i,j,k"; my $headerArrayRef = \@headerArray; ... my $headingAref = "$headerArrayRef"; ... my @headerArrayCopy = @$headingAref; print ($file "@headerArrayCopy\n"); #adds header

@headerArray starts out as a single string (an array of one element).

You then assign a reference of that array to $headerArrayRef, which could have been done in one step like this:

my $headerArrayRef = [ "a,b,c,d,e,f,g,h,i,j,k" ];

Next you convert that reference to a string and assign it to $headingAref. Which means that $headingAref can never access the original data from @headerArray.

And finally you dereference a string which is an error and will not work.

for ($currentIndex >= $readLineFrom and $currentIndex <= $readLine +To){

In Perl a for (foreach) loop iterates over a list but that is a list of one value (whatever $currentIndex >= $readLineFrom and $currentIndex <= $readLineTo evaluates to).

It looks like that should be if instead of for:

if ($currentIndex >= $readLineFrom and $currentIndex <= $readLineT +o){

Or you could do it the "Perl" way:

if ( $readLineFrom .. $readLineTo ) {

Log In?
Username:
Password:

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

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

    No recent polls found