Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

opening a file

by torres09 (Acolyte)
on Jun 13, 2013 at 14:08 UTC ( #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;

Comment on opening a file
Download Code
Re: opening a file
by choroba (Abbot) 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
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? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2014-12-27 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls