Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: creating a text file at run time and writing to it.

by zigdon (Deacon)
on Jul 20, 2006 at 11:47 UTC ( #562549=note: print w/replies, xml ) Need Help??


in reply to creating a text file at run time and writing to it.

Is it possible you're running on windows? Since you don't chomp your input, you're going to try to create a file called 'john\n.txt', which might blow up on a windows filesystem. What is the exact error you get when you try to create the file? Try this:
#!/usr/bin/perl -w use strict; open (NAMES, "names.txt") or die "Failed to read names: $!"; while my $name (<NAMES>) { chomp $name; open(OUT, ">$name.txt") or die "Failed to write $name.txt: $!"; print OUT " hellow"; close OUT; } close NAMES;

-- zigdon

Replies are listed 'Best First'.
Re^2: creating a text file at run time and writing to it.
by zigdon (Deacon) on Jul 20, 2006 at 12:08 UTC
    Absolutly correct - updated. That's what I get for switching to a named var from $_ :)

    -- zigdon

Re^2: creating a text file at run time and writing to it.
by madtoperl (Friar) on Jul 20, 2006 at 11:51 UTC
    Hi zidgon,

    Giving chomp won't remove the \n here.We have to give chomp($name) instead of chomp.

    Thanks and Regards,
    madtoperl.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2019-05-23 21:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (146 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!