Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: foreach loop and creating files with "$_"

by james28909 (Deacon)
on Jul 22, 2014 at 03:54 UTC ( [id://1094581]=note: print w/replies, xml ) Need Help??


in reply to Re: foreach loop and creating files with "$_"
in thread foreach loop and creating files with "$_"

just as an example, how would you do it differently if i might ask? :)
  • Comment on Re^2: foreach loop and creating files with "$_"

Replies are listed 'Best First'.
Re^3: foreach loop and creating files with "$_"
by wjw (Priest) on Jul 22, 2014 at 04:35 UTC
    my $file = "file"; my $temp = "temp"; foreach (1..5){ open $file, '>', "$temp" . "$_"; print $file "THIS IS DATA"; }
    or
    my $file = "file"; my $temp = "temp"; foreach my $end (1..5) { open $file, '>', "$temp" . "$end"; print $file "THIS IS DATA"; }
    (not tested)

    Personal preference only...

    ...the majority is always wrong, and always the last to know about it...

    Insanity: Doing the same thing over and over again and expecting different results...

    A solution is nothing more than a clearly stated problem...otherwise, the problem is not a problem, it is a facct

Re^3: foreach loop and creating files with "$_" (path tiny spew)
by Anonymous Monk on Jul 22, 2014 at 19:38 UTC

    First with $_ then without

    use Path::Tiny qw/ cwd path tempfile /; ## in cwd path( "temp$_" )->spew("THIS IS DATA") for 1 .. 5; ## in $TMP directory tempfile( 'tempjamesXXXX' )->spew("THIS IS DATA") for 1 .. 5;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-24 05:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found