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

Re: Can't open file within subroutine

by Lydia (Initiate)
on Jun 14, 2000 at 18:23 UTC ( [id://18104]=note: print w/replies, xml ) Need Help??


in reply to Can't open file within subroutine

Ok I cleaned it up a bit, I sill have the same problem though, only now I also have an uniitalized value for INFO. The file is still not being read. <CODE> "#!/usr/bin/perl -w opendir (EXA, "/export/home/cad/data/products") || die "no dir?: $1"; foreach $name(sort readdir (EXA)) { print "$name\n"; open(INFO, <"/export/home/cad/data/products/$name/source/$name.bom">) || die "no dir...grrrr?: $1"; @lines = <INFO> ; } foreach $line (@lines) { $line=~ s/BOARDPLACEMENT_BOM brd//; print "\n $line "; print "\n ------------------------ \n"; }" <CODE>

Replies are listed 'Best First'.
RE: Re: Can't open file within subroutine
by muppetBoy (Pilgrim) on Jun 14, 2000 at 18:33 UTC
    Try replacing
    open(INFO, <"/export/home/cad/data/products/$name/source/$name.bom">)
    with
    open(INFO, "/export/home/cad/data/products/$name/source/$name.bom")
    This should work if you want to just read from INFO.
    You are still not actually doing anything with the contents of the file. Try using:
    @lines = <INFO>; close (INFO);
    this will read all of the file into the lines array and then close the file (which is always good practice)
    Also, in your open or die code you may want to use $! as that will contain the relevent error message.
    Incidently try to wrap any code you post in the code tags, see Site How To, because it make it much easier to read.
RE: Re: Can't open file within subroutine
by t0mas (Priest) on Jun 14, 2000 at 18:48 UTC
    I'm not really sure what you are trying to do but here's a guess:
    #!/usr/bin/perl opendir(DIR, '/export/home/cad/data/products') || die "Can't opendir D +ir: $!"; my @Dirs = grep { /^[^.].*/ && -d "/export/home/cad/data/products/$_" +} readdir(DIR); closedir DIR; foreach $name (@Dirs) { open(FILE,"</export/home/cad/data/products/$name/source/$name.bom" +) || die "Can't open $file: $!"; my @lines=<FILE>; close(FILE); foreach $line (@lines) { $line=~ s/BOARDPLACEMENT_BOM brd//; print "\n $line "; print "\n------------------------ \n"; } };
    The thing I can't really figure out is why anyone would like to do that.

    /brother t0mas

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2025-01-16 22:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (54 votes). Check out past polls.