Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Error while trying to open a file

by ritchie (Initiate)
on Jan 05, 2011 at 03:55 UTC ( #880507=perlquestion: print w/ replies, xml ) Need Help??
ritchie has asked for the wisdom of the Perl Monks concerning the following question:

foreach $artefact (@objects) { $artefact=~ s/.bar//; print "artefact to be deployed is $artefact\n"; my $file = "C:/abc/def/klm/Properties/$artefact.properties"; open my $input_fh, '<', $file or die "failed to open '$file' +$!";
I get a error - failed to open 'C:/abc/def/klm/Properties/VerifyAccountId entity_Response .properties' Invalid argument at SIT_deploy.pl line 21, <INPUT> line 3. Could anyone please help me in fixing this error?

Comment on Error while trying to open a file
Download Code
Re: Error while trying to open a file
by Anonymous Monk on Jan 05, 2011 at 04:03 UTC
    Could anyone please help me in fixing this error?

    Don't feed junk to open?

    $ perl -Mautodie -e"open my$in, q!<!, q!echo|! " Can't open 'echo|' for reading: 'Invalid argument' at -e line 1
    on my operating system, filenames cannot contain |
Re: Error while trying to open a file
by k_manimuthu (Monk) on Jan 05, 2011 at 04:11 UTC

    Check the file is exists or not.

    $file='File Path'; print "\nFile $file ", (-e $file && -f $file ) ? "exists" : "doesn't e +xists";

    Get the OS error by using of $!

    open (FILEHANDELER,"FILEPATH") || die "Cannot open the input file : $! +";

    And check the file permission

      The file exists and it has read and write permission too. If i replace $artefact with the name of the file it works.
Re: Error while trying to open a file
by samarzone (Pilgrim) on Jan 05, 2011 at 09:41 UTC

    Did you notice that you have a space just before ".properties" in your file name?

    --
    Regards
    - Samar
      It was a typo when i posted it.
Re: Error while trying to open a file
by elagon (Initiate) on Jan 05, 2011 at 11:03 UTC

    Try change

    my $file = "C:/abc/def/klm/Properties/$artefact.properties"

    in

    my $file = 'C:/abc/def/klm/Properties/' . $artefact.properties

    I had the same problem but with a 'system' call

      Don't think this is going to help:

      #!/usr/bin/perl -wl my $artefact = "foo"; my $file = "C:/abc/def/klm/Properties/$artefact.properties"; print $file; $file = 'C:/abc/def/klm/Properties/' . $artefact.properties; print $file;

      gives

      $ ./880572.pl Unquoted string "properties" may clash with future reserved word at ./ +880572.pl line 9. C:/abc/def/klm/Properties/foo.properties C:/abc/def/klm/Properties/fooproperties

      and with use strict you'd get

      $ ./880572.pl Bareword "properties" not allowed while "strict subs" in use at ./8805 +72.pl line 10. Execution of ./880572.pl aborted due to compilation errors.
        use of chomp for the input helped solve the issue.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2014-12-25 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (159 votes), past polls