Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Problem reading files from directory

by shigetsu (Hermit)
on Jul 20, 2007 at 18:48 UTC ( [id://627848]=note: print w/replies, xml ) Need Help??


in reply to Problem reading files from directory

It's difficult to say where it goes wrong without some essential code provided; would you mind posting the relevant code bits?

(enclose them in code tags please)

Replies are listed 'Best First'.
Re^2: Problem reading files from directory
by zoryn (Initiate) on Jul 20, 2007 at 19:00 UTC
    Right, sorry.
    opendir(DIR, $INDIR) @mp3files = <*.mp3>; $OUTDIR = "./NEWDIR"; foreach my $FILE (@mp3files) { my $tmp= system("wine ......."); move($INFILE,"$OUTDIR/$INFILE"); if ($tmp!=0) { last; } } foreach my $FILE (@mp3files) { printf "File: %s\n",$FILE; } closedir(DIR);
    Now, when i press ctrl+c when wine is running, it jumps out of the 1st foreach. But at least one of the files has already been moved. When printing in the second foreach, it prints ALL files that were there, even the one that's been moved.

      First of, you should probably be using strictures (place them after the shebang line (usually #!/usr/bin/perl) separated by a blank line):

      use strict; use warnings;

      foreach will just iterate over a list given. Since you don't modifiy @mp3files anywhere, the contents will remain the same (i.e. untouched) in your second iteration.

        Not sure what you're doing in system(2) (the wine call), but why not try the following?

        @mp3files = <$INDIR/*.mp3>; $OUTDIR = "./NEWDIR"; foreach my $FILE (@mp3files) { my $tmp= system("wine ......."); move($INFILE,"$OUTDIR/$INFILE"); if ($tmp!=0) { last; } } @mp3files = <$OUTDIR/*.mp3>; foreach my $FILE (@mp3files) { printf "File: %s\n",$FILE; }

        Also, there's no such thing as the "move" subroutine. Is it just designed like:

        sub move { system "mv $_[0] $_[1]"; # $_[1] = directory + "/" + $_[0] specifi +ed file }

        If so you can simply that by just specifying the directory for the second argument.

        EDIT: Sorry, I got it, I just have to do a @mp3files = <*.mp3>; after the 1st iteration. Sorry about the newbness.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-03-29 11:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found