Am Dienstag, 31. Mai 2005 11.06 schrieb Dermot Paikkos:
> Hi,
>
> perl5 (revision 5 version 8 subversion 5) on redhat fedora 3
>
> I have been trying to create a list of home directories from a list.
> The directory name comes straight from the list but I seem to be
> getting a odd end of line character from each item on the list and
> this gets added to the directory name. For example this is the output
> from the script:
> "aking "/home/afrood
>
> : Bad file descriptorood
>
> "aking "/home/aplatt
>
> From this it looks like the chomp is deleting the first character
> from the next line.
>
> And the directories appear like this:
> drwxr-xr-x   2 root    root    4096 Jun  1 09:50 afrood?
> drwxr-xr-x   2 root    root    4096 Jun  1 09:50 aplatt?
> drwxr-xr-x   2 root    root    4096 Jun  1 09:50 asimmen?
> drwxr-xr-x   2 root    root    4096 Jun  1 09:50 bbroll?
> drwxr-xr-x   2 root    root    4096 Jun  1 09:50 bjones?
>
> I have edited the text file with ms notepad, lemmy and vim but none
> made a difference.
>
> I have noticed this before on this particular machine but I can't
> find out why or how to get around this. If I omit chomp then I get a
> newline in the file name instead.
>
> Any ideas? Below is what I have been using. Thanx.
> Dp.
>

In addition to the good tips provided:

> #!/bin/perl

 use strict;
 use warnings;

> my $root = "/home/";
> my $file = "home.txt";
> open(FH,$file) or die "Can't open $file: $!\n";
>
> while (<FH>) {
>         chomp;

This chomps $_ which is never used below.

>         my $n = "$root"."$f";

$f is never defined. Did you mean

 my $n = $root.$_;

?

joe


>         print "Making \"$n\"\n";
>         mkdir($n,0755) or warn "Can't make $n: $!\n";
>         chown $f,$n or warn "Can't chown $n: $!\n";
> }
>
> ======= home.txt ========
> afrood
> aplatt
> asimmen
> bbroll
> bjones
> chi-keat
> ckreuzer
> cmolloy
> cprice
> dpaikkos
> fsauze
> fvieceli
> gevans
> gzuccotto
> international
> jbeaton
> jkennedy
> jprice
> kdavis
> lrobertson
> mcutler
> mmarten
> mrossello
> mstorey
> nstroud
> ppleasants
> ptabarelli
> rcaballero
> rilari
> rshah
> rtaylor
> scallender
> sstone
> syang
> =================
>
>
>
> ~~
> Dermot Paikkos * [EMAIL PROTECTED]
> Network Administrator @ Science Photo Library
> Phone: 0207 432 1100 * Fax: 0207 286 8668

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to