Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

opening a file

by torres09 (Acolyte)
on Jun 13, 2013 at 14:08 UTC ( [id://1038748]=perlquestion: print w/replies, xml ) Need Help??

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

Hey

i have opened a file as shown in code and called sub routines which need to access the file , but i can't open the file . I am new to perl so any form of help is appreciated

print " Please input your new csv file \n"; my $ csv_name =<>; my $file_csv="$csv_name"; open(FILE_csv,"<","$file_csv")|| die ("can't open the csv file \n" +); @array_A= column_segregation_Spec_values (1); # function call close FILE;

Replies are listed 'Best First'.
Re: opening a file
by choroba (Cardinal) on Jun 13, 2013 at 14:19 UTC
    There are several issues:
    • After reading from the standard input, the line ends in a newline. This newline is not a part of the filename, so remove it. See chomp.
    • Why do you declare the variable $file_csv? Its value is identical to $csv_name (the space after the $ sigil is tolerated by Perl, but I would recommend removing it).
    • You are closing the FILE filehandle, but opening the FILE_csv one. If you turned warnings on, Perl would tell you.
    • Update: It is easier to send lexical filehandles as parameters to subroutines. Do not use bareword filehandles.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-03-28 18:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found