Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: selcting a specific file

by andyford (Curate)
on Oct 22, 2007 at 20:50 UTC ( #646576=note: print w/ replies, xml ) Need Help??


in reply to selcting a specific file

For us to help you most effectively, you should post your actual code. We don't know what "it doesn't work out" means. Perhaps your file is not zero bytes but contains some whitespace or something?

non-Perl: Andy Ford


Comment on Re: selcting a specific file
Re^2: selcting a specific file
by Anonymous Monk on Oct 22, 2007 at 21:34 UTC
    @files = grep { /\.log$/ } readdir ($DIR); foreach my $x (@files){ open READFILE, "......"; open WRITEFILE, ">......"; while(<READFILE>){ chomp; my @parts = split(/\s/, $_); print WRITEFILE $parts[1], " ", $parts[0], "\n"; } close WRITEFILE; close READFILE;
    this is the original code
Re^2: selcting a specific file
by Anonymous Monk on Oct 22, 2007 at 21:40 UTC
    the file doesn't have any content

      That's my point. -z is looking for a zero byte file, but 'no content' could be a bunch of tabs and spaces.

      [forda@hqnagtl1 ~]$ touch emptytest1 [forda@hqnagtl1 ~]$ touch emptytest2 [forda@hqnagtl1 ~]$ ls -l emptytest* -rw-rw-r-- 1 forda forda 0 Oct 22 17:19 emptytest1 -rw-rw-r-- 1 forda forda 0 Oct 22 17:19 emptytest2 [forda@hqnagtl1 ~]$ echo ' ' >> emptytest2 [forda@hqnagtl1 ~]$ ls -l emptytest* -rw-rw-r-- 1 forda forda 0 Oct 22 17:19 emptytest1 -rw-rw-r-- 1 forda forda 15 Oct 22 17:20 emptytest2
      I put some spaces into a formerly empty file and now it has a size of 15.

      non-Perl: Andy Ford

        wht command did you select for getting such an output???

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (17)
As of 2014-12-18 14:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (56 votes), past polls